RoleGrantedLockingTest.php in Commerce License 8.2
File
tests/src/Functional/RoleGrantedLockingTest.php
View source
<?php
namespace Drupal\Tests\commerce_license\Functional;
use Drupal\Tests\commerce\Functional\CommerceBrowserTestBase;
class RoleGrantedLockingTest extends CommerceBrowserTestBase {
protected $license;
public static $modules = [
'commerce_license',
];
protected function getAdministratorPermissions() {
return array_merge([
'administer users',
'administer permissions',
], parent::getAdministratorPermissions());
}
protected function setUp() : void {
parent::setUp();
$license_owner = $this
->createUser();
$role = $this
->createEntity('user_role', [
'id' => 'licensed_role',
'label' => 'Licensed role',
]);
$license = $this
->createEntity('commerce_license', [
'type' => 'role',
'state' => 'active',
'product_variation' => 1,
'uid' => $license_owner
->id(),
'expiration_type' => [
'target_plugin_id' => 'unlimited',
'target_plugin_configuration' => [],
],
'license_role' => $role,
]);
$this->license = $this
->reloadEntity($license);
}
public function testUserFormHasLock() {
$this
->drupalGet("user/" . $this->license
->getOwnerId() . "/edit");
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->fieldDisabled("roles[licensed_role]");
$this
->assertSession()
->pageTextContains("This role is granted by a license. It cannot be removed manually.");
$this
->submitForm([], 'Save');
$this
->assertTrue($this->license
->getOwner()
->hasRole('licensed_role'));
}
}