function ViewExecutableTest::testAttachDisplays
Same name in other branches
- 8.9.x core/modules/views/tests/src/Unit/ViewExecutableTest.php \Drupal\Tests\views\Unit\ViewExecutableTest::testAttachDisplays()
- 10 core/modules/views/tests/src/Unit/ViewExecutableTest.php \Drupal\Tests\views\Unit\ViewExecutableTest::testAttachDisplays()
- 11.x core/modules/views/tests/src/Unit/ViewExecutableTest.php \Drupal\Tests\views\Unit\ViewExecutableTest::testAttachDisplays()
Tests if a display gets attached or not.
@covers ::attachDisplays @dataProvider providerAttachDisplays
Parameters
bool $display_enabled: Whether the display to test should be enabled.
bool $access_granted: Whether the user has access to the attached display or not.
bool $expected_to_be_attached: Expected result.
File
-
core/
modules/ views/ tests/ src/ Unit/ ViewExecutableTest.php, line 467
Class
- ViewExecutableTest
- @coversDefaultClass \Drupal\views\ViewExecutable @group views
Namespace
Drupal\Tests\views\UnitCode
public function testAttachDisplays($display_enabled, $access_granted, $expected_to_be_attached) {
/** @var \Drupal\views\ViewExecutable|\PHPUnit\Framework\MockObject\MockObject $view */
/** @var \Drupal\views\Plugin\views\display\DisplayPluginBase|\PHPUnit\Framework\MockObject\MockObject $display */
[
$view,
$display,
] = $this->setupBaseViewAndDisplay();
$display->expects($this->atLeastOnce())
->method('acceptAttachments')
->willReturn(TRUE);
$display->expects($this->atLeastOnce())
->method('getAttachedDisplays')
->willReturn([
'page_1',
]);
$page_display = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\DisplayPluginBase')
->disableOriginalConstructor()
->getMock();
$page_display->expects($this->atLeastOnce())
->method('isEnabled')
->willReturn($display_enabled);
$page_display->method('access')
->willReturn($access_granted);
$display_collection = $this->getMockBuilder('Drupal\\views\\DisplayPluginCollection')
->disableOriginalConstructor()
->getMock();
$display_collection->expects($this->atLeastOnce())
->method('get')
->with('page_1')
->willReturn($page_display);
$view->displayHandlers = $display_collection;
// Setup the expectations.
$cloned_view = $this->getMockBuilder('Drupal\\views\\ViewExecutable')
->disableOriginalConstructor()
->getMock();
$this->viewExecutableFactory
->method('get')
->willReturn($cloned_view);
$page_display->expects($expected_to_be_attached ? $this->once() : $this->never())
->method('attachTo')
->with($cloned_view, 'default', $view->element);
$view->attachDisplays();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.