public function ViewExecutableTest::testDisplays

Tests the display related methods and properties.

File

drupal/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.php, line 117
Definition of Drupal\views\Tests\ViewExecutableTest.

Class

ViewExecutableTest
Tests the ViewExecutable class.

Namespace

Drupal\views\Tests

Code

public function testDisplays() {
  $view = views_get_view('test_executable_displays');

  // Tests Drupal\views\ViewExecutable::initDisplay().
  $view
    ->initDisplay();
  $count = count($view->displayHandlers);
  $this
    ->assertEqual($count, 3, format_string('Make sure all display handlers got instantiated (@count of @count_expected)', array(
    '@count' => $count,
    '@count_expected' => 3,
  )));

  // Tests the classes of the instances.
  $this
    ->assertTrue($view->displayHandlers['default'] instanceof DefaultDisplay);
  $this
    ->assertTrue($view->displayHandlers['page'] instanceof Page);
  $this
    ->assertTrue($view->displayHandlers['page_2'] instanceof Page);

  // After initializing the default display is the current used display.
  $this
    ->assertEqual($view->current_display, 'default');
  $this
    ->assertEqual(spl_object_hash($view->display_handler), spl_object_hash($view->displayHandlers['default']));

  // All handlers should have a reference to the default display.
  $this
    ->assertEqual(spl_object_hash($view->displayHandlers['page']->default_display), spl_object_hash($view->displayHandlers['default']));
  $this
    ->assertEqual(spl_object_hash($view->displayHandlers['page_2']->default_display), spl_object_hash($view->displayHandlers['default']));

  // Tests Drupal\views\ViewExecutable::setDisplay().
  $view
    ->setDisplay();
  $this
    ->assertEqual($view->current_display, 'default', 'If setDisplay is called with no parameter the default display should be used.');
  $this
    ->assertEqual(spl_object_hash($view->display_handler), spl_object_hash($view->displayHandlers['default']));

  // Set two different valid displays.
  $view
    ->setDisplay('page');
  $this
    ->assertEqual($view->current_display, 'page', 'If setDisplay is called with a valid display id the appropriate display should be used.');
  $this
    ->assertEqual(spl_object_hash($view->display_handler), spl_object_hash($view->displayHandlers['page']));
  $view
    ->setDisplay('page_2');
  $this
    ->assertEqual($view->current_display, 'page_2', 'If setDisplay is called with a valid display id the appropriate display should be used.');
  $this
    ->assertEqual(spl_object_hash($view->display_handler), spl_object_hash($view->displayHandlers['page_2']));
}