public function DisplayTest::testReadMore

Tests the readmore functionality.

File

drupal/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php, line 172
Definition of Drupal\views\Tests\Plugin\DisplayTest.

Class

DisplayTest
Tests the basic display plugin.

Namespace

Drupal\views\Tests\Plugin

Code

public function testReadMore() {
  $expected_more_text = 'custom more text';
  $view = views_get_view('test_display_more');
  $this
    ->executeView($view);
  $output = $view
    ->preview();
  $output = drupal_render($output);
  $this
    ->drupalSetContent($output);
  $result = $this
    ->xpath('//div[@class=:class]/a', array(
    ':class' => 'more-link',
  ));
  $this
    ->assertEqual($result[0]
    ->attributes()->href, url('test_display_more'), '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();
  $this
    ->drupalSetContent($more_link);
  $result = $this
    ->xpath('//div[@class=:class]/a', array(
    ':class' => 'more-link',
  ));
  $this
    ->assertEqual($result[0]
    ->attributes()->href, url('test_display_more'), '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.');
}