og-8.x-1.x-dev/og_ui/tests/src/Functional/OgPermissionsFormTest.php

og_ui/tests/src/Functional/OgPermissionsFormTest.php
<?php

declare(strict_types=1);

namespace Drupal\Tests\og_ui\Functional;

use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\og\Traits\OgMembershipCreationTrait;
use Drupal\node\Entity\NodeType;
use Drupal\og\Entity\OgRole;
use Drupal\og\Og;
use Drupal\og\OgRoleInterface;
use Drupal\user\UserInterface;

/**
 * Tests the OG permissions form.
 *
 * @group og_ui
 * @coversDefaultClass \Drupal\og_ui\Form\OgPermissionsForm
 */
class OgPermissionsFormTest extends BrowserTestBase {

  use OgMembershipCreationTrait;

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'field',
    'node',
    'og',
    'og_ui',
    'system',
    'user',
  ];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * The group bundle.
   */
  protected string $groupBundle;

  /**
   * A user with permission to administer group.
   */
  protected UserInterface $adminUser;

  /**
   * The anonymous OG role.
   */
  protected OgRoleInterface $anonymousRole;

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();

    // Create bundle.
    $this->groupBundle = mb_strtolower($this->randomMachineName());

    // Create a node type.
    $node_type = NodeType::create([
      'type' => $this->groupBundle,
      'name' => $this->groupBundle,
    ]);
    $node_type->save();

    // Add og_group field to the node type.
    Og::groupTypeManager()->addGroup('node', $this->groupBundle);

    // Create a user with permission to administer group permissions.
    $this->adminUser = $this->drupalCreateUser([
      'administer organic groups',
      'access content',
    ]);

    // Load the roles.
    $roles = OgRole::loadByGroupType('node', $this->groupBundle);
    foreach ($roles as $role) {
      if ($role->getName() === OgRoleInterface::ANONYMOUS) {
        $this->anonymousRole = $role;
        break;
      }
    }
  }

  /**
   * Tests that default role permission checkboxes are editable.
   */
  public function testDefaultRolePermissionsAreEditable(): void {
    $this->drupalLogin($this->adminUser);

    // Navigate to the OG permissions administration page.
    $this->drupalGet('admin/config/group/permissions/node/' . $this->groupBundle);
    $this->assertSession()->statusCodeEquals(200);

    // Check for the subscribe permission checkbox for the anonymous role.
    $anonymous_checkbox_name = $this->anonymousRole->id() . '[subscribe]';
    $field = $this->assertSession()->fieldExists($anonymous_checkbox_name);

    // Verify the checkbox is NOT disabled for the anonymous/non-member role.
    $this->assertFalse(
      $field->hasAttribute('disabled'),
      'Subscribe permission checkbox for anonymous/non-member role should be editable.'
    );
  }

}

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

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