class WorkspaceRequestSubscriberTest in Drupal 8
Same name and namespace in other branches
- 9 core/modules/workspaces/tests/src/Unit/WorkspaceRequestSubscriberTest.php \Drupal\Tests\workspaces\Unit\WorkspaceRequestSubscriberTest
- 10 core/modules/workspaces/tests/src/Unit/WorkspaceRequestSubscriberTest.php \Drupal\Tests\workspaces\Unit\WorkspaceRequestSubscriberTest
@coversDefaultClass \Drupal\workspaces\EventSubscriber\WorkspaceRequestSubscriber
@group workspace
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\workspaces\Unit\WorkspaceRequestSubscriberTest
Expanded class hierarchy of WorkspaceRequestSubscriberTest
File
- core/
modules/ workspaces/ tests/ src/ Unit/ WorkspaceRequestSubscriberTest.php, line 20
Namespace
Drupal\Tests\workspaces\UnitView source
class WorkspaceRequestSubscriberTest extends UnitTestCase {
/**
* @var \Drupal\path_alias\AliasManagerInterface
*/
protected $aliasManager;
/**
* @var \Drupal\Core\Path\CurrentPathStack
*/
protected $currentPath;
/**
* @var \Drupal\workspaces\WorkspaceManagerInterface
*/
protected $workspaceManager;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->aliasManager = $this
->prophesize(AliasManagerInterface::class)
->reveal();
$this->currentPath = $this
->prophesize(CurrentPathStack::class)
->reveal();
$this->workspaceManager = $this
->prophesize(WorkspaceManagerInterface::class);
$active_workspace = $this
->prophesize(WorkspaceInterface::class);
$active_workspace
->id()
->willReturn('test');
$this->workspaceManager
->getActiveWorkspace()
->willReturn($active_workspace
->reveal());
$this->workspaceManager
->hasActiveWorkspace()
->willReturn(TRUE);
}
/**
* @covers ::onKernelRequest
*/
public function testOnKernelRequestWithCacheableRouteProvider() {
$route_provider = $this
->prophesize(CacheableRouteProviderInterface::class);
$route_provider
->addExtraCacheKeyPart('workspace', 'test')
->shouldBeCalled();
// Check that WorkspaceRequestSubscriber::onKernelRequest() calls
// addExtraCacheKeyPart() on a route provider that implements
// CacheableRouteProviderInterface.
$workspace_request_subscriber = new WorkspaceRequestSubscriber($this->aliasManager, $this->currentPath, $route_provider
->reveal(), $this->workspaceManager
->reveal());
$event = $this
->prophesize(GetResponseEvent::class)
->reveal();
$this
->assertNull($workspace_request_subscriber
->onKernelRequest($event));
}
/**
* @covers ::onKernelRequest
*/
public function testOnKernelRequestWithoutCacheableRouteProvider() {
$route_provider = $this
->prophesize(RouteProviderInterface::class);
// Check that WorkspaceRequestSubscriber::onKernelRequest() doesn't call
// addExtraCacheKeyPart() on a route provider that does not implement
// CacheableRouteProviderInterface.
$workspace_request_subscriber = new WorkspaceRequestSubscriber($this->aliasManager, $this->currentPath, $route_provider
->reveal(), $this->workspaceManager
->reveal());
$event = $this
->prophesize(GetResponseEvent::class)
->reveal();
$this
->assertNull($workspace_request_subscriber
->onKernelRequest($event));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
WorkspaceRequestSubscriberTest:: |
protected | property | ||
WorkspaceRequestSubscriberTest:: |
protected | property | ||
WorkspaceRequestSubscriberTest:: |
protected | property | ||
WorkspaceRequestSubscriberTest:: |
protected | function |
Overrides UnitTestCase:: |
|
WorkspaceRequestSubscriberTest:: |
public | function | @covers ::onKernelRequest | |
WorkspaceRequestSubscriberTest:: |
public | function | @covers ::onKernelRequest |