AmpFormatterImageTest.php in Accelerated Mobile Pages (AMP) 8.3
File
tests/src/Functional/AmpFormatterImageTest.php
View source
<?php
namespace Drupal\Tests\amp\Functional;
use Drupal\file\Entity\File;
use Drupal\Tests\TestFileCreationTrait;
use Drupal\Tests\image\Kernel\ImageFieldCreationTrait;
class AmpFormatterImageTest extends AmpFormatterTestBase {
use TestFileCreationTrait;
use ImageFieldCreationTrait;
protected $removedElementName = 'img';
protected $ampFormatterType = 'amp_image';
protected $ampFormatterSettings = [
'layout' => 'responsive',
'width' => 16,
'height' => 9,
];
protected $ampElementName = 'amp-img';
protected function setUp() {
parent::setUp();
$fieldSettings = [
'max_resolution' => '100x100',
'min_resolution' => '50x50',
'alt_field' => 1,
'file_directory' => 'testing',
];
$this
->createImageField($this->fieldName, $this->contentType, [], $fieldSettings);
$this
->configureDisplay();
}
public function createAmpNode() {
parent::createAmpNode();
$images = $this
->getTestFiles('image');
$image = array_pop($images);
$file = File::create([
'uri' => $image->uri,
]);
$file
->save();
$this->node
->set($this->fieldName, [
'target_id' => $file
->id(),
'alt' => 'alt text',
])
->save();
$file_path = $file
->createFileUrl();
$this->valuesOut = [
'<amp-img layout="responsive" width="16" height="9" src="' . $file_path . '" alt="alt text">',
'</amp-img>',
];
}
}