public function QuickEditImageControllerTest::testInvalidUpload in Drupal 10
Same name and namespace in other branches
- 9 core/modules/quickedit/tests/src/Functional/QuickEditImageControllerTest.php \Drupal\Tests\quickedit\Functional\QuickEditImageControllerTest::testInvalidUpload()
Tests that uploading an invalid image does not work.
File
- core/
modules/ quickedit/ tests/ src/ Functional/ QuickEditImageControllerTest.php, line 144
Class
- QuickEditImageControllerTest
- Tests the endpoints used by the "image" in-place editor.
Namespace
Drupal\Tests\quickedit\FunctionalCode
public function testInvalidUpload() {
// Create a test Node.
$node = $this
->drupalCreateNode([
'type' => 'article',
'title' => 'Test Node',
]);
// We want a test image that will fail validation.
$invalid_image = FALSE;
/** @var \Drupal\Core\Image\ImageFactory $image_factory */
$image_factory = $this->container
->get('image.factory');
foreach ($this
->drupalGetTestFiles('image') as $image) {
/** @var \Drupal\Core\Image\ImageInterface $image_file */
$image_file = $image_factory
->get($image->uri);
if ($image_file
->getWidth() < 50 || $image_file
->getWidth() > 100) {
$invalid_image = $image;
break;
}
}
$this
->assertNotFalse($invalid_image);
$this
->drupalLogin($this->contentAuthorUser);
$this
->uploadImage($invalid_image, $node
->id(), $this->fieldName, $node
->language()
->getId());
$this
->assertStringContainsString('"main_error":"The image failed validation."', $this
->getSession()
->getPage()
->getContent(), 'Invalid upload returned errors.');
}