Commit 59388d8c authored by alexpott's avatar alexpott

Issue #2433281 by neclimdul, mrjmd: Move Role Constants on to a Class/Interface

parent c5338e00
......@@ -13,6 +13,7 @@
use Drupal\Core\DrupalKernel;
use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\Core\Logger\RfcLogLevel;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Site\Settings;
use Drupal\Core\Utility\Error;
use Symfony\Component\ClassLoader\ApcClassLoader;
......@@ -55,13 +56,21 @@
/**
* Role ID for anonymous users; should match what's in the "role" table.
*
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
* Use Drupal\Core\Session\AccountInterface::ANONYMOUS_ROLE or
* \Drupal\user\RoleInterface::ANONYMOUS_ID instead.
*/
const DRUPAL_ANONYMOUS_RID = 'anonymous';
const DRUPAL_ANONYMOUS_RID = AccountInterface::ANONYMOUS_ROLE;
/**
* Role ID for authenticated users; should match what's in the "role" table.
*
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
* Use Drupal\Core\Session\AccountInterface::AUTHENTICATED_ROLE or
* \Drupal\user\RoleInterface::AUTHENTICATED_ID instead.
*/
const DRUPAL_AUTHENTICATED_RID = 'authenticated';
const DRUPAL_AUTHENTICATED_RID = AccountInterface::AUTHENTICATED_ROLE;
/**
* The maximum number of characters in a module or theme name.
......
......@@ -17,6 +17,16 @@
*/
interface AccountInterface {
/**
* Role ID for anonymous users.
*/
const ANONYMOUS_ROLE = 'anonymous';
/**
* Role ID for authenticated users.
*/
const AUTHENTICATED_ROLE = 'authenticated';
/**
* Returns the user ID or 0 for anonymous.
*
......
......@@ -86,7 +86,7 @@ public function read($sid) {
$rids = $this->connection->query("SELECT ur.roles_target_id as rid FROM {user__roles} ur WHERE ur.entity_id = :uid", array(
':uid' => $values['uid'],
))->fetchCol();
$values['roles'] = array_merge(array(DRUPAL_AUTHENTICATED_RID), $rids);
$values['roles'] = array_merge(array(AccountInterface::AUTHENTICATED_ROLE), $rids);
$_session_user = new UserSession($values);
}
elseif ($values) {
......
......@@ -28,7 +28,7 @@ class UserSession implements AccountInterface {
*
* @var array
*/
protected $roles = array('anonymous');
protected $roles = array(AccountInterface::ANONYMOUS_ROLE);
/**
* Session ID.
......@@ -126,7 +126,7 @@ public function getRoles($exclude_locked_roles = FALSE) {
$roles = $this->roles;
if ($exclude_locked_roles) {
$roles = array_values(array_diff($roles, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID)));
$roles = array_values(array_diff($roles, array(AccountInterface::ANONYMOUS_ROLE, AccountInterface::AUTHENTICATED_ROLE)));
}
return $roles;
......
......@@ -10,6 +10,7 @@
use Drupal\aggregator\Entity\Feed;
use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
/**
* Tests the Feed entity's cache tags.
......@@ -31,7 +32,7 @@ protected function setUp() {
// Give anonymous users permission to access feeds, so that we can verify
// the cache tags of cached versions of feeds.
$user_role = Role::load(DRUPAL_ANONYMOUS_RID);
$user_role = Role::load(RoleInterface::ANONYMOUS_ID);
$user_role->grantPermission('access news feeds');
$user_role->save();
}
......
......@@ -11,6 +11,7 @@
use Drupal\aggregator\Entity\Item;
use Drupal\system\Tests\Entity\EntityCacheTagsTestBase;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
/**
* Tests the Item entity's cache tags.
......@@ -32,7 +33,7 @@ protected function setUp() {
// Give anonymous users permission to access feeds, so that we can verify
// the cache tags of cached versions of feed items.
$user_role = Role::load(DRUPAL_ANONYMOUS_RID);
$user_role = Role::load(RoleInterface::ANONYMOUS_ID);
$user_role->grantPermission('access news feeds');
$user_role->save();
}
......
......@@ -12,6 +12,7 @@
use Drupal\simpletest\WebTestBase;
use Drupal\Component\Utility\String;
use Drupal\block\Entity\Block;
use Drupal\user\RoleInterface;
/**
* Tests basic block functionality.
......@@ -38,7 +39,7 @@ function testBlockVisibility() {
// authenticated users.
$edit['visibility[request_path][pages]'] = 'user*';
$edit['visibility[request_path][negate]'] = TRUE;
$edit['visibility[user_role][roles][' . DRUPAL_AUTHENTICATED_RID . ']'] = TRUE;
$edit['visibility[user_role][roles][' . RoleInterface::AUTHENTICATED_ID . ']'] = TRUE;
$this->drupalPostForm('admin/structure/block/add/' . $block_name . '/' . $default_theme, $edit, t('Save block'));
$this->assertText('The block configuration has been saved.', 'Block was saved');
......@@ -74,13 +75,13 @@ public function testBlockToggleVisibility() {
);
$block_id = $edit['id'];
// Set the block to be shown only to authenticated users.
$edit['visibility[user_role][roles][' . DRUPAL_AUTHENTICATED_RID . ']'] = TRUE;
$edit['visibility[user_role][roles][' . RoleInterface::AUTHENTICATED_ID . ']'] = TRUE;
$this->drupalPostForm('admin/structure/block/add/' . $block_name . '/' . $default_theme, $edit, t('Save block'));
$this->clickLink('Configure');
$this->assertFieldChecked('edit-visibility-user-role-roles-authenticated');
$edit = [
'visibility[user_role][roles][' . DRUPAL_AUTHENTICATED_RID . ']' => FALSE,
'visibility[user_role][roles][' . RoleInterface::AUTHENTICATED_ID . ']' => FALSE,
];
$this->drupalPostForm(NULL, $edit, 'Save block');
$this->clickLink('Configure');
......
......@@ -10,6 +10,7 @@
use Drupal\Component\Utility\String;
use Drupal\Core\Entity\EntityInterface;
use Drupal\simpletest\WebTestBase;
use Drupal\user\RoleInterface;
/**
* Create a book, add pages, and test book interface.
......@@ -367,7 +368,7 @@ function testBookExport() {
// Now grant anonymous users permission to view the printer-friendly
// version and verify that node access restrictions still prevent them from
// seeing it.
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access printer-friendly version'));
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access printer-friendly version'));
$this->drupalGet('book/export/html/' . $this->book->id());
$this->assertResponse('403', 'Anonymous user properly forbidden from seeing the printer-friendly version when denied by node access.');
}
......@@ -383,8 +384,8 @@ function testBookNavigationBlock() {
// Give anonymous users the permission 'node test view'.
$edit = array();
$edit[DRUPAL_ANONYMOUS_RID . '[node test view]'] = TRUE;
$this->drupalPostForm('admin/people/permissions/' . DRUPAL_ANONYMOUS_RID, $edit, t('Save permissions'));
$edit[RoleInterface::ANONYMOUS_ID . '[node test view]'] = TRUE;
$this->drupalPostForm('admin/people/permissions/' . RoleInterface::ANONYMOUS_ID, $edit, t('Save permissions'));
$this->assertText(t('The changes have been saved.'), "Permission 'node test view' successfully assigned to anonymous users.");
// Test correct display of the block.
......@@ -404,8 +405,8 @@ function testNavigationBlockOnAccessModuleInstalled() {
// Give anonymous users the permission 'node test view'.
$edit = array();
$edit[DRUPAL_ANONYMOUS_RID . '[node test view]'] = TRUE;
$this->drupalPostForm('admin/people/permissions/' . DRUPAL_ANONYMOUS_RID, $edit, t('Save permissions'));
$edit[RoleInterface::ANONYMOUS_ID . '[node test view]'] = TRUE;
$this->drupalPostForm('admin/people/permissions/' . RoleInterface::ANONYMOUS_ID, $edit, t('Save permissions'));
$this->assertText(t('The changes have been saved.'), "Permission 'node test view' successfully assigned to anonymous users.");
// Create a book.
......
......@@ -31,6 +31,7 @@
use Drupal\file\FileInterface;
use Drupal\user\EntityOwnerInterface;
use Drupal\node\NodeInterface;
use Drupal\user\RoleInterface;
/**
* Anonymous posters cannot enter their contact information.
......@@ -439,10 +440,10 @@ function comment_node_update_index(EntityInterface $node, $langcode) {
// comments.
$index_comments = TRUE;
$roles = \Drupal::entityManager()->getStorage('user_role')->loadMultiple();
$authenticated_can_access = $roles[DRUPAL_AUTHENTICATED_RID]->hasPermission('access comments');
$authenticated_can_access = $roles[RoleInterface::AUTHENTICATED_ID]->hasPermission('access comments');
foreach ($roles as $rid => $role) {
if ($role->hasPermission('search content') && !$role->hasPermission('access comments')) {
if ($rid == DRUPAL_AUTHENTICATED_RID || $rid == DRUPAL_ANONYMOUS_RID || !$authenticated_can_access) {
if ($rid == RoleInterface::AUTHENTICATED_ID || $rid == RoleInterface::ANONYMOUS_ID || !$authenticated_can_access) {
$index_comments = FALSE;
break;
}
......
......@@ -22,6 +22,7 @@
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
use Drupal\user\RoleInterface;
/**
* Comment manager contains common functions to manage comment fields.
......@@ -45,7 +46,7 @@ class CommentManager implements CommentManagerInterface {
protected $queryFactory;
/**
* Whether the DRUPAL_AUTHENTICATED_RID can post comments.
* Whether the \Drupal\user\RoleInterface::AUTHENTICATED_ID can post comments.
*
* @var bool
*/
......@@ -154,7 +155,7 @@ public function forbiddenMessage(EntityInterface $entity, $field_name) {
// permission to post comments by logging in.
$this->authenticatedCanPostComments = $this->entityManager
->getStorage('user_role')
->load(DRUPAL_AUTHENTICATED_RID)
->load(RoleInterface::AUTHENTICATED_ID)
->hasPermission('post comments');
}
......
......@@ -7,6 +7,8 @@
namespace Drupal\comment\Tests;
use Drupal\user\RoleInterface;
/**
* Tests comment approval functionality.
*
......@@ -18,7 +20,7 @@ class CommentAdminTest extends CommentTestBase {
*/
function testApprovalAdminInterface() {
// Set anonymous comments to require approval.
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
user_role_change_permissions(RoleInterface::ANONYMOUS_ID, array(
'access comments' => TRUE,
'post comments' => TRUE,
'skip comment approval' => FALSE,
......@@ -100,7 +102,7 @@ function testApprovalAdminInterface() {
*/
function testApprovalNodeInterface() {
// Set anonymous comments to require approval.
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
user_role_change_permissions(RoleInterface::ANONYMOUS_ID, array(
'access comments' => TRUE,
'post comments' => TRUE,
'skip comment approval' => FALSE,
......@@ -173,7 +175,7 @@ public function testCommentAdmin() {
*/
public function testEditComment() {
// Enable anonymous user comments.
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array(
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array(
'access comments',
'post comments',
'skip comment approval',
......
......@@ -7,6 +7,8 @@
namespace Drupal\comment\Tests;
use Drupal\user\RoleInterface;
/**
* Tests anonymous commenting.
*
......@@ -18,12 +20,12 @@ protected function setUp() {
parent::setUp();
// Enable anonymous and authenticated user comments.
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array(
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array(
'access comments',
'post comments',
'skip comment approval',
));
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array(
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, array(
'access comments',
'post comments',
'skip comment approval',
......@@ -120,7 +122,7 @@ function testAnonymous() {
$this->drupalLogout();
// Reset.
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
user_role_change_permissions(RoleInterface::ANONYMOUS_ID, array(
'access comments' => FALSE,
'post comments' => FALSE,
'skip comment approval' => FALSE,
......@@ -139,7 +141,7 @@ function testAnonymous() {
$this->assertNoFieldByName('subject[0][value]', '', 'Subject field not found.');
$this->assertNoFieldByName('comment_body[0][value]', '', 'Comment field not found.');
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
user_role_change_permissions(RoleInterface::ANONYMOUS_ID, array(
'access comments' => TRUE,
'post comments' => FALSE,
'skip comment approval' => FALSE,
......@@ -149,7 +151,7 @@ function testAnonymous() {
$this->assertLink('Log in', 1, 'Link to log in was found.');
$this->assertLink('register', 1, 'Link to register was found.');
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
user_role_change_permissions(RoleInterface::ANONYMOUS_ID, array(
'access comments' => FALSE,
'post comments' => TRUE,
'skip comment approval' => TRUE,
......
......@@ -7,6 +7,7 @@
namespace Drupal\comment\Tests;
use Drupal\Component\Utility\String;
use Drupal\user\RoleInterface;
/**
* Tests comment block functionality.
......@@ -57,10 +58,10 @@ function testRecentCommentBlock() {
// Test that a user without the 'access comments' permission cannot see the
// block.
$this->drupalLogout();
user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, array('access comments'));
user_role_revoke_permissions(RoleInterface::ANONYMOUS_ID, array('access comments'));
$this->drupalGet('');
$this->assertNoText(t('Recent comments'));
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access comments'));
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access comments'));
// Test that a user with the 'access comments' permission can see the
// block.
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Language\LanguageInterface;
use Drupal\comment\CommentInterface;
use Drupal\user\RoleInterface;
/**
* Tests CSS classes on comments.
......@@ -21,7 +22,7 @@ protected function setUp() {
parent::setUp();
// Allow anonymous users to see comments.
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array(
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array(
'access comments',
'access content'
));
......
......@@ -12,6 +12,7 @@
use Drupal\field\Entity\FieldConfig;
use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
/**
* Tests the Comment entity's cache tags.
......@@ -35,7 +36,7 @@ protected function setUp() {
// Give anonymous users permission to view comments, so that we can verify
// the cache tags of cached versions of comment pages.
$user_role = Role::load(DRUPAL_ANONYMOUS_RID);
$user_role = Role::load(RoleInterface::ANONYMOUS_ID);
$user_role->grantPermission('access comments');
$user_role->save();
}
......
......@@ -15,6 +15,7 @@
use Drupal\simpletest\TestBase;
use Drupal\system\Tests\Entity\EntityUnitTestBase;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
/**
* Tests comment field level access.
......@@ -122,7 +123,7 @@ public function testAccessToAdministrativeFields() {
// An unprivileged user.
$comment_disabled_user = $this->createUser(['name' => 'disabled'], ['access content']);
$role = Role::load(DRUPAL_ANONYMOUS_RID);
$role = Role::load(RoleInterface::ANONYMOUS_ID);
$role->grantPermission('post comments')
->save();
......
......@@ -10,6 +10,7 @@
use Drupal\comment\CommentManagerInterface;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\comment\Entity\Comment;
use Drupal\user\RoleInterface;
/**
* Tests comment user interfaces.
......@@ -52,7 +53,7 @@ function testCommentInterface() {
// Comment as anonymous with preview required.
$this->drupalLogout();
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access content', 'access comments', 'post comments', 'skip comment approval'));
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access content', 'access comments', 'post comments', 'skip comment approval'));
$anonymous_comment = $this->postComment($this->node, $this->randomMachineName(), $this->randomMachineName(), TRUE);
$this->assertTrue($this->commentExists($anonymous_comment), 'Comment found.');
$anonymous_comment->delete();
......
......@@ -10,6 +10,7 @@
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\comment\CommentInterface;
use Drupal\user\RoleInterface;
/**
* Basic comment links tests to ensure markup present.
......@@ -87,7 +88,7 @@ public function testCommentLinks() {
'skip comment approval' => 1,
'edit own comments' => 1,
);
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, $perms);
user_role_change_permissions(RoleInterface::ANONYMOUS_ID, $perms);
$nid = $this->node->id();
......
......@@ -15,6 +15,7 @@
use Drupal\field_ui\Tests\FieldUiTestTrait;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Entity\EntityInterface;
use Drupal\user\RoleInterface;
/**
* Tests commenting on a test entity.
......@@ -75,12 +76,12 @@ protected function setUp() {
));
// Enable anonymous and authenticated user comments.
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array(
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array(
'access comments',
'post comments',
'skip comment approval',
));
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array(
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, array(
'access comments',
'post comments',
'skip comment approval',
......@@ -328,7 +329,7 @@ function testCommentFunctionality() {
$this->drupalLogout();
// Deny anonymous users access to comments.
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
user_role_change_permissions(RoleInterface::ANONYMOUS_ID, array(
'access comments' => FALSE,
'post comments' => FALSE,
'skip comment approval' => FALSE,
......@@ -346,7 +347,7 @@ function testCommentFunctionality() {
$this->assertNoFieldByName('subject[0][value]', '', 'Subject field not found.');
$this->assertNoFieldByName('comment_body[0][value]', '', 'Comment field not found.');
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
user_role_change_permissions(RoleInterface::ANONYMOUS_ID, array(
'access comments' => TRUE,
'post comments' => FALSE,
'view test entity' => TRUE,
......@@ -362,7 +363,7 @@ function testCommentFunctionality() {
// Test the combination of anonymous users being able to post, but not view
// comments, to ensure that access to post comments doesn't grant access to
// view them.
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
user_role_change_permissions(RoleInterface::ANONYMOUS_ID, array(
'access comments' => FALSE,
'post comments' => TRUE,
'skip comment approval' => TRUE,
......
......@@ -9,6 +9,7 @@
use Drupal\comment\CommentManagerInterface;
use Drupal\comment\Entity\Comment;
use Drupal\user\RoleInterface;
/**
* Tests comment statistics on nodes.
......@@ -74,7 +75,7 @@ function testCommentNodeCommentStatistics() {
// Prepare for anonymous comment submission (comment approval enabled).
$this->drupalLogin($this->adminUser);
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
user_role_change_permissions(RoleInterface::ANONYMOUS_ID, array(
'access comments' => TRUE,
'post comments' => TRUE,
'skip comment approval' => FALSE,
......@@ -98,7 +99,7 @@ function testCommentNodeCommentStatistics() {
// Prepare for anonymous comment submission (no approval required).
$this->drupalLogin($this->adminUser);
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
user_role_change_permissions(RoleInterface::ANONYMOUS_ID, array(
'access comments' => TRUE,
'post comments' => TRUE,
'skip comment approval' => TRUE,
......
......@@ -10,6 +10,7 @@
use Drupal\Component\Utility\String;
use Drupal\Core\Session\AccountInterface;
use Drupal\simpletest\WebTestBase;
use Drupal\user\RoleInterface;
/**
* Tests personal contact form functionality.
......@@ -144,7 +145,7 @@ function testPersonalContactAccess() {
// Test that anonymous users can access the contact form.
$this->drupalLogout();
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access user contact forms'));
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access user contact forms'));
$this->drupalGet('user/' . $this->contactUser->id() . '/contact');
$this->assertResponse(200);
......@@ -153,7 +154,7 @@ function testPersonalContactAccess() {
$this->assertResponse(200);
// Revoke the personal contact permission for the anonymous user.
user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, array('access user contact forms'));
user_role_revoke_permissions(RoleInterface::ANONYMOUS_ID, array('access user contact forms'));
$this->drupalGet('user/' . $this->contactUser->id() . '/contact');
$this->assertResponse(403);
$this->drupalGet('user/' . $this->adminUser->id() . '/contact');
......@@ -247,7 +248,7 @@ function testPersonalContactFlood() {
* Tests the personal contact form based access when an admin adds users.
*/
function testAdminContact() {
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access user contact forms'));
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access user contact forms'));
$this->checkContactAccess(200);
$this->checkContactAccess(403, FALSE);
$config = $this->config('contact.settings');
......
......@@ -13,6 +13,7 @@
use Drupal\field_ui\Tests\FieldUiTestTrait;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\user\RoleInterface;
/**
* Tests site-wide contact form functionality.
......@@ -95,7 +96,7 @@ function testSiteWideContact() {
$this->assertNoLinkByHref('admin/structure/contact/manage/feedback');
// Ensure that the contact form won't be shown without forms.
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form'));
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access site-wide contact form'));
$this->drupalLogout();
$this->drupalGet('contact');
$this->assertResponse(404);
......@@ -159,7 +160,7 @@ function testSiteWideContact() {
$this->config('contact.settings')->set('default_form', $id)->save();
// Ensure that the contact form is shown without a form selection input.
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form'));
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access site-wide contact form'));
$this->drupalLogout();
$this->drupalGet('contact');
$this->assertText(t('Your email address'));
......@@ -185,12 +186,12 @@ function testSiteWideContact() {
$this->drupalLogout();
// Check to see that anonymous user cannot see contact page without permission.
user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form'));
user_role_revoke_permissions(RoleInterface::ANONYMOUS_ID, array('access site-wide contact form'));
$this->drupalGet('contact');
$this->assertResponse(403);
// Give anonymous user permission and see that page is viewable.
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form'));
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access site-wide contact form'));
$this->drupalGet('contact');
$this->assertResponse(200);
......@@ -305,7 +306,7 @@ function testAutoReply() {
// Log the current user out in order to test the name and email fields.
$this->drupalLogout();
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form'));
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access site-wide contact form'));
// Test the auto-reply for form 'foo'.
$email = $this->randomMachineName(32) . '@example.com';
......
......@@ -9,6 +9,7 @@
use Drupal\Component\Utility\Unicode;
use Drupal\contact\Entity\Message;
use Drupal\user\RoleInterface;
/**
* Tests storing contact messages.
......@@ -56,7 +57,7 @@ public function testContactStorage() {
$this->assertRaw(t('Contact form %label has been added.', array('%label' => $label)));
// Ensure that anonymous can submit site-wide contact form.
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form'));
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access site-wide contact form'));
$this->drupalLogout();
$this->drupalGet('contact');
$this->assertText(t('Your email address'));
......
......@@ -13,6 +13,7 @@
use Drupal\filter\Entity\FilterFormat;
use Drupal\system\Tests\Entity\EntityUnitTestBase;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
/**
* Tests the formatters functionality.
......@@ -69,7 +70,7 @@ protected function setUp() {
// Grant the 'view test entity' permission.
$this->installConfig(array('user'));
Role::load(DRUPAL_ANONYMOUS_RID)
Role::load(RoleInterface::ANONYMOUS_ID)
->grantPermission('view test entity')
->save();
......@@ -126,7 +127,7 @@ protected function setUp() {
*/
public function testAccess() {
// Revoke the 'view test entity' permission for this test.
Role::load(DRUPAL_ANONYMOUS_RID)
Role::load(RoleInterface::ANONYMOUS_ID)
->revokePermission('view test entity')
->save();
......
......@@ -12,6 +12,7 @@
use Drupal\Component\Utility\Html;
use Drupal\field\Entity\FieldConfig;
use Drupal\field_ui\Tests\FieldUiTestTrait;
use Drupal\user\RoleInterface;
/**
* Tests the file field widget, single and multi-valued, with and without AJAX,
......@@ -266,8 +267,8 @@ function testPrivateFileComment() {
// Revoke access comments permission from anon user, grant post to
// authenticated.
user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, array('access comments'));
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('post comments', 'skip comment approval'));
user_role_revoke_permissions(RoleInterface::ANONYMOUS_ID, array('access comments'));
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, array('post comments', 'skip comment approval'));
// Create a new field.
$this->addDefaultCommentField('node', 'article');
......
......@@ -10,6 +10,7 @@
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Unicode;
use Drupal\simpletest\WebTestBase;
use Drupal\user\RoleInterface;
/**
* Thoroughly test the administrative interface of the filter module.
......@@ -248,7 +249,7 @@ function testFilterAdmin() {
$edit = array();
$edit['format'] = Unicode::strtolower($this->randomMachineName());
$edit['name'] = $this->randomMachineName();
$edit['roles[' . DRUPAL_AUTHENTICATED_RID . ']'] = 1;
$edit['roles[' . RoleInterface::AUTHENTICATED_ID . ']'] = 1;
$edit['filters[' . $second_filter . '][status]'] = TRUE;
$edit['filters[' . $first_filter . '][status]'] = TRUE;
$this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
......@@ -259,7 +260,7 @@ function testFilterAdmin() {
$format = entity_load('filter_format', $edit['format']);
$this->assertNotNull($format, 'Format found in database.');
$this->drupalGet('admin/config/content/formats/manage/' . $format->id());
$this->assertFieldByName('roles[' . DRUPAL_AUTHENTICATED_RID . ']', '', 'Role found.');
$this->assertFieldByName('roles[' . RoleInterface::AUTHENTICATED_ID . ']', '', 'Role found.');
$this->assertFieldByName('filters[' . $second_filter . '][status]', '', 'Line break filter found.');
$this->assertFieldByName('filters[' . $first_filter . '][status]', '', 'Url filter found.');
......@@ -271,8 +272,8 @@ function testFilterAdmin() {
// Allow authenticated users on full HTML.
$format = entity_load('filter_format', $full);
$edit = array();
$edit['roles[' . DRUPAL_ANONYMOUS_RID . ']'] = 0;
$edit['roles[' . DRUPAL_AUTHENTICATED_RID . ']'] = 1;
$edit['roles[' . RoleInterface::ANONYMOUS_ID . ']'] = 0;
$edit['roles[' . RoleInterface::AUTHENTICATED_ID . ']'] = 1;
$this->drupalPostForm('admin/config/content/formats/manage/' . $full, $edit, t('Save configuration'));
$this->assertUrl('admin/config/content/formats');
$this->assertRaw(t('The text format %format has been updated.', array('%format' => $format->label())), 'Full HTML format successfully updated.');
......@@ -330,12 +331,12 @@ function testFilterAdmin() {
// Full HTML.
$edit = array();
$edit['roles[' . DRUPAL_AUTHENTICATED_RID . ']'] = FALSE;
$edit['roles[' . RoleInterface::AUTHENTICATED_ID . ']'] = FALSE;
$this->drupalPostForm('admin/config/content/formats/manage/' . $full, $edit, t('Save configuration'));
$this->assertUrl('admin/config/content/formats');
$this->assertRaw(t('The text format %format has been updated.', array('%format' => $format->label())), 'Full HTML format successfully reverted.');
$this->drupalGet('admin/config/content/formats/manage/' . $full);