AnimatedGifFieldTest.php in Animated GIF 8
File
tests/src/Functional/AnimatedGifFieldTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\animated_gif\Functional;
use Drupal\file\FileInterface;
class AnimatedGifFieldTest extends AnimatedGifFunctionalTestBase {
const TEST_ANIMATED_FILE = 'animated.gif';
const TEST_ANIMATED_FILE_URI = 'temporary://' . self::TEST_ANIMATED_FILE;
const TEST_NOT_ANIMATED_FILE = 'not-animated.gif';
const TEST_NOT_ANIMATED_FILE_URI = 'temporary://' . self::TEST_NOT_ANIMATED_FILE;
protected $node;
protected $fieldName = 'field_image';
protected function setUp() : void {
parent::setUp();
$entityType = 'node';
$bundle = 'article';
$this
->createFileField($entityType, $bundle, $this->fieldName);
$this->node = $this
->drupalCreateNode([
'type' => $bundle,
]);
$this->node
->save();
$this->displayRepository
->getFormDisplay($entityType, $bundle)
->setComponent($this->fieldName, [
'type' => 'image_image',
])
->save();
}
public function testGif() : void {
$this
->gifAnimationTest(self::TEST_ANIMATED_FILE, self::TEST_ANIMATED_FILE_URI, TRUE);
$this
->gifAnimationTest(self::TEST_NOT_ANIMATED_FILE, self::TEST_NOT_ANIMATED_FILE_URI, FALSE);
}
protected function gifAnimationTest(string $fileName, string $fileUri, bool $isAnimated) : void {
$this
->drupalLogin($this->adminUser);
$nid = $this->node
->id();
$this
->drupalGet("node/{$nid}/edit");
$file = $this
->getTestFile($fileName, $fileUri);
$this
->uploadImage($file);
if ($isAnimated) {
$this
->assertSession()
->pageTextContains('GIF images are not being processed by image styles, use with caution!');
}
else {
$this
->assertSession()
->pageTextNotContains('GIF images are not being processed by image styles, use with caution!');
}
}
protected function uploadImage(FileInterface $file) : void {
$edit = [
'files[' . $this->fieldName . '_0]' => $this->fileSystem
->realpath($file
->getFileUri()),
];
$this
->submitForm($edit, 'Upload');
}
}