class CKEditor5ImageControllerTest
Tests CKEditor5ImageController.
@group ckeditor5
@coversDefaultClass \Drupal\ckeditor5\Controller\CKEditor5ImageController
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\ckeditor5\Unit\CKEditor5ImageControllerTest implements \Drupal\Tests\UnitTestCase
Expanded class hierarchy of CKEditor5ImageControllerTest
File
-
core/
modules/ ckeditor5/ tests/ src/ Unit/ CKEditor5ImageControllerTest.php, line 31
Namespace
Drupal\Tests\ckeditor5\UnitView source
final class CKEditor5ImageControllerTest extends UnitTestCase {
/**
* Tests that upload fails correctly when the file is too large.
*/
public function testInvalidFile() : void {
$file_system = $this->prophesize(FileSystemInterface::class);
$file_system->move(Argument::any())
->shouldNotBeCalled();
$directory = 'public://';
$file_system->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY)
->willReturn(TRUE);
$file_system->getDestinationFilename(Argument::cetera())
->willReturn('/tmp/foo.txt');
$lock = $this->prophesize(LockBackendInterface::class);
$lock->acquire(Argument::any())
->willReturn(TRUE);
$container = $this->prophesize(ContainerInterface::class);
$file_storage = $this->prophesize(EntityStorageInterface::class);
$file = $this->prophesize(FileInterface::class);
$violations = $this->prophesize(EntityConstraintViolationList::class);
$violations->count()
->willReturn(0);
$file->validate()
->willReturn($violations->reveal());
$file_storage->create(Argument::any())
->willReturn($file->reveal());
$entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class);
$entity_type_manager->getStorage('file')
->willReturn($file_storage->reveal());
$container->get('entity_type.manager')
->willReturn($entity_type_manager->reveal());
$entity_type_repository = $this->prophesize(EntityTypeRepositoryInterface::class);
$entity_type_repository->getEntityTypeFromClass(File::class)
->willReturn('file');
$container->get('entity_type.repository')
->willReturn($entity_type_repository->reveal());
\Drupal::setContainer($container->reveal());
$controller = new CKEditor5ImageController($file_system->reveal(), $this->prophesize(FileUploadHandlerInterface::class)
->reveal(), $lock->reveal(), $this->prophesize(CKEditor5PluginManagerInterface::class)
->reveal());
// We can't use vfsstream here because of how Symfony request works.
$file_uri = tempnam(sys_get_temp_dir(), 'tmp');
$fp = fopen($file_uri, 'w');
fwrite($fp, 'foo');
fclose($fp);
$request = Request::create('/', files: [
'upload' => [
'name' => 'foo.txt',
'type' => 'text/plain',
'size' => 42,
'tmp_name' => $file_uri,
'error' => \UPLOAD_ERR_FORM_SIZE,
],
]);
$editor = $this->prophesize(EditorInterface::class);
$request->attributes
->set('editor', $editor->reveal());
$this->expectException(HttpException::class);
$this->expectExceptionMessage('The file "foo.txt" exceeds the upload limit defined in your form.');
$controller->upload($request);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
CKEditor5ImageControllerTest::testInvalidFile | public | function | Tests that upload fails correctly when the file is too large. | |
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
UnitTestCase::$root | protected | property | The app root. | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | |
UnitTestCase::setUp | protected | function | 375 | |
UnitTestCase::setupMockIterator | protected | function | Set up a traversable class mock to return specific items when iterated. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.