ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilAdvancedMDRecordObjectOrderingsTest.php
Go to the documentation of this file.
1 <?php
2 
21 
23 {
24  protected Container $dic;
25 
26  protected function setUp(): void
27  {
29  parent::setUp();
30  }
31 
32  public function testConstruct(): void
33  {
34  $sorting = new ilAdvancedMDRecordObjectOrderings();
35  $this->assertTrue($sorting instanceof ilAdvancedMDRecordObjectOrderings);
36  }
37 
38  public function testGlobalRecordSorting(): void
39  {
40  $record_id_reflection = new ReflectionMethod(ilAdvancedMDRecord::class, 'setRecordId');
41  $record_id_reflection->setAccessible(true);
42 
43  $ids = [1, 2, 3, 4, 5];
44  $positions = array_reverse($ids);
45  $records = [];
46  foreach ($ids as $id) {
47  $record = new ilAdvancedMDRecord();
48  $record->setGlobalPosition(array_shift($positions));
49  $record_id_reflection->invokeArgs($record, [$id]);
50 
51  $records[] = $record;
52  }
53 
54  $sorting = new ilAdvancedMDRecordObjectOrderings();
55  $sorted = $sorting->sortRecords($records);
56  $this->assertTrue(is_array($sorted));
57  foreach ($sorted as $index => $record) {
58  // test reverse ordering (idx + record equals 5)
59  $this->assertEquals(5, $index + $record->getRecordId());
60  }
61  }
62 
67  protected function setGlobalVariable(string $name, $value): void
68  {
69  global $DIC;
70 
71  $GLOBALS[$name] = $value;
72  unset($DIC[$name]);
73  $DIC[$name] = static function (\ILIAS\DI\Container $c) use ($value) {
74  return $value;
75  };
76  }
77 
78  protected function initRecordSortingDependencies(): void
79  {
80  $this->dic = new Container();
81  $GLOBALS['DIC'] = $this->dic;
82  $this->setGlobalVariable('ilDB', $this->createMock(ilDBInterface::class));
83  }
84 }
$c
Definition: deliver.php:25
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
$GLOBALS["DIC"]
Definition: wac.php:53
global $DIC
Definition: shib_login.php:22
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23