You are here

public function ViewExecutableTest::testAttachDisplays in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Unit/ViewExecutableTest.php \Drupal\Tests\views\Unit\ViewExecutableTest::testAttachDisplays()
  2. 10 core/modules/views/tests/src/Unit/ViewExecutableTest.php \Drupal\Tests\views\Unit\ViewExecutableTest::testAttachDisplays()

@covers ::attachDisplays

File

core/modules/views/tests/src/Unit/ViewExecutableTest.php, line 447

Class

ViewExecutableTest
@coversDefaultClass \Drupal\views\ViewExecutable @group views

Namespace

Drupal\Tests\views\Unit

Code

public function testAttachDisplays() {

  /** @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',
  ]);
  $cloned_view = $this
    ->getMockBuilder('Drupal\\views\\ViewExecutable')
    ->disableOriginalConstructor()
    ->getMock();
  $this->viewExecutableFactory
    ->expects($this
    ->atLeastOnce())
    ->method('get')
    ->willReturn($cloned_view);
  $page_display = $this
    ->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\DisplayPluginBase')
    ->disableOriginalConstructor()
    ->getMock();
  $page_display
    ->expects($this
    ->atLeastOnce())
    ->method('isEnabled')
    ->willReturn(TRUE);
  $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.
  $page_display
    ->expects($this
    ->once())
    ->method('attachTo')
    ->with($cloned_view, 'default', $view->element);
  $view
    ->attachDisplays();
}