ChecklistapiTest.php in Checklist API 8
File
tests/src/Functional/ChecklistapiTest.php
View source
<?php
namespace Drupal\Tests\checklistapi\Functional;
use Drupal\Tests\BrowserTestBase;
class ChecklistapiTest extends BrowserTestBase {
protected static $modules = [
'checklistapi',
'checklistapiexample',
'help',
'block',
];
protected $defaultTheme = 'stark';
protected $privilegedUser;
public function setUp() {
parent::setUp();
$permissions = [
'edit any checklistapi checklist',
];
$this->privilegedUser = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($this->privilegedUser);
$this
->drupalPlaceBlock('help_block', [
'region' => 'help',
]);
}
public function testChecklistAccess() {
$this
->drupalGet('admin/config/development/checklistapi-example');
$this
->assertResponse(200);
$permissions = [
'edit example_checklist checklistapi checklist',
];
$semi_privileged_user = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($semi_privileged_user);
$this
->drupalGet('admin/config/development/checklistapi-example');
$this
->assertResponse(200);
$this
->drupalLogout();
$this
->drupalGet('admin/config/development/checklistapi-example');
$this
->assertResponse(403);
}
public function testChecklistComposition() {
$this
->drupalGet('admin/config/development/checklistapi-example');
$this
->assertRaw('This checklist based on');
}
public function testPermissions() {
self::assertTrue($this
->checkPermissions([
'view checklistapi checklists report',
'view any checklistapi checklist',
'edit any checklistapi checklist',
]), 'Created universal permissions.');
self::assertTrue($this
->checkPermissions([
'view example_checklist checklistapi checklist',
'edit example_checklist checklistapi checklist',
]), 'Created per-checklist permissions.');
}
}