ViewExecutableFactoryTest.php in Drupal 10
File
core/modules/views/tests/src/Unit/ViewExecutableFactoryTest.php
View source
<?php
namespace Drupal\Tests\views\Unit;
use Drupal\Tests\UnitTestCase;
use Drupal\views\ViewExecutableFactory;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
class ViewExecutableFactoryTest extends UnitTestCase {
protected $user;
protected $requestStack;
protected $view;
protected $viewExecutableFactory;
protected $viewsData;
protected $routeProvider;
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->viewExecutableFactory = new ViewExecutableFactory($this->user, $this->requestStack, $this->viewsData, $this->routeProvider);
}
public function testGet() {
$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);
$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);
}
}