og-8.x-1.x-dev/tests/src/Unit/Plugin/OgGroupResolver/RouteGroupResolverTest.php

tests/src/Unit/Plugin/OgGroupResolver/RouteGroupResolverTest.php
<?php

declare(strict_types=1);

namespace Drupal\Tests\og\Unit\Plugin\OgGroupResolver;

use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\og\Plugin\OgGroupResolver\RouteGroupResolver;
use Prophecy\PhpUnit\ProphecyTrait;

/**
 * Tests the RouteGroupResolver plugin.
 *
 * @group og
 * @coversDefaultClass \Drupal\og\Plugin\OgGroupResolver\RouteGroupResolver
 */
class RouteGroupResolverTest extends OgRouteGroupResolverTestBase {

  use ProphecyTrait;

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

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

  /**
   * {@inheritdoc}
   */
  protected function getInjectedDependencies(): array {
    return [
      $this->routeMatch->reveal(),
      $this->groupTypeManager->reveal(),
      $this->entityTypeManager->reveal(),
    ];
  }

  /**
   * {@inheritdoc}
   */
  protected function getTestEntityProperties(): array {
    return [
      'group' => ['type' => 'node', 'bundle' => 'group', 'group' => TRUE],
      'group_content' => ['type' => 'entity_test', 'bundle' => 'group_content'],
      'non_group' => ['type' => 'taxonomy_term', 'bundle' => 'taxonomy_term'],
    ];
  }

  /**
   * Returns a list of test entity types.
   *
   * This mimics the data returned by EntityTypeManager::getDefinitions().
   *
   * @return \Drupal\Core\Entity\EntityTypeInterface[]
   *   A list of mocked entity types.
   *
   * @see \Drupal\Core\Entity\EntityTypeManagerInterface::getDefinitions()
   */
  protected function getEntityTypes(): array {
    return [
      'node' => $this->prophesize(ContentEntityInterface::class),
    ];
  }

  /**
   * Data provider for testResolve().
   *
   * @see ::testResolve()
   */
  public static function resolveProvider(): array {
    return [
      // Test that no groups are returned 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, the
      // correct group is returned.
      [
        // We're on the canonical group entity page.
        '/node/{node}',
        // The test group is found on the route.
        'group',
        // The plugin should be able to figure out this is a group.
        ['group'],
      ],
      // Test that if we are on the delete form of a group, the correct group is
      // returned.
      [
        '/node/{node}/delete',
        'group',
        ['group'],
      ],
      // Test that if we are on the canonical entity page of a group content
      // entity, no group should be returned.
      [
        '/entity_test/{entity_test}',
        'group_content',
        [],
      ],
      // Test that if we are on the delete form of a group content entity, no
      // group should be returned.
      [
        '/entity_test/delete/entity_test/{entity_test}',
        'group_content',
        [],
      ],
      // 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 returned.
      [
        '/taxonomy/term/{taxonomy_term}',
        '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.
      [
        '/taxonomy/term/{taxonomy_term}/delete',
        'non_group',
        [],
      ],
    ];
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc