class WorkspaceRequestSubscriberTest

Same name and namespace in other branches
  1. 9 core/modules/workspaces/tests/src/Unit/WorkspaceRequestSubscriberTest.php \Drupal\Tests\workspaces\Unit\WorkspaceRequestSubscriberTest
  2. 8.9.x core/modules/workspaces/tests/src/Unit/WorkspaceRequestSubscriberTest.php \Drupal\Tests\workspaces\Unit\WorkspaceRequestSubscriberTest
  3. 10 core/modules/workspaces/tests/src/Unit/WorkspaceRequestSubscriberTest.php \Drupal\Tests\workspaces\Unit\WorkspaceRequestSubscriberTest

@coversDefaultClass \Drupal\workspaces\EventSubscriber\WorkspaceRequestSubscriber

@group workspaces

Hierarchy

Expanded class hierarchy of WorkspaceRequestSubscriberTest

File

core/modules/workspaces/tests/src/Unit/WorkspaceRequestSubscriberTest.php, line 20

Namespace

Drupal\Tests\workspaces\Unit
View source
class WorkspaceRequestSubscriberTest extends UnitTestCase {
  
  /**
   * The workspace manager.
   *
   * @var \Drupal\workspaces\WorkspaceManagerInterface
   */
  protected $workspaceManager;
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $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() : void {
    $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($route_provider->reveal(), $this->workspaceManager
      ->reveal());
    $event = $this->prophesize(RequestEvent::class)
      ->reveal();
    $this->assertNull($workspace_request_subscriber->onKernelRequest($event));
  }
  
  /**
   * @covers ::onKernelRequest
   */
  public function testOnKernelRequestWithoutCacheableRouteProvider() : void {
    $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($route_provider->reveal(), $this->workspaceManager
      ->reveal());
    $event = $this->prophesize(RequestEvent::class)
      ->reveal();
    $this->assertNull($workspace_request_subscriber->onKernelRequest($event));
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
ExpectDeprecationTrait::expectDeprecation public function Adds an expected deprecation.
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::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::setDebugDumpHandler public static function Registers the dumper CLI handler when the DebugDump extension is enabled.
UnitTestCase::setupMockIterator protected function Set up a traversable class mock to return specific items when iterated.
WorkspaceRequestSubscriberTest::$workspaceManager protected property The workspace manager.
WorkspaceRequestSubscriberTest::setUp protected function Overrides UnitTestCase::setUp
WorkspaceRequestSubscriberTest::testOnKernelRequestWithCacheableRouteProvider public function @covers ::onKernelRequest[[api-linebreak]]
WorkspaceRequestSubscriberTest::testOnKernelRequestWithoutCacheableRouteProvider public function @covers ::onKernelRequest[[api-linebreak]]

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