You are here

public function DisplayTest::testReadMoreNoDisplay in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Functional/Plugin/DisplayTest.php \Drupal\Tests\views\Functional\Plugin\DisplayTest::testReadMoreNoDisplay()

Tests the readmore validation.

File

core/modules/views/tests/src/Functional/Plugin/DisplayTest.php, line 178

Class

DisplayTest
Tests the basic display plugin.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testReadMoreNoDisplay() {
  $view = Views::getView('test_display_more');

  // Confirm that the view validates when there is a page display.
  $errors = $view
    ->validate();
  $this
    ->assertTrue(empty($errors), 'More link validation has no errors.');

  // Confirm that the view does not validate when the page display is disabled.
  $view
    ->setDisplay('page_1');
  $view->display_handler
    ->setOption('enabled', FALSE);
  $view
    ->setDisplay('default');
  $errors = $view
    ->validate();
  $this
    ->assertTrue(!empty($errors), 'More link validation has some errors.');
  $this
    ->assertEquals('Display "Default" uses a "more" link but there are no displays it can link to. You need to specify a custom URL.', $errors['default'][0], 'More link validation has the right error.');

  // Confirm that the view does not validate when the page display does not exist.
  $view = Views::getView('test_view');
  $view
    ->setDisplay('default');
  $view->display_handler
    ->setOption('use_more', 1);
  $errors = $view
    ->validate();
  $this
    ->assertTrue(!empty($errors), 'More link validation has some errors.');
  $this
    ->assertEquals('Display "Default" uses a "more" link but there are no displays it can link to. You need to specify a custom URL.', $errors['default'][0], 'More link validation has the right error.');
}