ImageUploadAccessTest.php in Drupal 10
File
core/modules/ckeditor5/tests/src/Functional/ImageUploadAccessTest.php
View source
<?php
namespace Drupal\Tests\ckeditor5\Functional;
use Drupal\Component\Utility\Crypt;
use Drupal\Core\File\FileSystemInterface;
class ImageUploadAccessTest extends ImageUploadTest {
public function testCkeditor5ImageUploadRoute() {
$this
->createBasicFormat();
$url = $this
->getUploadUrl();
$test_image = file_get_contents(current($this
->getTestFiles('image'))->uri);
$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,
],
]);
$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());
$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());
$this
->drupalLogout();
$response = $this
->uploadRequest($url, $test_image, 'test.jpg');
$this
->assertSame(403, $response
->getStatusCode());
}
}