You are here

public function FieldReportTest::testReportPage in Field Permissions 8

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/FieldReportTest.php \Drupal\Tests\field_permissions\Functional\FieldReportTest::testReportPage()

Test the report page.

File

tests/src/Functional/FieldReportTest.php, line 73

Class

FieldReportTest
Test the field permissions report page.

Namespace

Drupal\Tests\field_permissions\Functional

Code

public function testReportPage() {
  $this
    ->drupalGet(Url::fromRoute('field_permissions.reports'));
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Initially, no fields should be private or custom.
  $this
    ->assertSession()
    ->pageTextContains('Not set (Field inherits content permissions.)');
  $this
    ->assertSession()
    ->pageTextNotContains('Private (Only author and administrators can edit and view.)');
  $this
    ->assertSession()
    ->pageTextNotContains('Not all users have this permission');
  $this
    ->assertSession()
    ->pageTextNotContains('All users have this permission');

  // Set to private.
  $this->fieldStorage
    ->setThirdPartySetting('field_permissions', 'permission_type', FieldPermissionTypeInterface::ACCESS_PRIVATE);
  $this->fieldStorage
    ->save();
  $this
    ->drupalGet(Url::fromRoute('field_permissions.reports'));
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('Private (Only author and administrators can edit and view.)');

  // Set custom, and grant no permissions initially.
  $this->fieldStorage
    ->setThirdPartySetting('field_permissions', 'permission_type', FieldPermissionTypeInterface::ACCESS_CUSTOM);
  $this->fieldStorage
    ->save();
  $this
    ->drupalGet(Url::fromRoute('field_permissions.reports'));
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('Not all users have this permission');

  // Grant anonymous and authenticated view permission.
  foreach ([
    RoleInterface::ANONYMOUS_ID,
    RoleInterface::AUTHENTICATED_ID,
  ] as $role_id) {

    /** @var \Drupal\user\RoleInterface $role */
    $role = $this->container
      ->get('entity_type.manager')
      ->getStorage('user_role')
      ->load($role_id);
    $role
      ->grantPermission('view_field_test')
      ->save();
  }
  $this
    ->drupalGet(Url::fromRoute('field_permissions.reports'));
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('All users have this permission');
}