FieldReportTest.php in Field Permissions 8.2
File
tests/src/Functional/FieldReportTest.php
View source
<?php
namespace Drupal\Tests\field_permissions\Functional;
use Drupal\Core\Url;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field_permissions\Plugin\FieldPermissionTypeInterface;
use Drupal\Tests\BrowserTestBase;
use Drupal\user\RoleInterface;
class FieldReportTest extends BrowserTestBase {
public static $modules = [
'field_permissions',
'entity_test',
'field_ui',
'text',
];
protected $defaultTheme = 'stark';
protected $fieldStorage;
public function setUp() {
parent::setUp();
$admin = $this
->drupalCreateUser([
'administer field permissions',
'access site reports',
]);
$this
->drupalLogin($admin);
$this->fieldStorage = FieldStorageConfig::create([
'field_name' => 'field_test',
'type' => 'integer',
'entity_type' => 'entity_test',
]);
$this->fieldStorage
->save();
$field = FieldConfig::create([
'field_name' => 'field_test',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
]);
$field
->save();
}
public function testReportPage() {
$this
->drupalGet(Url::fromRoute('field_permissions.reports'));
$this
->assertSession()
->statusCodeEquals(200);
$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');
$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.)');
$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');
foreach ([
RoleInterface::ANONYMOUS_ID,
RoleInterface::AUTHENTICATED_ID,
] as $role_id) {
$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');
}
}