Commit 48d0da96 authored by Nikolay Lobachev's avatar Nikolay Lobachev
Browse files

Issue #3312174 by LOBsTerr: Group media 3.0: Update tests

parent e2f41861
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -96,8 +96,9 @@ function groupmedia_help($route_name, RouteMatchInterface $route_match) {
function groupmedia_entity_operation(EntityInterface $entity) {
  $operations = [];

  if ($entity->getEntityTypeId() == 'group' && \Drupal::moduleHandler()
    ->moduleExists('views')) {
  if ($entity->getEntityTypeId() == 'group' &&
    \Drupal::moduleHandler()->moduleExists('views')
  ) {
    /** @var \Drupal\group\Entity\GroupInterface $entity */
    if (!$entity->hasPermission('access group_media overview', \Drupal::currentUser())) {
      // Exit early without checking group relationship plugins.
@@ -121,8 +122,7 @@ function groupmedia_entity_operation(EntityInterface $entity) {
    if ($has_media) {
      /** @var \Symfony\Component\Routing\RouterInterface $router */
      $router = \Drupal::service('router.no_access_checks');
      if ($router->getRouteCollection()
        ->get('view.group_media.page_1') !== NULL) {
      if ($router->getRouteCollection()->get('view.group_media.page_1') !== NULL) {
        $operations['media'] = [
          'title' => t('Media'),
          'weight' => 22,
+82 −20
Original line number Diff line number Diff line
@@ -3,8 +3,10 @@
namespace Drupal\Tests\groupmedia\Functional;

use Drupal\group\Entity\GroupType;
use Drupal\group\PermissionScopeInterface;
use Drupal\Tests\group\Functional\EntityOperationsTest as GroupEntityOperationsTest;
use Drupal\Tests\media\Traits\MediaTypeCreationTrait;
use Drupal\user\RoleInterface;

/**
 * Tests that entity operations (do not) show up on the group overview.
@@ -20,7 +22,35 @@ class EntityOperationsTest extends GroupEntityOperationsTest {
  /**
   * {@inheritdoc}
   */
  public static $modules = ['groupmedia'];
  public static $modules = [
    'flexible_permissions',
    'group',
    'group_test_config',
    'groupmedia',
  ];

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();
    $group_type = GroupType::load('default');
    // Allow outsider request membership.
    $this->createGroupRole([
      'group_type' => $group_type->id(),
      'scope' => PermissionScopeInterface::OUTSIDER_ID,
      'global_role' => RoleInterface::AUTHENTICATED_ID,
      'permissions' => ['view published group'],
    ]);
    // Allow outsider request membership.
    $this->createGroupRole([
      'group_type' => $group_type->id(),
      'scope' => PermissionScopeInterface::INSIDER_ID,
      'global_role' => RoleInterface::AUTHENTICATED_ID,
      'permissions' => ['view published group'],
    ]);

  }

  /**
   * Checks for entity operations under given circumstances.
@@ -46,24 +76,47 @@ class EntityOperationsTest extends GroupEntityOperationsTest {
   * @dataProvider provideEntityOperationScenarios
   */
  public function testEntityOperations($visible, $invisible, $permissions = [], $modules = [], $has_media = FALSE) {
    if (!$has_media) {
      parent::testEntityOperations($visible, $invisible, $permissions, $modules);
      return;
    }

    // Create an media type and enable it as group content.
    $group_type = $this->createGroupType();
    if ($has_media) {
      // Create a media type and enable it as group content.
      $media_type = $this->createMediaType('image');
      $media_type->save();
    \Drupal::entityTypeManager()
      $this->entityTypeManager
        ->getStorage('group_content_type')
      ->createFromPlugin(GroupType::load('default'), 'group_media:' . $media_type->id(), [
        ->createFromPlugin( $group_type, 'group_media:' . $media_type->id(), [
          'group_cardinality' => 0,
          'entity_cardinality' => 1,
          'use_creation_wizard' => FALSE,
        ])
        ->save();
    }

    parent::testEntityOperations($visible, $invisible, $permissions, $modules);
    $group = $this->createGroup(['type' => $group_type->id()]);

    if (!empty($permissions)) {
      $this->createGroupRole([
        'group_type' => $group_type->id(),
        'scope' => PermissionScopeInterface::INSIDER_ID,
        'global_role' => RoleInterface::AUTHENTICATED_ID,
        'permissions' => $permissions,
      ]);
    }

    if (!empty($modules)) {
      $this->container->get('module_installer')->install($modules, TRUE);
    }

    $this->drupalGet('admin/group');

    foreach ($visible as $path => $label) {
      $this->assertSession()->linkExists($label);
      $this->assertSession()->linkByHrefExists($path);
    }

    foreach ($invisible as $path => $label) {
      $this->assertSession()->linkNotExists($label);
      $this->assertSession()->linkByHrefNotExists($path);
    }
  }

  /**
@@ -78,20 +131,29 @@ class EntityOperationsTest extends GroupEntityOperationsTest {
    $scenarios['withAccess'] = [
      [],
      ['group/1/media' => 'Media'],
      ['access group_media overview'],
      [
        'view group',
        'access group_media overview',
      ],
    ];

    $scenarios['withAccessAndViewsNoMedia'] = [
      [],
      ['group/1/media' => 'Media'],
      ['access group_media overview'],
      [
        'view group',
        'access group_media overview',
      ],
      ['views'],
    ];

    $scenarios['withAccessAndViewsAndMedia'] = [
      ['group/1/media' => 'Media'],
      [],
      ['access group_media overview'],
      [
        'view group',
        'access group_media overview',
      ],
      ['views'],
      TRUE,
    ];