diff --git a/core/modules/user/src/Tests/Condition/UserRoleConditionTest.php b/core/modules/user/src/Tests/Condition/UserRoleConditionTest.php index ca02b6d..d810e6e 100644 --- a/core/modules/user/src/Tests/Condition/UserRoleConditionTest.php +++ b/core/modules/user/src/Tests/Condition/UserRoleConditionTest.php @@ -7,6 +7,7 @@ namespace Drupal\user\Tests\Condition; +use Drupal\Component\Utility\String; use Drupal\simpletest\KernelTestBase; use Drupal\user\Entity\Role; use Drupal\user\Entity\User; @@ -73,6 +74,16 @@ protected function setUp() { $this->manager = $this->container->get('plugin.manager.condition'); + // Set up the authenticated and anonymous roles. + Role::create(array( + 'id' => DRUPAL_ANONYMOUS_RID, + 'label' => 'Anonymous user', + ))->save(); + Role::create(array( + 'id' => DRUPAL_AUTHENTICATED_RID, + 'label' => 'Authenticated user', + ))->save(); + // Create new role. $rid = strtolower($this->randomName(8)); $label = $this->randomString(8); @@ -113,19 +124,19 @@ public function testConditions() { $this->assertFalse($condition->execute(), 'Anonymous users fail role checks for authenticated.'); // Check for the proper summary. // Summaries require an extra space due to negate handling in summary(). - $this->assertEqual($condition->summary(), 'The user is a member of authenticated'); + $this->assertEqual($condition->summary(), 'The user is a member of Authenticated user'); // Set the user role to anonymous. $condition->setConfig('roles', array(DRUPAL_ANONYMOUS_RID => DRUPAL_ANONYMOUS_RID)); $this->assertTrue($condition->execute(), 'Anonymous users pass role checks for anonymous.'); // Check for the proper summary. - $this->assertEqual($condition->summary(), 'The user is a member of anonymous'); + $this->assertEqual($condition->summary(), 'The user is a member of Anonymous user'); // Set the user role to check anonymous or authenticated. $condition->setConfig('roles', array(DRUPAL_ANONYMOUS_RID => DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID)); $this->assertTrue($condition->execute(), 'Anonymous users pass role checks for anonymous or authenticated.'); // Check for the proper summary. - $this->assertEqual($condition->summary(), 'The user is a member of anonymous, authenticated'); + $this->assertEqual($condition->summary(), 'The user is a member of Anonymous user, Authenticated user'); // Set the context to the authenticated user and check that they also pass // against anonymous or authenticated roles. @@ -137,22 +148,22 @@ public function testConditions() { $this->assertTrue($condition->execute(), 'Authenticated users pass role checks for authenticated.'); // Test Constructor injection. - $condition = $this->manager->createInstance('user_role', array('roles' => array(DRUPAL_AUTHENTICATED_RID), 'context' => array('user' => $this->authenticated))); + $condition = $this->manager->createInstance('user_role', array('roles' => array(DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID), 'context' => array('user' => $this->authenticated))); $this->assertTrue($condition->execute(), 'Constructor injection of context and configuration working as anticipated.'); // Check the negated summary. $condition->setConfig('negate', TRUE); - $this->assertEqual($condition->summary(), 'The user is not a member of authenticated'); + $this->assertEqual($condition->summary(), 'The user is not a member of Authenticated user'); // Check the complex negated summary. $condition->setConfig('roles', array(DRUPAL_ANONYMOUS_RID => DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID)); - $this->assertEqual($condition->summary(), 'The user is not a member of anonymous, authenticated'); + $this->assertEqual($condition->summary(), 'The user is not a member of Anonymous user, Authenticated user'); // Check a custom role. $condition->setConfig('roles', array($this->role->id() => $this->role->id())); $condition->setConfig('negate', FALSE); - $this->assertTRUE($condition->execute(), 'Authenticated user is a member of the custom role.'); - $this->assertEqual($condition->summary(), 'The user is a member of ' . $this->role->id()); + $this->assertTrue($condition->execute(), 'Authenticated user is a member of the custom role.'); + $this->assertEqual($condition->summary(), String::format('The user is a member of @roles', array('@roles' => $this->role->label()))); } }