function PollCreateTest::testwithRestrictedUser in Poll 8
Poll create with restricted user.
File
- tests/
src/ Functional/ PollCreateTest.php, line 110
Class
- PollCreateTest
- Tests creating a poll.
Namespace
Drupal\Tests\poll\FunctionalCode
function testwithRestrictedUser() {
$admin_poll = $this->poll;
// Create and login restricted user.
$account = $this
->drupalCreateUser([
'create polls',
]);
$this
->drupalLogin($account);
// Create poll allowed.
$this
->drupalGet('poll/add');
$this
->assertResponse(200);
$this
->assertNoFieldByName('uid[0][target_id]', NULL);
// create poll and test edit
$own_poll = $this
->pollCreate(7, $account);
$this
->drupalGet('poll/' . $admin_poll
->id() . '/edit');
$this
->assertResponse(403);
$this
->drupalGet('poll/' . $own_poll
->id() . '/edit');
$this
->assertResponse(403);
// test another user with "edit own poll" permission
$account = $this
->drupalCreateUser([
'create polls',
'edit own polls',
]);
$this
->drupalLogin($account);
$own_poll = $this
->pollCreate(7, $account);
$this
->drupalGet('poll/' . $admin_poll
->id() . '/edit');
$this
->assertResponse(403);
$this
->drupalGet('poll/' . $own_poll
->id() . '/edit');
$this
->assertResponse(200);
$this
->assertNoFieldByName('uid[0][target_id]', NULL);
}