public function DisplayTest::testReadMore in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/views/src/Tests/Plugin/DisplayTest.php \Drupal\views\Tests\Plugin\DisplayTest::testReadMore()
Tests the readmore functionality.
File
- core/
modules/ views/ src/ Tests/ Plugin/ DisplayTest.php, line 170 - Contains \Drupal\views\Tests\Plugin\DisplayTest.
Class
- DisplayTest
- Tests the basic display plugin.
Namespace
Drupal\views\Tests\PluginCode
public function testReadMore() {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = $this->container
->get('renderer');
if (!isset($this->options['validate']['type'])) {
return;
}
$expected_more_text = 'custom more text';
$view = Views::getView('test_display_more');
$this
->executeView($view);
$output = $view
->preview();
$output = $renderer
->renderRoot($output);
$this
->setRawContent($output);
$result = $this
->xpath('//a[@class=:class]', array(
':class' => 'more-link',
));
$this
->assertEqual($result[0]
->attributes()->href, \Drupal::url('view.test_display_more.page_1'), 'The right more link is shown.');
$this
->assertEqual(trim($result[0][0]), $expected_more_text, 'The right link text is shown.');
// Test the renderMoreLink method directly. This could be directly unit
// tested.
$more_link = $view->display_handler
->renderMoreLink();
$more_link = $renderer
->renderRoot($more_link);
$this
->setRawContent($more_link);
$result = $this
->xpath('//a[@class=:class]', array(
':class' => 'more-link',
));
$this
->assertEqual($result[0]
->attributes()->href, \Drupal::url('view.test_display_more.page_1'), 'The right more link is shown.');
$this
->assertEqual(trim($result[0][0]), $expected_more_text, 'The right link text is shown.');
// Test the useMoreText method directly. This could be directly unit
// tested.
$more_text = $view->display_handler
->useMoreText();
$this
->assertEqual($more_text, $expected_more_text, 'The right more text is chosen.');
$view = Views::getView('test_display_more');
$view
->setDisplay();
$view->display_handler
->setOption('use_more', 0);
$this
->executeView($view);
$output = $view
->preview();
$output = $renderer
->renderRoot($output);
$this
->setRawContent($output);
$result = $this
->xpath('//a[@class=:class]', array(
':class' => 'more-link',
));
$this
->assertTrue(empty($result), 'The more link is not shown.');
$view = Views::getView('test_display_more');
$view
->setDisplay();
$view->display_handler
->setOption('use_more', 0);
$view->display_handler
->setOption('use_more_always', 0);
$view->display_handler
->setOption('pager', array(
'type' => 'some',
'options' => array(
'items_per_page' => 1,
'offset' => 0,
),
));
$this
->executeView($view);
$output = $view
->preview();
$output = $renderer
->renderRoot($output);
$this
->setRawContent($output);
$result = $this
->xpath('//a[@class=:class]', array(
':class' => 'more-link',
));
$this
->assertTrue(empty($result), 'The more link is not shown when view has more records.');
// Test the default value of use_more_always.
$view = entity_create('view')
->getExecutable();
$this
->assertTrue($view
->getDisplay()
->getOption('use_more_always'), 'Always display the more link by default.');
}