diff --git a/core/tests/Drupal/Tests/Component/Uuid/UuidTest.php b/core/tests/Drupal/Tests/Component/Uuid/UuidTest.php index 09e221c..66bd544 100644 --- a/core/tests/Drupal/Tests/Component/Uuid/UuidTest.php +++ b/core/tests/Drupal/Tests/Component/Uuid/UuidTest.php @@ -9,7 +9,9 @@ use Drupal\Component\Uuid\Uuid; use Drupal\Component\Uuid\UuidInterface; -use Drupal\Component\Uuid\UuidService; +use Drupal\Component\Uuid\Com; +use Drupal\Component\Uuid\Pecl; +use Drupal\Component\Uuid\Php; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Tests\UnitTestCase; @@ -32,7 +34,7 @@ public static function getInfo() { /** * Tests generating a UUID. * - * @dataProvider uuidInstances + * @dataProvider providerUuidInstances */ public function testGenerateUuid(UuidInterface $instance) { $this->assertTrue(Uuid::isValid($instance->generate()), sprintf('UUID generation for %s works.', get_class($instance))); @@ -41,7 +43,7 @@ public function testGenerateUuid(UuidInterface $instance) { /** * Tests that generated UUIDs are unique. * - * @dataProvider uuidInstances + * @dataProvider providerUuidInstances */ public function testUuidIsUnique(UuidInterface $instance) { $this->assertNotEquals($instance->generate(), $instance->generate(), 'Same UUID was not generated twice.'); @@ -50,23 +52,41 @@ public function testUuidIsUnique(UuidInterface $instance) { /** * Tests UUID validation. + * + * @param string $uuid + * The uuid to check against. + * @param bool $is_valid + * Whether the uuid is valid or not. + * + * @dataProvider providerTestValidation */ - public function testUuidValidation() { - // These valid UUIDs. - $uuid_fqdn = '6ba7b810-9dad-11d1-80b4-00c04fd430c8'; - $uuid_min = '00000000-0000-0000-0000-000000000000'; - $uuid_max = 'ffffffff-ffff-ffff-ffff-ffffffffffff'; - - $this->assertTrue(Uuid::isValid($uuid_fqdn), $uuid_fqdn . ' is a valid UUID.'); - $this->assertTrue(Uuid::isValid($uuid_min), $uuid_min . ' is a valid UUID.'); - $this->assertTrue(Uuid::isValid($uuid_max), $uuid_max . ' is a valid UUID.'); - - // These are invalid UUIDs. - $invalid_format = '0ab26e6b-f074-4e44-9da-601205fa0e976'; - $invalid_length = '0ab26e6b-f074-4e44-9daf-1205fa0e9761f'; + public function testValidation($uuid, $is_valid) { + $this->assertEquals($is_valid, Uuid::isValid($uuid)); + } - $this->assertFalse(Uuid::isValid($invalid_format), $invalid_format . ' is not a valid UUID.'); - $this->assertFalse(Uuid::isValid($invalid_length), $invalid_length . ' is not a valid UUID.'); + /** + * Dataprovider for UUID instance tests. + * + * @return array + * An array of arrays containing + * - The Uuid to check against. + * - (bool) Whether or not the Uuid is valid. + */ + public function providerTestValidation() { + return array( + // These valid UUIDs. + // FQDN. + array('6ba7b810-9dad-11d1-80b4-00c04fd430c8', TRUE), + // Minimum. + array('00000000-0000-0000-0000-000000000000', TRUE), + // Maximum. + array('ffffffff-ffff-ffff-ffff-ffffffffffff', TRUE), + // These are invalid UUIDs. + // Invalid format. + array('0ab26e6b-f074-4e44-9da-601205fa0e976', FALSE), + // Invalid length. + array('0ab26e6b-f074-4e44-9daf-1205fa0e9761f', FALSE), + ); } /** @@ -74,18 +94,18 @@ public function testUuidValidation() { * * @return array */ - public function uuidInstances() { + public function providerUuidInstances() { - $instances[][] = new \Drupal\Component\Uuid\Php(); + $instances[][] = new Php(); // If valid PECL extensions exists add to list. if (function_exists('uuid_create') && !function_exists('uuid_make')) { - $instances[][] = new \Drupal\Component\Uuid\Pecl(); + $instances[][] = new Pecl(); } // If we are on Windows add the com implementation as well. if (function_exists('com_create_guid')) { - $instances[][] = new \Drupal\Component\Uuid\Com(); + $instances[][] = new Com(); } return $instances;