diff --git a/core/tests/Drupal/Tests/Component/Utility/CryptTest.php b/core/tests/Drupal/Tests/Component/Utility/CryptTest.php index f212d68..4d0c4ad 100644 --- a/core/tests/Drupal/Tests/Component/Utility/CryptTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/CryptTest.php @@ -89,21 +89,16 @@ public function testHmacBase64Invalid($data, $key) { * * @dataProvider providerTestShortHash * @covers ::shortHash - * + * * @param string $data * Data to hash. * @param string $key * Key to use in hashing process. + * @param string $expected_hash + * The expected hash. */ - public function testShortHash($data, $key) { - $hash = Crypt::shortHash($data, NULL); - $this->assertEquals(strlen($hash), Crypt::SHORT_HASH_LENGTH_DEFAULT); - $hash2 = Crypt::shortHash($data, $key); - $this->assertEquals(strlen($hash2), Crypt::SHORT_HASH_LENGTH_DEFAULT); - $this->assertNotEqual($hash, $hash2); - $hash3 = Crypt::shortHash($data, NULL, 15); - $this->assertEquals(strlen($hash3), 15); - $this->assertEquals(substr($hash3, 0, 10), $hash); + public function testShortHash($data, $key, $expected_hash) { + $this->assertSame($expected_hash, Crypt::shortHash($data, $key)); } /** @@ -177,13 +172,25 @@ public function providerTestHmacBase64Invalid() { /** * Provides data for self::testShortHash(). * - * @return array Test data. + * @return array + * Test data. */ public function providerTestShortHash() { return [ [ 'data' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum', 'key' => 'secret-key', + 'expected_hash' => '3gulzih2ms', + ], + [ + 'data' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum', + 'key' => NULL, + 'expected_hash' => '3js5i38cnx', + ], + [ + 'data' => 'Lorem', + 'key' => NULL, + 'expected_hash' => 'oo8723opxr', ], ]; }