]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - tests/UUIDTest.php
UUID-generation tools
[quix0rs-gnu-social.git] / tests / UUIDTest.php
diff --git a/tests/UUIDTest.php b/tests/UUIDTest.php
new file mode 100644 (file)
index 0000000..de256ff
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+
+if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
+    print "This script must be run from the command line\n";
+    exit();
+}
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
+define('STATUSNET', true);
+
+require_once INSTALLDIR . '/lib/common.php';
+
+class UUIDTest extends PHPUnit_Framework_TestCase
+{
+    public function testGenerate()
+    {
+        $result = UUID::gen();
+        $this->assertRegExp('/^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$/',
+                            $result);
+        // Check version number
+        $this->assertEquals(0x4000, hexdec(substr($result, 14, 4)) & 0xF000);
+        $this->assertEquals(0x8000, hexdec(substr($result, 19, 4)) & 0xC000);
+    }
+}
+