You are here

public function ViewExecutableTest::testSetDisplayWithInvalidDisplay 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::testSetDisplayWithInvalidDisplay()
  2. 9 core/modules/views/tests/src/Kernel/ViewExecutableTest.php \Drupal\Tests\views\Kernel\ViewExecutableTest::testSetDisplayWithInvalidDisplay()

File

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

Class

ViewExecutableTest
Tests the ViewExecutable class.

Namespace

Drupal\Tests\views\Kernel

Code

public function testSetDisplayWithInvalidDisplay() {
  $view = Views::getView('test_executable_displays');
  $view
    ->initDisplay();

  // Error is triggered while calling the wrong display.
  try {
    $view
      ->setDisplay('invalid');
    $this
      ->fail('Expected error, when setDisplay() called with invalid display ID');
  } catch (Warning $e) {
    $this
      ->assertEquals('setDisplay() called with invalid display ID "invalid".', $e
      ->getMessage());
  }
  $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));
}