function ViewExecutableTest::testPropertyMethods
Same name in other branches
- 9 core/modules/views/tests/src/Kernel/ViewExecutableTest.php \Drupal\Tests\views\Kernel\ViewExecutableTest::testPropertyMethods()
- 10 core/modules/views/tests/src/Kernel/ViewExecutableTest.php \Drupal\Tests\views\Kernel\ViewExecutableTest::testPropertyMethods()
- 11.x core/modules/views/tests/src/Kernel/ViewExecutableTest.php \Drupal\Tests\views\Kernel\ViewExecutableTest::testPropertyMethods()
Tests the setting/getting of properties.
File
-
core/
modules/ views/ tests/ src/ Kernel/ ViewExecutableTest.php, line 294
Class
- ViewExecutableTest
- Tests the ViewExecutable class.
Namespace
Drupal\Tests\views\KernelCode
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', [
'type' => 'full',
'options' => [
'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 = [
'views_test_data' => TRUE,
'#global' => TRUE,
];
$this->assertIdentical($view->getBaseTables(), $expected);
// Test response methods.
$this->assertInstanceOf(Response::class, $view->getResponse());
$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));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.