View source
<?php
namespace Drupal\Tests\forward\Functional;
class PermissionsTest extends ForwardTestBase {
public function testPermissions() {
$this
->drupalLogin($this->webUser);
$this
->drupalGet('admin/config/user-interface/forward');
$this
->assertResponse(403, 'Users with access content permission cannot change settings.');
$this
->drupalLogin($this->forwardUser);
$this
->drupalGet('admin/config/user-interface/forward');
$this
->assertResponse(403, 'Users with access forward permission cannot change settings.');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/config/user-interface/forward');
$this
->assertResponse(200, 'Users with administer forward permission can change settings.');
$article = $this
->drupalCreateNode([
'type' => 'article',
]);
$this
->drupalLogin($this->forwardUser);
$this
->drupalGet('/forward/node/' . $article
->id());
$this
->assertNoText('Your email address', 'Users without override email address permission cannot change their email address on the Forward form.');
$overrideUser = $this
->drupalCreateUser([
'access content',
'access forward',
'override email address',
'override flood control',
]);
$article = $this
->drupalCreateNode([
'type' => 'article',
]);
$this
->drupalLogin($overrideUser);
$this
->drupalGet('/forward/node/' . $article
->id());
$this
->assertText('Your email address', 'Users with override email address permission can change their email address on the Forward form.');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/config/user-interface/forward');
$edit = [
'forward_flood_control_limit' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Save configuration');
$this
->drupalLogin($this->forwardUser);
$this
->drupalGet('/forward/node/' . $article
->id());
$edit = [
'name' => 'Test Forwarder',
'recipient' => 'test@test.com',
'message' => 'This is a test personal message.',
];
$this
->drupalPostForm(NULL, $edit, 'Send Message');
$this
->drupalGet('/forward/node/' . $article
->id());
$edit = [
'name' => 'Test Forwarder',
'recipient' => 'test@test.com',
'message' => 'This is a test personal message.',
];
$this
->drupalPostForm(NULL, $edit, 'Send Message');
$this
->assertNoText('Thank you for spreading the word about Drupal.', 'Users without override flood control permission cannot do more than 1 forward in an hour.');
$this
->drupalLogin($overrideUser);
$this
->drupalGet('/forward/node/' . $article
->id());
$edit = [
'name' => 'Test Forwarder',
'recipient' => 'test@test.com',
'message' => 'This is a test personal message.',
];
$this
->drupalPostForm(NULL, $edit, 'Send Message');
$this
->drupalGet('/forward/node/' . $article
->id());
$edit = [
'name' => 'Test Forwarder',
'recipient' => 'test@test.com',
'message' => 'This is a test personal message.',
];
$this
->drupalPostForm(NULL, $edit, 'Send Message');
$this
->assertText('Thank you for spreading the word about Drupal.', 'Users with override flood control permission can do more than 1 forward in an hour.');
}
}