ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilCtrlStructureCidGeneratorTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /* Copyright (c) 2021 Thibeau Fuhrer <thf@studer-raimann.ch> Extended GPL, see docs/LICENSE */
6 
8 
14 class ilCtrlStructureCidGeneratorTest extends TestCase
15 {
16  public function testCidGeneratorIncrements(): void
17  {
18  $generator = new ilCtrlStructureCidGenerator();
19  $first_cid = $generator->getCid();
20  $next_cid = $generator->getCid();
21 
22  $this->assertEquals('0', $first_cid);
23  $this->assertNotEquals('0', $next_cid);
24  $this->assertEquals('1', $next_cid);
25  }
26 
28  {
29  $generator = new ilCtrlStructureCidGenerator(100);
30  $first_cid = $generator->getCid();
31  $next_cid = $generator->getCid();
32 
33  $this->assertEquals('2s', $first_cid);
34  $this->assertNotEquals('2s', $next_cid);
35  $this->assertEquals('2t', $next_cid);
36  }
37 
39  {
40  $generator = new ilCtrlStructureCidGenerator(-100);
41  $first_cid = $generator->getCid();
42  $next_cid = $generator->getCid();
43 
44  $this->assertEquals('-2s', $first_cid);
45  $this->assertNotEquals('-2s', $next_cid);
46  $this->assertEquals('-2r', $next_cid);
47  }
48 
50  {
51  $generator = new ilCtrlStructureCidGenerator(9223372036854775807);
52 
53  $this->expectException(TypeError::class);
54  $this->expectExceptionMessage('Cannot increment property ilCtrlStructureCidGenerator::$index of type int past its maximal value');
55  $cid = $generator->getCid();
56  }
57 
58  public function testCidGeneratorIndexByCidValue(): void
59  {
60  $generator = new ilCtrlStructureCidGenerator();
61 
62  $this->assertEquals(99999, $generator->getIndexByCid('255r'));
63  $this->assertEquals(-99999, $generator->getIndexByCid('-255r'));
64  $this->assertEquals(0, $generator->getIndexByCid('0'));
65  $this->assertEquals(0, $generator->getIndexByCid('-0'));
66  $this->assertEquals(1, $generator->getIndexByCid('1'));
67  $this->assertEquals(-1, $generator->getIndexByCid('-1'));
68  }
69 
70  public function testCidGeneratorCidByIndexValue(): void
71  {
72  $generator = new ilCtrlStructureCidGenerator();
73 
74  $this->assertEquals('255r', $generator->getCidByIndex(99999));
75  $this->assertEquals('-255r', $generator->getCidByIndex(-99999));
76  $this->assertEquals('0', $generator->getCidByIndex(0));
77  $this->assertEquals('0', $generator->getCidByIndex(-0));
78  $this->assertEquals('1', $generator->getCidByIndex(1));
79  $this->assertEquals('-1', $generator->getCidByIndex(-1));
80  }
81 }
Class ilCtrlStructureCidGenerator.
Class ilCtrlStructureCidGeneratorTest.