You are here

public function ViewExecutableTest::testPropertyMethods in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Tests/ViewExecutableTest.php \Drupal\views\Tests\ViewExecutableTest::testPropertyMethods()

Tests the setting/getting of properties.

File

core/modules/views/src/Tests/ViewExecutableTest.php, line 279
Contains \Drupal\views\Tests\ViewExecutableTest.

Class

ViewExecutableTest
Tests the ViewExecutable class.

Namespace

Drupal\views\Tests

Code

public function testPropertyMethods() {
  $view = Views::getView('test_executable_displays');

  // Test the setAjaxEnabled() method.
  $this
    ->assertFalse($view
    ->ajaxEnabled());
  $view
    ->setAjaxEnabled(TRUE);
  $this
    ->assertTrue($view
    ->ajaxEnabled());
  $view
    ->setDisplay();

  // There should be no pager set initially.
  $this
    ->assertNull($view
    ->usePager());

  // Add a pager, initialize, and test.
  $view->displayHandlers
    ->get('default')
    ->overrideOption('pager', array(
    'type' => 'full',
    'options' => array(
      'items_per_page' => 10,
    ),
  ));
  $view
    ->initPager();
  $this
    ->assertTrue($view
    ->usePager());

  // Test setting and getting the offset.
  $rand = rand();
  $view
    ->setOffset($rand);
  $this
    ->assertEqual($view
    ->getOffset(), $rand);

  // Test the getBaseTable() method.
  $expected = array(
    'views_test_data' => TRUE,
    '#global' => TRUE,
  );
  $this
    ->assertIdentical($view
    ->getBaseTables(), $expected);

  // Test response methods.
  $this
    ->assertTrue($view
    ->getResponse() instanceof Response, 'New response object returned.');
  $new_response = new Response();
  $view
    ->setResponse($new_response);
  $this
    ->assertIdentical(spl_object_hash($view
    ->getResponse()), spl_object_hash($new_response), 'New response object correctly set.');

  // Test the getPath() method.
  $path = $this
    ->randomMachineName();
  $view->displayHandlers
    ->get('page_1')
    ->overrideOption('path', $path);
  $view
    ->setDisplay('page_1');
  $this
    ->assertEqual($view
    ->getPath(), $path);

  // Test the override_path property override.
  $override_path = $this
    ->randomMachineName();
  $view->override_path = $override_path;
  $this
    ->assertEqual($view
    ->getPath(), $override_path);

  // Test the title methods.
  $title = $this
    ->randomString();
  $view
    ->setTitle($title);
  $this
    ->assertEqual($view
    ->getTitle(), Xss::filterAdmin($title));
}