You are here

public function ViewExecutableTest::testValidate in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/ViewExecutableTest.php \Drupal\Tests\views\Kernel\ViewExecutableTest::testValidate()
  2. 9 core/modules/views/tests/src/Kernel/ViewExecutableTest.php \Drupal\Tests\views\Kernel\ViewExecutableTest::testValidate()

Tests the validation of display handlers.

File

core/modules/views/tests/src/Kernel/ViewExecutableTest.php, line 437

Class

ViewExecutableTest
Tests the ViewExecutable class.

Namespace

Drupal\Tests\views\Kernel

Code

public function testValidate() {
  $view = Views::getView('test_executable_displays');
  $view
    ->setDisplay('page_1');
  $validate = $view
    ->validate();

  // Validating a view shouldn't change the active display.
  $this
    ->assertEquals('page_1', $view->current_display, "The display should be constant while validating");
  $count = 0;
  foreach ($view->displayHandlers as $id => $display) {
    $match = function ($value) use ($display) {
      return strpos($value, $display->display['display_title']) !== FALSE;
    };
    $this
      ->assertNotEmpty(array_filter($validate[$id], $match), new FormattableMarkup('Error message found for @id display', [
      '@id' => $id,
    ]));
    $count++;
  }
  $this
    ->assertCount($count, $view->displayHandlers, 'Error messages from all handlers merged.');

  // Test that a deleted display is not included.
  $display =& $view->storage
    ->getDisplay('default');
  $display['deleted'] = TRUE;
  $validate_deleted = $view
    ->validate();
  $this
    ->assertNotSame($validate, $validate_deleted);
}