ViewInclusionTest.php in Context 8.4
File
tests/src/Kernel/ViewInclusionTest.php
View source
<?php
namespace Drupal\Tests\context\Kernel;
use Drupal\Core\Path\CurrentPathStack;
use Drupal\Core\Routing\CurrentRouteMatch;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Route;
class ViewInclusionTest extends KernelTestBase {
protected static $modules = [
'context',
];
protected $pluginManager;
protected $requestStack;
protected $currentPath;
protected function setUp() : void {
parent::setUp();
$this->pluginManager = $this->container
->get('plugin.manager.condition');
$this->requestStack = new RequestStack();
$this->container
->set('request_stack', $this->requestStack);
$this->currentPath = new CurrentPathStack($this->requestStack);
$this->container
->set('path.current', $this->currentPath);
$this->container
->set('current_route_match', new CurrentRouteMatch($this->requestStack));
}
public function testViewInclusion() {
$request = Request::create('');
$request->attributes
->set('_route', 'view-frontpage-page_1');
$request->attributes
->set('_route_object', new Route('/node/'));
$this->requestStack
->push($request);
$condition = $this->pluginManager
->createInstance('view_inclusion');
$condition
->setConfig('view_inclusion', [
'view-frontpage-page_1' => 'view-frontpage-page_1',
]);
$this
->assertTrue($condition
->execute(), 'The path does not match');
$condition
->setConfig('view_inclusion', [
'view-user_admin_people-page_1' => 'view-user_admin_people-page_1',
]);
$this
->assertFalse($condition
->execute(), 'The path does match');
}
}