function ViewExecutableTest::testPropertyMethods
Same name in other branches
- 8.9.x 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->assertEquals($rand, $view->getOffset());
// Test the getBaseTable() method.
$expected = [
'views_test_data' => TRUE,
'#global' => TRUE,
];
$this->assertSame($expected, $view->getBaseTables());
// Test response methods.
$this->assertInstanceOf(Response::class, $view->getResponse());
$new_response = new Response();
$view->setResponse($new_response);
$this->assertSame(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->assertEquals($path, $view->getPath());
// Test the override_path property override.
$override_path = $this->randomMachineName();
$view->override_path = $override_path;
$this->assertEquals($override_path, $view->getPath());
// Test the title methods.
$title = $this->randomString();
$view->setTitle($title);
$this->assertEquals(Xss::filterAdmin($title), $view->getTitle());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.