public function EntityPagerTest::testAllLink in Entity Pager 8
Same name and namespace in other branches
- 2.0.x tests/src/Functional/EntityPagerTest.php \Drupal\Tests\entity_pager\Functional\EntityPagerTest::testAllLink()
Tests all link.
File
- tests/
src/ Functional/ EntityPagerTest.php, line 183
Class
- EntityPagerTest
- Tests the entity pager view style.
Namespace
Drupal\Tests\entity_pager\FunctionalCode
public function testAllLink() {
$this
->drupalPlaceBlock('views_block:entity_pager_example-entity_pager_example_block', [
'id' => 'test',
]);
$this
->drupalGet($this->nodes[1]
->toUrl());
$elements = $this
->cssSelect('#block-test .entity-pager-item-all a');
$this
->assertCount(1, $elements, 'All link exists.');
$link = reset($elements);
$expected = Url::fromUserInput('/')
->toString();
$this
->assertEquals($expected, $link
->getAttribute('href'), 'All link points to URI set in configuration.');
$this
->assertEquals('Home', trim($link
->getText()), 'All link text from configuration.');
$this
->updateExampleView([
'link_all_text' => '<b>Text</b>',
]);
$this
->drupalGet($this
->getUrl());
$elements = $this
->cssSelect('#block-test .entity-pager-item-all a > b');
$this
->assertCount(1, $elements, 'HTML is displayed in all text.');
$this
->updateExampleView([
'link_all_text' => '[site:name]',
'link_all_url' => '[site:name]',
]);
$this
->drupalGet($this
->getUrl());
$link = $this
->cssSelect('#block-test .entity-pager-item-all a')[0];
$expected = \Drupal::token()
->replace('[site:name]');
$this
->assertEquals($expected, trim($link
->getText()), 'Global token text replacement.');
$expected = Url::fromUserInput("/{$expected}")
->toString();
$this
->assertEquals($expected, $link
->getAttribute('href'), 'Global token URL replacement.');
$this
->updateExampleView([
'link_all_text' => '[node:nid]',
'link_all_url' => '[node:nid]',
]);
$this
->drupalGet($this
->getUrl());
$link = $this
->cssSelect('#block-test .entity-pager-item-all a')[0];
$expected = (string) $this->nodes[1]
->id();
$this
->assertEquals($expected, trim($link
->getText()), 'Node context token text replacement.');
$expected = Url::fromUserInput("/{$expected}")
->toString();
$this
->assertEquals($expected, $link
->getAttribute('href'), 'Node context token URL replacement.');
$this
->updateExampleView([
'link_all_text' => '[node:nid] [node:_invalid_token_]',
'link_all_url' => '[node:nid][node:_invalid_token_]',
]);
$this
->drupalGet($this
->getUrl());
$link = $this
->cssSelect('#block-test .entity-pager-item-all a')[0];
$expected = (string) $this->nodes[1]
->id();
$this
->assertEquals($expected, trim($link
->getText()), 'Node context token text replacement clearing invalid tokens.');
$expected = Url::fromUserInput("/{$expected}")
->toString();
$this
->assertEquals($expected, $link
->getAttribute('href'), 'Node context token URL replacement clearing invalid tokens.');
$this
->updateExampleView([
'link_all_url' => '/a%20space',
]);
$this
->drupalGet($this
->getUrl());
$href = $this
->cssSelect('#block-test .entity-pager-item-all a')[0]
->getAttribute('href');
$this
->assertEquals('/a%20space', $href, 'URLs should not be double encoded.');
$this
->updateExampleView([
'link_all_url' => 'https://example.com',
]);
$this
->drupalGet($this
->getUrl());
$link = $this
->cssSelect('#block-test .entity-pager-item-all a')[0];
$this
->assertEquals('https://example.com', $link
->getAttribute('href'), 'External URL.');
$this
->updateExampleView([
'display_all' => FALSE,
]);
$this
->drupalGet($this
->getUrl());
$this
->assertEmpty($this
->cssSelect('#block-test .entity-pager-item-all'), 'All link does not exist.');
}