function ViewExecutableTest::testValidate

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/ViewExecutableTest.php \Drupal\Tests\views\Kernel\ViewExecutableTest::testValidate()
  2. 10 core/modules/views/tests/src/Kernel/ViewExecutableTest.php \Drupal\Tests\views\Kernel\ViewExecutableTest::testValidate()
  3. 11.x 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 434

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->assertEqual('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->assertEqual(count($view->displayHandlers), $count, '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->assertNotIdentical($validate, $validate_deleted, 'Master display has not been validated.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.