.../Drupal/user/Tests/PermissionsHashTest.php | 40 ++++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/core/modules/user/tests/Drupal/user/Tests/PermissionsHashTest.php b/core/modules/user/tests/Drupal/user/Tests/PermissionsHashTest.php index fbda820..5bde4bc 100644 --- a/core/modules/user/tests/Drupal/user/Tests/PermissionsHashTest.php +++ b/core/modules/user/tests/Drupal/user/Tests/PermissionsHashTest.php @@ -23,11 +23,32 @@ class PermissionsHashTest extends UnitTestCase { /** - * The mocked account. + * A mocked account. * * @var \Drupal\user\UserInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $account; + protected $account_1; + + /** + * An "updated" mocked account. + * + * @var \Drupal\user\UserInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $account_1_updated; + + /** + * A different account. + * + * @var \Drupal\user\UserInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $account_2; + + /** + * The mocked private key service. + * + * @var \Drupal\Core\PrivateKey|\PHPUnit_Framework_MockObject_MockObject + */ + protected $private_key; /** * The mocked cache backend. @@ -101,6 +122,16 @@ protected function setUp() { * Tests the generate() method. */ public function testGenerate() { + // Set expectations for the mocked cache backend. + $expected_cid = 'user_permissions_hash:administrator,authenticated'; + $this->cache->expects($this->at(0))->method('get')->with($expected_cid)->will($this->returnValue(FALSE)); + $this->cache->expects($this->at(1))->method('set')->with($expected_cid); + $this->cache->expects($this->at(2))->method('get')->with($expected_cid)->will($this->returnValue(FALSE)); + $this->cache->expects($this->at(3))->method('set')->with($expected_cid); + $expected_cid .= ',editor'; + $this->cache->expects($this->at(4))->method('get')->with($expected_cid)->will($this->returnValue(FALSE)); + $this->cache->expects($this->at(5))->method('set')->with($expected_cid); + // Ensure that two user accounts with the same roles generate the same hash. $permissions_hash = new PermissionsHash($this->private_key, $this->cache); $hash_1 = $permissions_hash->generate($this->account_1); @@ -116,9 +147,9 @@ public function testGenerate() { } -// @todo remove once user_role_permissions() can be injected. namespace { + // @todo remove once user_role_permissions() can be injected. if (!function_exists('user_role_permissions')) { function user_role_permissions(array $roles) { $role_permissions = array(); @@ -129,11 +160,12 @@ function user_role_permissions(array $roles) { } } + // @todo remove once drupal_get_hash_salt() can be injected. if (!function_exists('drupal_get_hash_salt')) { function drupal_get_hash_salt() { static $salt; - if (isset($salt)) { + if (!isset($salt)) { $salt = Drupal\Component\Utility\Crypt::randomStringHashed(55); }