public function BlazyFormatterTest::testBlazyMedia in Blazy 8.2
Same name and namespace in other branches
- 8 tests/src/Kernel/BlazyFormatterTest.php \Drupal\Tests\blazy\Kernel\BlazyFormatterTest::testBlazyMedia()
Tests the Blazy formatter faked Media integration.
@dataProvider providerTestBlazyMedia
Parameters
mixed|string|bool $input_url: Input URL, else empty.
bool $expected: The expected output.
File
- tests/
src/ Kernel/ BlazyFormatterTest.php, line 158
Class
- BlazyFormatterTest
- Tests the Blazy image formatter.
Namespace
Drupal\Tests\blazy\KernelCode
public function testBlazyMedia($input_url, $expected) {
// Attempts to fix undefined DRUPAL_TEST_IN_CHILD_SITE for PHP 8 at 9.1.x.
// The middleware test.http_client.middleware calls drupal_generate_test_ua
// which checks the DRUPAL_TEST_IN_CHILD_SITE constant, that is not defined
// in Kernel tests.
try {
if (!defined('DRUPAL_TEST_IN_CHILD_SITE')) {
define('DRUPAL_TEST_IN_CHILD_SITE', FALSE);
}
$entity = $this->entity;
$settings = [
'input_url' => $input_url,
'source_field' => $this->testFieldName,
'media_source' => 'remote_video',
'view_mode' => 'default',
'bundle' => $this->bundle,
'thumbnail_style' => 'thumbnail',
'uri' => $this->uri,
];
$build = $this->display
->build($entity);
$render = BlazyMedia::build($entity, $settings);
if ($expected && $render) {
$this
->assertNotEmpty($render);
$field[0] = $render;
$field['#settings'] = $settings;
$wrap = BlazyMedia::wrap($field, $settings);
$this
->assertNotEmpty($wrap);
$render = $this->blazyManager
->getRenderer()
->renderRoot($build[$this->testFieldName]);
$this
->assertStringContainsString('data-blazy', $render);
}
else {
$this
->assertFalse($render);
}
} catch (GuzzleException $e) {
// Ignore any HTTP errors.
}
}