You are here

protected function ViewAjaxControllerTest::setupValidMocks in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php \Drupal\Tests\views\Unit\Controller\ViewAjaxControllerTest::setupValidMocks()

Sets up a bunch of valid mocks like the view entity and executable.

Parameters

bool $use_ajax: Whether the 'use_ajax' option is set on the view display. Defaults to using ajax (TRUE).

Return value

array A pair of view storage entity and executable.

7 calls to ViewAjaxControllerTest::setupValidMocks()
ViewAjaxControllerTest::testAjaxView in core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php
Tests a valid view without arguments pagers etc.
ViewAjaxControllerTest::testAjaxViewViewPathNoSlash in core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php
Tests a valid view with a view_path with no slash.
ViewAjaxControllerTest::testAjaxViewWithArguments in core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php
Tests a valid view with arguments.
ViewAjaxControllerTest::testAjaxViewWithEmptyArguments in core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php
Tests a valid view with arguments.
ViewAjaxControllerTest::testAjaxViewWithHtmlEntityArguments in core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php
Tests a valid view with arguments.

... See full list

File

core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php, line 365

Class

ViewAjaxControllerTest
@coversDefaultClass \Drupal\views\Controller\ViewAjaxController @group views

Namespace

Drupal\Tests\views\Unit\Controller

Code

protected function setupValidMocks($use_ajax = self::USE_AJAX) {
  $view = $this
    ->getMockBuilder('Drupal\\views\\Entity\\View')
    ->disableOriginalConstructor()
    ->getMock();
  $this->viewStorage
    ->expects($this
    ->once())
    ->method('load')
    ->with('test_view')
    ->will($this
    ->returnValue($view));
  $executable = $this
    ->getMockBuilder('Drupal\\views\\ViewExecutable')
    ->disableOriginalConstructor()
    ->getMock();
  $executable
    ->expects($this
    ->once())
    ->method('access')
    ->will($this
    ->returnValue(TRUE));
  $executable
    ->expects($this
    ->any())
    ->method('setDisplay')
    ->willReturn(TRUE);
  $executable
    ->expects($this
    ->atMost(1))
    ->method('preview')
    ->will($this
    ->returnValue([
    '#markup' => 'View result',
  ]));
  $this->executableFactory
    ->expects($this
    ->once())
    ->method('get')
    ->with($view)
    ->will($this
    ->returnValue($executable));
  $display_handler = $this
    ->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\DisplayPluginBase')
    ->disableOriginalConstructor()
    ->getMock();

  // Ensure that the pager element is not set.
  $display_handler
    ->expects($this
    ->never())
    ->method('setOption');
  $display_handler
    ->expects($this
    ->any())
    ->method('ajaxEnabled')
    ->willReturn($use_ajax);
  $display_collection = $this
    ->getMockBuilder('Drupal\\views\\DisplayPluginCollection')
    ->disableOriginalConstructor()
    ->getMock();
  $display_collection
    ->expects($this
    ->any())
    ->method('get')
    ->with('page_1')
    ->will($this
    ->returnValue($display_handler));
  $executable->display_handler = $display_handler;
  $executable->displayHandlers = $display_collection;
  return [
    $view,
    $executable,
  ];
}