You are here

protected function RouteSubscriberTest::setupMocks in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/tests/src/Unit/EventSubscriber/RouteSubscriberTest.php \Drupal\Tests\views\Unit\EventSubscriber\RouteSubscriberTest::setupMocks()

Sets up mocks of Views objects needed for testing.

Return value

array \Drupal\views\Plugin\views\display\DisplayRouterInterface[]|\PHPUnit_Framework_MockObject_MockObject[] An array of two mocked view displays

2 calls to RouteSubscriberTest::setupMocks()
RouteSubscriberTest::testOnAlterRoutes in core/modules/views/tests/src/Unit/EventSubscriber/RouteSubscriberTest.php
Tests the onAlterRoutes method.
RouteSubscriberTest::testRouteRebuildFinished in core/modules/views/tests/src/Unit/EventSubscriber/RouteSubscriberTest.php
@covers ::routeRebuildFinished

File

core/modules/views/tests/src/Unit/EventSubscriber/RouteSubscriberTest.php, line 145
Contains \Drupal\Tests\views\Unit\EventSubscriber\RouteSubscriberTest.

Class

RouteSubscriberTest
@coversDefaultClass \Drupal\views\EventSubscriber\RouteSubscriber @group views

Namespace

Drupal\Tests\views\Unit\EventSubscriber

Code

protected function setupMocks() {
  $executable = $this
    ->getMockBuilder('Drupal\\views\\ViewExecutable')
    ->disableOriginalConstructor()
    ->getMock();
  $view = $this
    ->getMockBuilder('Drupal\\views\\Entity\\View')
    ->disableOriginalConstructor()
    ->getMock();
  $this->viewStorage
    ->expects($this
    ->any())
    ->method('load')
    ->will($this
    ->returnValue($view));
  $view
    ->expects($this
    ->any())
    ->method('getExecutable')
    ->will($this
    ->returnValue($executable));
  $view
    ->expects($this
    ->any())
    ->method('id')
    ->will($this
    ->returnValue('test_id'));
  $executable->storage = $view;
  $executable
    ->expects($this
    ->any())
    ->method('setDisplay')
    ->will($this
    ->returnValueMap(array(
    array(
      'page_1',
      TRUE,
    ),
    array(
      'page_2',
      TRUE,
    ),
    array(
      'page_3',
      FALSE,
    ),
  )));

  // Ensure that only the first two displays are actually called.
  $display_1 = $this
    ->getMock('Drupal\\views\\Plugin\\views\\display\\DisplayRouterInterface');
  $display_2 = $this
    ->getMock('Drupal\\views\\Plugin\\views\\display\\DisplayRouterInterface');
  $display_collection = $this
    ->getMockBuilder('Drupal\\views\\DisplayPluginCollection')
    ->disableOriginalConstructor()
    ->getMock();
  $display_collection
    ->expects($this
    ->any())
    ->method('get')
    ->will($this
    ->returnValueMap(array(
    array(
      'page_1',
      $display_1,
    ),
    array(
      'page_2',
      $display_2,
    ),
  )));
  $executable->displayHandlers = $display_collection;
  $this->routeSubscriber->applicableViews = array();
  $this->routeSubscriber->applicableViews[] = array(
    'test_id',
    'page_1',
  );
  $this->routeSubscriber->applicableViews[] = array(
    'test_id',
    'page_2',
  );
  $this->routeSubscriber->applicableViews[] = array(
    'test_id',
    'page_3',
  );
  return array(
    $display_1,
    $display_2,
  );
}