public function ViewExecutableTest::testAttachDisplays in Drupal 9
Same name and namespace in other branches
- 8 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()
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 */
list($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();
}