class OgLocalTaskTest in Organic groups 8
Tests OG local task definition.
Assert that the "Group" tab is properly added.
@group og @coversDefaultClass \Drupal\og\Plugin\Derivative\OgLocalTask
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\og\Unit\OgLocalTaskTest
Expanded class hierarchy of OgLocalTaskTest
File
- tests/
src/ Unit/ OgLocalTaskTest.php, line 22
Namespace
Drupal\Tests\og\UnitView source
class OgLocalTaskTest extends UnitTestCase {
/**
* The group type manager.
*
* @var \Drupal\og\GroupTypeManagerInterface|\Prophecy\Prophecy\ObjectProphecy
*/
protected $groupTypeManager;
/**
* Route provider object.
*
* @var \Drupal\Core\Routing\RouteProvider|\Prophecy\Prophecy\ObjectProphecy
*/
protected $routeProvider;
/**
* The route service.
*
* @var \Symfony\Component\Routing\Route|\Prophecy\Prophecy\ObjectProphecy
*/
protected $route;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
$this->groupTypeManager = $this
->prophesize(GroupTypeManagerInterface::class);
$this->routeProvider = $this
->prophesize(RouteProvider::class);
$this->route = $this
->prophesize(Route::class);
$container = new ContainerBuilder();
$container
->set('string_translation', $this
->getStringTranslationStub());
\Drupal::setContainer($container);
}
/**
* Tests setting local task definitions.
*
* @covers ::getDerivativeDefinitions
*/
public function testGetDerivativeDefinitions() {
$entity_type_id1 = $this
->randomMachineName();
$entity_type_id2 = $this
->randomMachineName();
$group_map = [
// We don't need to add the bundles data, as they are skipped by doing
// array_keys() on the tested method.
$entity_type_id1 => [],
$entity_type_id2 => [],
];
$this->groupTypeManager
->getGroupMap()
->willReturn($group_map);
foreach (array_keys($group_map) as $entity_type_id) {
$route_name = "entity.{$entity_type_id}.og_admin_routes";
$this->routeProvider
->getRoutesByNames([
$route_name,
])
->willReturn([
$this->route
->reveal(),
$this->route
->reveal(),
]);
}
$og_local_task = new OgLocalTask($this->groupTypeManager
->reveal(), $this->routeProvider
->reveal());
$derivatives = $og_local_task
->getDerivativeDefinitions([]);
$this
->assertCount(2, $derivatives);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OgLocalTaskTest:: |
protected | property | The group type manager. | |
OgLocalTaskTest:: |
protected | property | The route service. | |
OgLocalTaskTest:: |
protected | property | Route provider object. | |
OgLocalTaskTest:: |
protected | function |
Overrides UnitTestCase:: |
|
OgLocalTaskTest:: |
public | function | Tests setting local task definitions. | |
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. |