You are here

class RouteGroupContentResolverTest in Organic groups 8

Tests the RouteGroupContentResolver plugin.

@group og @coversDefaultClass \Drupal\og\Plugin\OgGroupResolver\RouteGroupContentResolver

Hierarchy

Expanded class hierarchy of RouteGroupContentResolverTest

File

tests/src/Unit/Plugin/OgGroupResolver/RouteGroupContentResolverTest.php, line 15

Namespace

Drupal\Tests\og\Unit\Plugin\OgGroupResolver
View source
class RouteGroupContentResolverTest extends OgRouteGroupResolverTestBase {

  /**
   * {@inheritdoc}
   */
  protected $className = RouteGroupContentResolver::class;

  /**
   * {@inheritdoc}
   */
  protected $pluginId = 'route_group_content';

  /**
   * {@inheritdoc}
   */
  protected function getInjectedDependencies($path = NULL, $route_object_id = NULL) {
    return [
      $this->routeMatch
        ->reveal(),
      $this->groupTypeManager
        ->reveal(),
      $this->entityTypeManager
        ->reveal(),
      $this->membershipManager
        ->reveal(),
      $this->groupAudienceHelper
        ->reveal(),
    ];
  }

  /**
   * {@inheritdoc}
   */
  protected function getTestEntityProperties() {
    return [
      // A 'normal' test group.
      'group-0' => [
        'type' => 'node',
        'bundle' => 'group',
        'group' => TRUE,
      ],
      // A test group that is also group content for group-0.
      'group-1' => [
        'type' => 'taxonomy_term',
        'bundle' => 'assembly',
        'group' => TRUE,
        'group_content' => [
          'group-0',
        ],
      ],
      // Group content belonging to group-0.
      'group_content-0' => [
        'type' => 'entity_test',
        'bundle' => 'content',
        'group_content' => [
          'group-0',
        ],
      ],
      // Group content belonging to group-1.
      'group_content-1' => [
        'type' => 'node',
        'bundle' => 'article',
        'group_content' => [
          'group-1',
        ],
      ],
      // Group content belonging to both groups.
      'group_content-2' => [
        'type' => 'taxonomy_term',
        'bundle' => 'tags',
        'group_content' => [
          'group-0',
          'group-1',
        ],
      ],
      // An entity that is not a group nor group content.
      'non_group' => [
        'type' => 'entity_test',
        'bundle' => 'non_group',
      ],
    ];
  }

  /**
   * Data provider for testResolve().
   *
   * @see ::testResolve()
   */
  public function resolveProvider() {
    return [
      // Test that no groups are found on a path that is not associated with any
      // entities.
      [
        // A path that is not associated with any entities.
        '/user/logout',
        // There is no entity on this route.
        NULL,
        // So the plugin should not find anything.
        [],
      ],
      // Test that if we are on the canonical entity page of a group, no group
      // should be found.
      [
        // We're on the canonical group entity page.
        '/node/{node}',
        // The test group is found on the route.
        'group-0',
        // This is not a group content entity, so the plugin should not find any
        // results.
        [],
      ],
      // Test that if we are on the delete form of a group, no group is found.
      [
        '/node/{node}/delete',
        'group-0',
        [],
      ],
      // Test that if we are on the edit form of an entity that is both a group
      // and group content, the group is found of which this entity is group
      // content.
      [
        '/taxonomy/term/{taxonomy_term}/edit',
        'group-1',
        [
          'group-0',
        ],
      ],
      // Test that if we are on the canonical entity page of a group content
      // entity that is linked to one group, the group is found.
      [
        '/entity_test/{entity_test}',
        'group_content-0',
        [
          'group-0',
        ],
      ],
      // Test that if we are on the delete form of a group content entity, the
      // group that this group content belongs to is found.
      [
        '/node/{node}/delete',
        'group_content-1',
        [
          'group-1',
        ],
      ],
      // Test that if we are on the canonical entity page of an entity that is
      // group content belonging to two groups, both are found.
      [
        '/taxonomy/term/{taxonomy_term}',
        'group_content-2',
        [
          'group-0',
          'group-1',
        ],
      ],
      // Test that if we are on the canonical entity page of an entity that is
      // neither a group nor group content, no group should be found.
      [
        '/entity_test/{entity_test}',
        'non_group',
        [],
      ],
      // Test that if we are on the delete form of an entity that is neither a
      // group nor group content, no group should be returned.
      [
        '/entity_test/delete/entity_test/{entity_test}',
        'non_group',
        [],
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OgGroupResolverTestBase::$entityTypeManager protected property The mocked entity type manager.
OgGroupResolverTestBase::$groupAudienceHelper protected property The OG group audience helper.
OgGroupResolverTestBase::$groupTypeManager protected property The mocked OG group type manager.
OgGroupResolverTestBase::$membershipManager protected property The OG membership manager.
OgGroupResolverTestBase::$testEntities protected property Mocked test entities.
OgGroupResolverTestBase::createMockedEntity protected function Creates a mocked content entity to use in the test. 1
OgGroupResolverTestBase::getPluginInstance protected function Returns an instance of the plugin under test.
OgGroupResolverTestBase::testStopPropagation public function Tests if the plugin is able to stop the group resolving process.
OgRouteGroupResolverTestBase::$linkTemplates protected property A list of link templates that belong to entity types used in the tests.
OgRouteGroupResolverTestBase::$routeMatch protected property The mocked route matcher.
OgRouteGroupResolverTestBase::getLinkTemplates protected function Returns a set of entity link templates for testing.
OgRouteGroupResolverTestBase::mightCheckIfRouteObjectIsGroup protected function Adds an expectation that checks if the route object is a group.
OgRouteGroupResolverTestBase::mightRetrieveRouteObject protected function Adds an expectation that the plugin will (not) retrieve the route object.
OgRouteGroupResolverTestBase::setUp protected function Overrides OgGroupResolverTestBase::setUp
OgRouteGroupResolverTestBase::testResolve public function @todo Update documentation. Overrides OgGroupResolverTestBase::testResolve
OgRouteGroupResolverTestBase::willRetrieveContentEntityPaths protected function Adds an expectation that the plugin will retrieve a list of entity paths.
OgRouteGroupResolverTestBase::willRetrieveCurrentPathFromRouteMatcher protected function Adds an expectation that the current path will be retrieved from the route.
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.
RouteGroupContentResolverTest::$className protected property The fully qualified class name of the plugin under test. Overrides OgGroupResolverTestBase::$className
RouteGroupContentResolverTest::$pluginId protected property The ID of the plugin under test. Overrides OgGroupResolverTestBase::$pluginId
RouteGroupContentResolverTest::getInjectedDependencies protected function Returns the mocked classes that the plugin depends on. Overrides OgGroupResolverTestBase::getInjectedDependencies
RouteGroupContentResolverTest::getTestEntityProperties protected function Returns properties used to create mock test entities. Overrides OgGroupResolverTestBase::getTestEntityProperties
RouteGroupContentResolverTest::resolveProvider public function Data provider for testResolve().
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.