LinkOwnershipAccessTest.php in Flag 8.4
File
tests/src/Functional/LinkOwnershipAccessTest.php
View source
<?php
namespace Drupal\Tests\flag\Functional;
class LinkOwnershipAccessTest extends FlagTestBase {
protected $node;
protected function setUp() {
parent::setUp();
$this->entityTypeManager = $this->container
->get('entity_type.manager');
$this->node = $this
->drupalCreateNode([
'type' => $this->nodeType,
]);
}
public function testFlagOwnershipAccess() {
$this
->doFlagOwnershipAccessTest();
$this
->doGlobalFlagOwnershipAccessTest();
}
public function doFlagOwnershipAccessTest() {
$flag = $this
->createFlag();
$this
->grantFlagPermissions($flag);
$user_1 = $this
->drupalCreateUser();
$this
->drupalLogin($user_1);
$this
->drupalGet($this->node
->toUrl());
$this
->clickLink($flag
->getShortText('flag'));
$this
->assertResponse(200);
$this
->assertLink($flag
->getShortText('unflag'));
$user_2 = $this
->drupalCreateUser();
$this
->drupalLogin($user_2);
$this
->drupalGet($this->node
->toUrl());
$this
->assertLink($flag
->getShortText('flag'), 0, "A flag link is found on the page for user 2.");
}
public function doGlobalFlagOwnershipAccessTest() {
$flag = $this
->createGlobalFlag();
$this
->grantFlagPermissions($flag);
$user_1 = $this
->drupalCreateUser();
$this
->drupalLogin($user_1);
$this
->drupalGet($this->node
->toUrl());
$this
->clickLink($flag
->getShortText('flag'));
$this
->assertResponse(200);
$this
->assertLink($flag
->getShortText('unflag'));
$user_2 = $this
->drupalCreateUser();
$this
->drupalLogin($user_2);
$this
->drupalGet($this->node
->toUrl());
$this
->assertLink($flag
->getShortText('unflag'), 0, "The unflag link is found on the page for user 2.");
}
}