class ActiveWorkspaceCheckTest
Same name in other branches
- 9 core/modules/workspaces/tests/src/Unit/ActiveWorkspaceCheckTest.php \Drupal\Tests\workspaces\Unit\ActiveWorkspaceCheckTest
- 8.9.x core/modules/workspaces/tests/src/Unit/ActiveWorkspaceCheckTest.php \Drupal\Tests\workspaces\Unit\ActiveWorkspaceCheckTest
- 11.x core/modules/workspaces/tests/src/Unit/ActiveWorkspaceCheckTest.php \Drupal\Tests\workspaces\Unit\ActiveWorkspaceCheckTest
@coversDefaultClass \Drupal\workspaces\Access\ActiveWorkspaceCheck
@group workspaces @group Access
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\workspaces\Unit\ActiveWorkspaceCheckTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of ActiveWorkspaceCheckTest
File
-
core/
modules/ workspaces/ tests/ src/ Unit/ ActiveWorkspaceCheckTest.php, line 21
Namespace
Drupal\Tests\workspaces\UnitView source
class ActiveWorkspaceCheckTest extends UnitTestCase {
/**
* The dependency injection container.
*
* @var \Symfony\Component\DependencyInjection\ContainerBuilder
*/
protected $container;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->container = new ContainerBuilder();
$cache_contexts_manager = $this->prophesize(CacheContextsManager::class);
$cache_contexts_manager->assertValidTokens()
->willReturn(TRUE);
$cache_contexts_manager->reveal();
$this->container
->set('cache_contexts_manager', $cache_contexts_manager);
\Drupal::setContainer($this->container);
}
/**
* Provides data for the testAccess method.
*
* @return array
*/
public static function providerTestAccess() {
return [
[
[],
FALSE,
FALSE,
],
[
[],
TRUE,
FALSE,
],
[
[
'_has_active_workspace' => 'TRUE',
],
TRUE,
TRUE,
[
'workspace',
],
],
[
[
'_has_active_workspace' => 'TRUE',
],
FALSE,
FALSE,
[
'workspace',
],
],
[
[
'_has_active_workspace' => 'FALSE',
],
TRUE,
FALSE,
[
'workspace',
],
],
[
[
'_has_active_workspace' => 'FALSE',
],
FALSE,
TRUE,
[
'workspace',
],
],
];
}
/**
* @covers ::access
* @dataProvider providerTestAccess
*/
public function testAccess($requirements, $has_active_workspace, $access, array $contexts = []) : void {
$route = new Route('', [], $requirements);
$workspace_manager = $this->prophesize(WorkspaceManagerInterface::class);
$workspace_manager->hasActiveWorkspace()
->willReturn($has_active_workspace);
$access_check = new ActiveWorkspaceCheck($workspace_manager->reveal());
$access_result = AccessResult::allowedIf($access)->addCacheContexts($contexts);
$this->assertEquals($access_result, $access_check->access($route));
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|---|
ActiveWorkspaceCheckTest::$container | protected | property | The dependency injection container. | |||
ActiveWorkspaceCheckTest::providerTestAccess | public static | function | Provides data for the testAccess method. | |||
ActiveWorkspaceCheckTest::setUp | protected | function | Overrides UnitTestCase::setUp | |||
ActiveWorkspaceCheckTest::testAccess | public | function | @covers ::access @dataProvider providerTestAccess |
|||
PhpUnitWarnings::$deprecationWarnings | private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |||
PhpUnitWarnings::addWarning | public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |||
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. | |||
RandomGeneratorTrait::randomStringValidate | Deprecated | public | function | Callback for random string validation. | ||
UnitTestCase::$root | protected | property | The app root. | 1 | ||
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 | ||||
UnitTestCase::__get | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.