function ViewAjaxControllerTest::setupValidMocks

Same name in other branches
  1. 9 core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php \Drupal\Tests\views\Unit\Controller\ViewAjaxControllerTest::setupValidMocks()
  2. 10 core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php \Drupal\Tests\views\Unit\Controller\ViewAjaxControllerTest::setupValidMocks()
  3. 11.x 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.

6 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::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.
ViewAjaxControllerTest::testAjaxViewWithoutAjax in core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php
Tests a valid view without ajax enabled.

... See full list

File

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

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,
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.