]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/UUIDTest.php
Always naming it 'plugin' is not good, it can easily confuse. So better name it
[quix0rs-gnu-social.git] / tests / UUIDTest.php
1 <?php
2
3 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
4     print "This script must be run from the command line\n";
5     exit();
6 }
7
8 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
9 define('GNUSOCIAL', true);
10 define('STATUSNET', true);  // compatibility
11
12 require_once INSTALLDIR . '/lib/common.php';
13
14 class UUIDTest extends PHPUnit_Framework_TestCase
15 {
16     public function testGenerate()
17     {
18         $result = UUID::gen();
19         $this->assertRegExp('/^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$/',
20                             $result);
21         // Check version number
22         $this->assertEquals(0x4000, hexdec(substr($result, 14, 4)) & 0xF000);
23         $this->assertEquals(0x8000, hexdec(substr($result, 19, 4)) & 0xC000);
24     }
25
26     public function testUnique()
27     {
28         $reps = 100;
29         $ids = array();
30
31         for ($i = 0; $i < $reps; $i++) {
32             $ids[] = UUID::gen();
33         }
34
35         $this->assertEquals(count($ids), count(array_unique($ids)), "UUIDs must be unique");
36     }
37 }
38