function ViewExecutableTest::testSetDisplayWithInvalidDisplay

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/ViewExecutableTest.php \Drupal\Tests\views\Kernel\ViewExecutableTest::testSetDisplayWithInvalidDisplay()
  2. 8.9.x core/modules/views/tests/src/Kernel/ViewExecutableTest.php \Drupal\Tests\views\Kernel\ViewExecutableTest::testSetDisplayWithInvalidDisplay()
  3. 11.x core/modules/views/tests/src/Kernel/ViewExecutableTest.php \Drupal\Tests\views\Kernel\ViewExecutableTest::testSetDisplayWithInvalidDisplay()

File

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

Class

ViewExecutableTest
Tests the ViewExecutable class.

Namespace

Drupal\Tests\views\Kernel

Code

public function testSetDisplayWithInvalidDisplay() : void {
    \Drupal::service('module_installer')->install([
        'dblog',
    ]);
    $view = Views::getView('test_executable_displays');
    $view->initDisplay();
    // Error is logged while calling the wrong display.
    $view->setDisplay('invalid');
    $arguments = [
        '@display_id' => 'invalid',
    ];
    $logged = Database::getConnection()->select('watchdog')
        ->fields('watchdog', [
        'variables',
    ])
        ->condition('type', 'views')
        ->condition('message', 'setDisplay() called with invalid display ID "@display_id".')
        ->execute()
        ->fetchField();
    $this->assertEquals(serialize($arguments), $logged);
    $this->assertEquals('default', $view->current_display, 'If setDisplay is called with an invalid display id the default display should be used.');
    $this->assertEquals(spl_object_hash($view->displayHandlers
        ->get('default')), spl_object_hash($view->display_handler));
}

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