ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilCtrlStructureCidGeneratorTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
29 {
30  public function testCidGeneratorIncrements(): void
31  {
32  $generator = new ilCtrlStructureCidGenerator();
33  $first_cid = $generator->getCid();
34  $next_cid = $generator->getCid();
35 
36  $this->assertEquals('0', $first_cid);
37  $this->assertNotEquals('0', $next_cid);
38  $this->assertEquals('1', $next_cid);
39  }
40 
42  {
43  $generator = new ilCtrlStructureCidGenerator(100);
44  $first_cid = $generator->getCid();
45  $next_cid = $generator->getCid();
46 
47  $this->assertEquals('2s', $first_cid);
48  $this->assertNotEquals('2s', $next_cid);
49  $this->assertEquals('2t', $next_cid);
50  }
51 
53  {
54  $generator = new ilCtrlStructureCidGenerator(-100);
55  $first_cid = $generator->getCid();
56  $next_cid = $generator->getCid();
57 
58  $this->assertEquals('-2s', $first_cid);
59  $this->assertNotEquals('-2s', $next_cid);
60  $this->assertEquals('-2r', $next_cid);
61  }
62 
64  {
65  $generator = new ilCtrlStructureCidGenerator(9223372036854775807);
66 
67  $this->expectException(TypeError::class);
68  $this->expectExceptionMessage('Cannot increment property ilCtrlStructureCidGenerator::$index of type int past its maximal value');
69  $cid = $generator->getCid();
70  }
71 
72  public function testCidGeneratorIndexByCidValue(): void
73  {
74  $generator = new ilCtrlStructureCidGenerator();
75 
76  $this->assertEquals(99999, $generator->getIndexByCid('255r'));
77  $this->assertEquals(-99999, $generator->getIndexByCid('-255r'));
78  $this->assertEquals(0, $generator->getIndexByCid('0'));
79  $this->assertEquals(0, $generator->getIndexByCid('-0'));
80  $this->assertEquals(1, $generator->getIndexByCid('1'));
81  $this->assertEquals(-1, $generator->getIndexByCid('-1'));
82  }
83 
84  public function testCidGeneratorCidByIndexValue(): void
85  {
86  $generator = new ilCtrlStructureCidGenerator();
87 
88  $this->assertEquals('255r', $generator->getCidByIndex(99999));
89  $this->assertEquals('-255r', $generator->getCidByIndex(-99999));
90  $this->assertEquals('0', $generator->getCidByIndex(0));
91  $this->assertEquals('0', $generator->getCidByIndex(-0));
92  $this->assertEquals('1', $generator->getCidByIndex(1));
93  $this->assertEquals('-1', $generator->getCidByIndex(-1));
94  }
95 }
Class ilCtrlStructureCidGenerator.
Class ilCtrlStructureCidGeneratorTest.