You are here

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

Expanded class hierarchy of OgLocalTaskTest

File

tests/src/Unit/OgLocalTaskTest.php, line 22

Namespace

Drupal\Tests\og\Unit
View 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

Namesort descending Modifiers Type Description Overrides
OgLocalTaskTest::$groupTypeManager protected property The group type manager.
OgLocalTaskTest::$route protected property The route service.
OgLocalTaskTest::$routeProvider protected property Route provider object.
OgLocalTaskTest::setUp protected function Overrides UnitTestCase::setUp
OgLocalTaskTest::testGetDerivativeDefinitions public function Tests setting local task definitions.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 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::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.