class ViewExecutableFactoryTest

Same name in other branches
  1. 9 core/modules/views/tests/src/Unit/ViewExecutableFactoryTest.php \Drupal\Tests\views\Unit\ViewExecutableFactoryTest
  2. 8.9.x core/modules/views/tests/src/Unit/ViewExecutableFactoryTest.php \Drupal\Tests\views\Unit\ViewExecutableFactoryTest
  3. 10 core/modules/views/tests/src/Unit/ViewExecutableFactoryTest.php \Drupal\Tests\views\Unit\ViewExecutableFactoryTest

@coversDefaultClass \Drupal\views\ViewExecutableFactory @group views

Hierarchy

Expanded class hierarchy of ViewExecutableFactoryTest

File

core/modules/views/tests/src/Unit/ViewExecutableFactoryTest.php, line 16

Namespace

Drupal\Tests\views\Unit
View source
class ViewExecutableFactoryTest extends UnitTestCase {
    
    /**
     * The mock user object.
     *
     * @var \Drupal\Core\Session\AccountInterface|\PHPUnit\Framework\MockObject\MockObject
     */
    protected $user;
    
    /**
     * The mock request stack object.
     *
     * @var \Symfony\Component\HttpFoundation\RequestStack
     */
    protected $requestStack;
    
    /**
     * The mock view entity.
     *
     * @var \Drupal\Core\Config\Entity\ConfigEntityInterface|\PHPUnit\Framework\MockObject\MockObject
     */
    protected $view;
    
    /**
     * The ViewExecutableFactory class under test.
     *
     * @var \Drupal\views\ViewExecutableFactory
     */
    protected $viewExecutableFactory;
    
    /**
     * The mocked views data.
     *
     * @var \Drupal\views\ViewsData|\PHPUnit\Framework\MockObject\MockObject
     */
    protected $viewsData;
    
    /**
     * The mocked route provider.
     *
     * @var \Drupal\Core\Routing\RouteProviderInterface|\PHPUnit\Framework\MockObject\MockObject
     */
    protected $routeProvider;
    
    /**
     * The display plugin manager.
     *
     * @var \Drupal\Component\Plugin\PluginManagerInterface
     */
    protected $displayPluginManager;
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() : void {
        parent::setUp();
        $this->user = $this->createMock('Drupal\\Core\\Session\\AccountInterface');
        $this->requestStack = new RequestStack();
        $this->view = $this->createMock('Drupal\\views\\ViewEntityInterface');
        $this->viewsData = $this->getMockBuilder('Drupal\\views\\ViewsData')
            ->disableOriginalConstructor()
            ->getMock();
        $this->routeProvider = $this->createMock('Drupal\\Core\\Routing\\RouteProviderInterface');
        $this->displayPluginManager = $this->getMockBuilder('\\Drupal\\views\\Plugin\\ViewsPluginManager')
            ->disableOriginalConstructor()
            ->getMock();
        $this->viewExecutableFactory = new ViewExecutableFactory($this->user, $this->requestStack, $this->viewsData, $this->routeProvider, $this->displayPluginManager);
    }
    
    /**
     * Tests the get method.
     *
     * @covers ::get
     */
    public function testGet() : void {
        $request_1 = new Request();
        $request_2 = new Request();
        $this->requestStack
            ->push($request_1);
        $executable = $this->viewExecutableFactory
            ->get($this->view);
        $this->assertInstanceOf('Drupal\\views\\ViewExecutable', $executable);
        $this->assertSame($executable->getRequest(), $request_1);
        $this->assertSame($executable->getUser(), $this->user);
        // Call get() again to ensure a new executable is created with the other
        // request object.
        $this->requestStack
            ->push($request_2);
        $executable = $this->viewExecutableFactory
            ->get($this->view);
        $this->assertInstanceOf('Drupal\\views\\ViewExecutable', $executable);
        $this->assertSame($executable->getRequest(), $request_2);
        $this->assertSame($executable->getUser(), $this->user);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
ExpectDeprecationTrait::expectDeprecation public function Adds an expected deprecation.
ExpectDeprecationTrait::getCallableName private static function Returns a callable as a string suitable for inclusion in a message.
ExpectDeprecationTrait::setUpErrorHandler public function Sets up the test error handler.
ExpectDeprecationTrait::tearDownErrorHandler public function Tears down the test error handler.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
UnitTestCase::$root protected property The app root.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setUpBeforeClass public static function
ViewExecutableFactoryTest::$displayPluginManager protected property The display plugin manager.
ViewExecutableFactoryTest::$requestStack protected property The mock request stack object.
ViewExecutableFactoryTest::$routeProvider protected property The mocked route provider.
ViewExecutableFactoryTest::$user protected property The mock user object.
ViewExecutableFactoryTest::$view protected property The mock view entity.
ViewExecutableFactoryTest::$viewExecutableFactory protected property The ViewExecutableFactory class under test.
ViewExecutableFactoryTest::$viewsData protected property The mocked views data.
ViewExecutableFactoryTest::setUp protected function Overrides UnitTestCase::setUp
ViewExecutableFactoryTest::testGet public function Tests the get method.

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