AmpFormatterVideoTest.php in Accelerated Mobile Pages (AMP) 8.3
File
tests/src/Functional/AmpFormatterVideoTest.php
View source
<?php
namespace Drupal\Tests\amp\Functional;
use Drupal\file\Entity\File;
use Drupal\Tests\file\Functional\FileFieldCreationTrait;
use Drupal\Core\StreamWrapper\PublicStream;
class AmpFormatterVideoTest extends AmpFormatterTestBase {
use FileFieldCreationTrait;
protected $removedElementName = 'video';
protected $ampFormatterType = 'amp_video';
protected $ampFormatterSettings = [
'height' => 9,
'width' => 16,
'layout' => 'responsive',
'autoplay' => FALSE,
'controls' => FALSE,
'loop' => FALSE,
];
protected $ampElementName = 'amp-video';
protected function setUp() {
parent::setUp();
$fieldSettings = [
'file_directory' => 'testing',
'file_extensions' => 'mp4',
];
$this
->createFileField($this->fieldName, 'node', $this->contentType, [], $fieldSettings);
$this
->configureDisplay();
}
public function createAmpNode() {
parent::createAmpNode();
$file_system = \Drupal::service('file_system');
$source_path = 'https://amp.dev/static/samples/video/tokyo.mp4';
$video_path = system_retrieve_file($source_path, PublicStream::basePath());
$file = File::create([
'uri' => $video_path,
]);
$file
->save();
$this->node
->set($this->fieldName, [
'target_id' => $file
->id(),
])
->save();
$file_path = $file
->createFileUrl();
$this->valuesOut = [
'<amp-video',
'src="' . $file_path . '"',
'<div fallback>',
'<p>Your browser doesn’t support HTML5 video</p>',
'</div>',
'</amp-video>',
];
}
}