MediaWiki  1.23.0
UIDGeneratorTest.php
Go to the documentation of this file.
1 <?php
2 
4 
5  protected function tearDown() {
6  // Bug: 44850
8  parent::tearDown();
9  }
10 
16  public function testTimestampedUID( $method, $digitlen, $bits, $tbits, $hostbits ) {
17  $id = call_user_func( array( 'UIDGenerator', $method ) );
18  $this->assertEquals( true, ctype_digit( $id ), "UID made of digit characters" );
19  $this->assertLessThanOrEqual( $digitlen, strlen( $id ),
20  "UID has the right number of digits" );
21  $this->assertLessThanOrEqual( $bits, strlen( wfBaseConvert( $id, 10, 2 ) ),
22  "UID has the right number of bits" );
23 
24  $ids = array();
25  for ( $i = 0; $i < 300; $i++ ) {
26  $ids[] = call_user_func( array( 'UIDGenerator', $method ) );
27  }
28 
29  $lastId = array_shift( $ids );
30 
31  $this->assertArrayEquals( array_unique( $ids ), $ids, "All generated IDs are unique." );
32 
33  foreach ( $ids as $id ) {
34  $id_bin = wfBaseConvert( $id, 10, 2 );
35  $lastId_bin = wfBaseConvert( $lastId, 10, 2 );
36 
37  $this->assertGreaterThanOrEqual(
38  substr( $id_bin, 0, $tbits ),
39  substr( $lastId_bin, 0, $tbits ),
40  "New ID timestamp ($id_bin) >= prior one ($lastId_bin)." );
41 
42  if ( $hostbits ) {
43  $this->assertEquals(
44  substr( $id_bin, 0, -$hostbits ),
45  substr( $lastId_bin, 0, -$hostbits ),
46  "Host ID of ($id_bin) is same as prior one ($lastId_bin)." );
47  }
48 
49  $lastId = $id;
50  }
51  }
52 
57  public static function provider_testTimestampedUID() {
58  return array(
59  array( 'newTimestampedUID128', 39, 128, 46, 48 ),
60  array( 'newTimestampedUID128', 39, 128, 46, 48 ),
61  array( 'newTimestampedUID88', 27, 88, 46, 32 ),
62  );
63  }
64 
68  public function testUUIDv4() {
69  for ( $i = 0; $i < 100; $i++ ) {
71  $this->assertEquals( true,
72  preg_match( '!^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$!', $id ),
73  "UID $id has the right format" );
74  }
75  }
76 
80  public function testRawUUIDv4() {
81  for ( $i = 0; $i < 100; $i++ ) {
83  $this->assertEquals( true,
84  preg_match( '!^[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15}$!', $id ),
85  "UID $id has the right format" );
86  }
87  }
88 
92  public function testRawUUIDv4QuickRand() {
93  for ( $i = 0; $i < 100; $i++ ) {
95  $this->assertEquals( true,
96  preg_match( '!^[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15}$!', $id ),
97  "UID $id has the right format" );
98  }
99  }
100 
104  public function testNewSequentialID() {
105  $id1 = UIDGenerator::newSequentialPerNodeID( 'test', 32 );
106  $id2 = UIDGenerator::newSequentialPerNodeID( 'test', 32 );
107 
108  $this->assertType( 'float', $id1, "ID returned as float" );
109  $this->assertType( 'float', $id2, "ID returned as float" );
110  $this->assertGreaterThan( 0, $id1, "ID greater than 1" );
111  $this->assertGreaterThan( $id1, $id2, "IDs increasing in value" );
112  }
113 
117  public function testNewSequentialIDs() {
118  $ids = UIDGenerator::newSequentialPerNodeIDs( 'test', 32, 5 );
119  $lastId = null;
120  foreach ( $ids as $id ) {
121  $this->assertType( 'float', $id, "ID returned as float" );
122  $this->assertGreaterThan( 0, $id, "ID greater than 1" );
123  if ( $lastId ) {
124  $this->assertGreaterThan( $lastId, $id, "IDs increasing in value" );
125  }
126  $lastId = $id;
127  }
128  }
129 }
UIDGenerator\QUICK_RAND
const QUICK_RAND
Definition: UIDGenerator.php:42
MediaWikiTestCase\assertArrayEquals
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
Definition: MediaWikiTestCase.php:764
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
UIDGeneratorTest
Definition: UIDGeneratorTest.php:3
UIDGeneratorTest\provider_testTimestampedUID
static provider_testTimestampedUID()
array( method, length, bits, hostbits ) NOTE: When adding a new method name here please update the co...
Definition: UIDGeneratorTest.php:57
UIDGenerator\newRawUUIDv4
static newRawUUIDv4( $flags=0)
Return an RFC4122 compliant v4 UUID.
Definition: UIDGenerator.php:217
UIDGeneratorTest\testTimestampedUID
testTimestampedUID( $method, $digitlen, $bits, $tbits, $hostbits)
@dataProvider provider_testTimestampedUID @covers UIDGenerator::newTimestampedUID128 @covers UIDGener...
Definition: UIDGeneratorTest.php:16
UIDGeneratorTest\testUUIDv4
testUUIDv4()
@covers UIDGenerator::newUUIDv4
Definition: UIDGeneratorTest.php:68
UIDGenerator\newSequentialPerNodeID
static newSequentialPerNodeID( $bucket, $bits=48, $flags=0)
Return an ID that is sequential only for this node and bucket.
Definition: UIDGenerator.php:233
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
UIDGeneratorTest\testRawUUIDv4QuickRand
testRawUUIDv4QuickRand()
@covers UIDGenerator::newRawUUIDv4
Definition: UIDGeneratorTest.php:92
UIDGeneratorTest\testNewSequentialIDs
testNewSequentialIDs()
@covers UIDGenerator::newSequentialPerNodeIDs
Definition: UIDGeneratorTest.php:117
UIDGenerator\newUUIDv4
static newUUIDv4( $flags=0)
Return an RFC4122 compliant v4 UUID.
Definition: UIDGenerator.php:191
UIDGenerator\unitTestTearDown
static unitTestTearDown()
Cleanup resources when tearing down after a unit test.
Definition: UIDGenerator.php:495
wfBaseConvert
wfBaseConvert( $input, $sourceBase, $destBase, $pad=1, $lowercase=true, $engine='auto')
Convert an arbitrarily-long digit string from one numeric base to another, optionally zero-padding to...
Definition: GlobalFunctions.php:3368
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
UIDGeneratorTest\testRawUUIDv4
testRawUUIDv4()
@covers UIDGenerator::newRawUUIDv4
Definition: UIDGeneratorTest.php:80
UIDGeneratorTest\testNewSequentialID
testNewSequentialID()
@covers UIDGenerator::newSequentialPerNodeID
Definition: UIDGeneratorTest.php:104
UIDGenerator\newSequentialPerNodeIDs
static newSequentialPerNodeIDs( $bucket, $bits, $count, $flags=0)
Return IDs that are sequential only for this node and bucket.
Definition: UIDGenerator.php:248
UIDGeneratorTest\tearDown
tearDown()
Definition: UIDGeneratorTest.php:5
MediaWikiTestCase\assertType
assertType( $type, $actual, $message='')
Asserts the type of the provided value.
Definition: MediaWikiTestCase.php:869