function ImageThemeFunctionTest::testImageStyleTheme in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/image/src/Tests/ImageThemeFunctionTest.php \Drupal\image\Tests\ImageThemeFunctionTest::testImageStyleTheme()
Tests usage of the image style theme function.
File
- core/
modules/ image/ src/ Tests/ ImageThemeFunctionTest.php, line 127 - Contains \Drupal\image\Tests\ImageThemeFunctionTest.
Class
- ImageThemeFunctionTest
- Tests image theme functions.
Namespace
Drupal\image\TestsCode
function testImageStyleTheme() {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = $this->container
->get('renderer');
// Create an image.
$files = $this
->drupalGetTestFiles('image');
$file = reset($files);
$original_uri = file_unmanaged_copy($file->uri, 'public://', FILE_EXISTS_RENAME);
// Create a style.
$style = entity_create('image_style', array(
'name' => 'image_test',
'label' => 'Test',
));
$style
->save();
$url = $style
->buildUrl($original_uri);
// Create the base element that we'll use in the tests below.
$base_element = array(
'#theme' => 'image_style',
'#style_name' => 'image_test',
'#uri' => $original_uri,
);
$element = $base_element;
$this
->setRawContent($renderer
->renderRoot($element));
$elements = $this
->xpath('//img[@class="image-style-image-test" and @src=:url and @alt=""]', array(
':url' => $url,
));
$this
->assertEqual(count($elements), 1, 'theme_image_style() renders an image correctly.');
// Test using theme_image_style() with a NULL value for the alt option.
$element = $base_element;
$element['#alt'] = NULL;
$this
->setRawContent($renderer
->renderRoot($element));
$elements = $this
->xpath('//img[@class="image-style-image-test" and @src=:url]', array(
':url' => $url,
));
$this
->assertEqual(count($elements), 1, 'theme_image_style() renders an image correctly with a NULL value for the alt option.');
}