View source
<?php
namespace Drupal\forward\Tests;
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(t('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(t('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, t('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, t('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, t('Send Message'));
$this
->assertNoText(t('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, t('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, t('Send Message'));
$this
->assertText(t('Thank you for spreading the word about Drupal.'), 'Users with override flood control permission can do more than 1 forward in an hour.');
}
}