View source
<?php
namespace Drupal\Tests\flag\Functional;
use Drupal\flag\Entity\Flag;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\BrowserTestBase;
class OutputLocationEntityFormAccessTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
public static $modules = [
'system',
'user',
'node',
'flag',
'flag_test_plugins',
];
protected $node;
protected $flag_granted;
protected $flag_denied;
protected function setUp() {
parent::setUp();
NodeType::create([
'type' => 'page',
'name' => 'page',
])
->save();
$this->node = Node::create([
'type' => 'page',
'title' => 'test',
]);
$this->node
->save();
$this->flag_granted = Flag::create([
'id' => 'flag_granted',
'label' => 'Flag allowed',
'entity_type' => 'node',
'bundles' => [
'page',
],
'flag_type' => 'test_access_granted',
'link_type' => 'reload',
'flagTypeConfig' => [
'show_on_form' => TRUE,
],
'linkTypeConfig' => [],
'flag_short' => 'Flag this',
'unflag_short' => 'Unflag this',
]);
$this->flag_granted
->save();
$this->flag_denied = Flag::create([
'id' => 'flag_denied',
'label' => 'Flag denied',
'entity_type' => 'node',
'bundles' => [
'page',
],
'flag_type' => 'test_access_denied',
'link_type' => 'reload',
'flagTypeConfig' => [
'show_on_form' => TRUE,
],
'linkTypeConfig' => [],
'flag_short' => 'Flag this',
'unflag_short' => 'Unflag this',
]);
$this->flag_denied
->save();
$auth_user = $this
->drupalCreateUser([
'access content',
'edit any page content',
]);
$this
->drupalLogin($auth_user);
}
public function testCheckboxAccess() {
$this
->drupalGet("node/" . $this->node
->id() . "/edit");
$this
->assertSession()
->pageTextContains('Flag allowed', 'The checkbox for the flag with access is shown.');
$this
->assertSession()
->pageTextNotContains('Flag denied', 'The checkbox for the flag without access is not shown.');
}
}