public function ViewsBaseUrlFieldTest::testViewsBaseUrlImage in Views base url 2.0.x
Same name and namespace in other branches
- 8 tests/src/Functional/ViewsBaseUrlFieldTest.php \Drupal\Tests\views_base_url\Functional\ViewsBaseUrlFieldTest::testViewsBaseUrlImage()
Tests views base url field when rendered as image.
File
- tests/
src/ Functional/ ViewsBaseUrlFieldTest.php, line 319
Class
- ViewsBaseUrlFieldTest
- Basic test for views base url.
Namespace
Drupal\Tests\views_base_url\FunctionalCode
public function testViewsBaseUrlImage() {
global $base_url;
$this
->drupalGet('views-base-url-image-test');
$this
->assertResponse(200);
$elements = $this
->xpath('//div[contains(@class,"view-views-base-url-image-test")]/div[@class="view-content"]/div[contains(@class,"views-row")]');
$this
->assertEqual(count($elements), $this->nodeCount, t('There are @count rows', [
'@count' => $this->nodeCount,
]));
foreach ($this->nodes as $node) {
$field = $node
->get('field_image');
$value = $field
->getValue();
$image_uri = file_url_transform_relative(file_create_url($field->entity
->getFileUri()));
$image_alt = $value[0]['alt'];
$image_width = $value[0]['width'];
$image_height = $value[0]['height'];
$link_class = 'views-base-url-test';
$link_title = $node
->getTitle();
$link_rel = 'rel-attribute';
$link_target = '_blank';
$link_path = Url::fromUri($base_url . $this->pathAliasManager
->getAliasByPath('/node/' . $node
->id()), [
'attributes' => [
'class' => $link_class,
'title' => $link_title,
'rel' => $link_rel,
'target' => $link_target,
],
'fragment' => 'new',
'query' => [
'destination' => 'node',
],
])
->toUriString();
$elements = $this
->xpath('//a[@href=:path and @class=:class and @title=:title and @rel=:rel and @target=:target]/img[@src=:url and @width=:width and @height=:height and @alt=:alt]', [
':path' => $link_path,
':class' => $link_class,
':title' => $link_title,
':rel' => $link_rel,
':target' => $link_target,
':url' => $image_uri,
':width' => $image_width,
':height' => $image_height,
':alt' => $image_alt,
]);
$this
->assertEqual(count($elements), 1, 'Views base url rendered as link image');
}
}