class ImageUploadAccessTest
Same name and namespace in other branches
- 11.x core/modules/ckeditor5/tests/src/Functional/ImageUploadAccessTest.php \Drupal\Tests\ckeditor5\Functional\ImageUploadAccessTest
- 10 core/modules/ckeditor5/tests/src/Functional/ImageUploadAccessTest.php \Drupal\Tests\ckeditor5\Functional\ImageUploadAccessTest
Test image upload access.
@group ckeditor5 @internal
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\ckeditor5\Functional\ImageUploadTest uses \Drupal\Tests\jsonapi\Functional\JsonApiRequestTestTrait, \Drupal\Tests\TestFileCreationTrait, \Drupal\Tests\ckeditor5\Traits\SynchronizeCsrfTokenSeedTrait implements \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\ckeditor5\Functional\ImageUploadAccessTest implements \Drupal\Tests\ckeditor5\Functional\ImageUploadTest
- class \Drupal\Tests\ckeditor5\Functional\ImageUploadTest uses \Drupal\Tests\jsonapi\Functional\JsonApiRequestTestTrait, \Drupal\Tests\TestFileCreationTrait, \Drupal\Tests\ckeditor5\Traits\SynchronizeCsrfTokenSeedTrait implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of ImageUploadAccessTest
File
-
core/
modules/ ckeditor5/ tests/ src/ Functional/ ImageUploadAccessTest.php, line 14
Namespace
Drupal\Tests\ckeditor5\FunctionalView source
class ImageUploadAccessTest extends ImageUploadTest {
/**
* Test access to the CKEditor 5 image upload controller.
*/
public function testCkeditor5ImageUploadRoute() {
$this->createBasicFormat();
$url = $this->getUploadUrl();
$test_image = file_get_contents(current($this->getTestFiles('image'))->uri);
// With no text editor, expect a 404.
$response = $this->uploadRequest($url, $test_image, 'test.jpg');
$this->assertSame(404, $response->getStatusCode());
$editor = $this->createEditorWithUpload([
'status' => FALSE,
'scheme' => 'public',
'directory' => 'inline-images',
'max_size' => '',
'max_dimensions' => [
'width' => 0,
'height' => 0,
],
]);
// Ensure that images cannot be uploaded when image upload is disabled.
$response = $this->uploadRequest($url, $test_image, 'test.jpg');
$this->assertSame(403, $response->getStatusCode());
$editor->setImageUploadSettings([
'status' => TRUE,
] + $editor->getImageUploadSettings())
->save();
$response = $this->uploadRequest($url, $test_image, 'test.jpg');
$this->assertSame(201, $response->getStatusCode());
// Ensure lock failures are reported correctly.
$d = 'public://inline-images/test.jpg';
$f = $this->container
->get('file_system')
->getDestinationFilename($d, FileSystemInterface::EXISTS_RENAME);
$this->container
->get('lock')
->acquire('file:ckeditor5:' . Crypt::hashBase64($f));
$response = $this->uploadRequest($url, $test_image, 'test.jpg');
$this->assertSame(503, $response->getStatusCode());
$this->assertStringContainsString('File "public://inline-images/test_0.jpg" is already locked for writing.', (string) $response->getBody());
// Ensure that users without permissions to the text format cannot upload
// images.
$this->drupalLogout();
$response = $this->uploadRequest($url, $test_image, 'test.jpg');
$this->assertSame(403, $response->getStatusCode());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.