diff --git a/core/modules/views/src/ViewExecutable.php b/core/modules/views/src/ViewExecutable.php index da859252cd7..c8b059332db 100644 --- a/core/modules/views/src/ViewExecutable.php +++ b/core/modules/views/src/ViewExecutable.php @@ -1421,7 +1421,7 @@ class ViewExecutable implements \Serializable { // Let modules modify the view just after executing it. $module_handler->invokeAll('views_post_execute', array($this)); - $this->executed = TRUE; + return $this->executed = TRUE; } /** diff --git a/core/modules/views/tests/src/Unit/ViewExecutableTest.php b/core/modules/views/tests/src/Unit/ViewExecutableTest.php index d3e2222429c..fe64ec27880 100644 --- a/core/modules/views/tests/src/Unit/ViewExecutableTest.php +++ b/core/modules/views/tests/src/Unit/ViewExecutableTest.php @@ -21,6 +21,16 @@ use Symfony\Component\Routing\Route; */ class ViewExecutableTest extends UnitTestCase { + /** + * Indicates that a display is enabled. + */ + const DISPLAY_ENABLED = TRUE; + + /** + * Indicates that a display is disabled. + */ + const DISPLAY_DISABLED = FALSE; + /** * A mocked display collection. * @@ -632,4 +642,52 @@ class ViewExecutableTest extends UnitTestCase { $view->execute(); } + /** + * Tests the return values for the execute() method. + * + * @param bool $display_enabled + * Whether the display to test should be enabled. + * @param bool $expected_result + * The expected result when calling execute(). + * + * @covers ::execute + * @dataProvider providerExecuteReturn + */ + 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()); + } + + /** + * Provider for testExecuteReturn(). + * + * @return array[] + * An array of arrays containing the display state and expected value. + */ + public function providerExecuteReturn() { + return [ + 'enabled' => [static::DISPLAY_ENABLED, TRUE], + 'disabled' => [static::DISPLAY_DISABLED, FALSE], + ]; + } + }