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. 8.9.x 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.

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 379

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')
        ->willReturn($view);
    $executable = $this->getMockBuilder('Drupal\\views\\ViewExecutable')
        ->disableOriginalConstructor()
        ->getMock();
    $executable->expects($this->once())
        ->method('access')
        ->willReturn(TRUE);
    $executable->expects($this->any())
        ->method('setDisplay')
        ->willReturn(TRUE);
    $executable->expects($this->atMost(1))
        ->method('preview')
        ->willReturn([
        '#markup' => 'View result',
        '#attached' => [
            'drupalSettings' => [
                'testSetting' => [
                    'Setting',
                ],
            ],
        ],
    ]);
    $this->executableFactory
        ->expects($this->once())
        ->method('get')
        ->with($view)
        ->willReturn($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')
        ->willReturn($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.