You are here

public function ViewExecutableTest::testSetDisplayWithInvalidDisplay in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Kernel/ViewExecutableTest.php \Drupal\Tests\views\Kernel\ViewExecutableTest::testSetDisplayWithInvalidDisplay()
  2. 10 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
    ->assertEqual($view->current_display, 'default', 'If setDisplay is called with an invalid display id the default display should be used.');
  $this
    ->assertEqual(spl_object_hash($view->display_handler), spl_object_hash($view->displayHandlers
    ->get('default')));
}