You are here

public function ViewExecutableTest::testExecuteReturn in Drupal 9

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

Tests the return values for the execute() method.

@covers ::execute @dataProvider providerExecuteReturn

Parameters

bool $display_enabled: Whether the display to test should be enabled.

bool $expected_result: The expected result when calling execute().

File

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

Class

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

Namespace

Drupal\Tests\views\Unit

Code

public function testExecuteReturn($display_enabled, $expected_result) {

  /** @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
    ->any())
    ->method('isEnabled')
    ->willReturn($display_enabled);

  // Pager needs to be set to avoid false test failures.
  $view->pager = $this
    ->getMockBuilder(NonePager::class)
    ->disableOriginalConstructor()
    ->getMock();
  $query = $this
    ->getMockBuilder(QueryPluginBase::class)
    ->disableOriginalConstructor()
    ->getMock();
  $view->query = $query;
  $view->built = TRUE;
  $this
    ->assertEquals($expected_result, $view
    ->execute());
}