ILIAS  release_8 Revision v8.23
ilAdvancedMDRecordObjectOrderingsTest.php
Go to the documentation of this file.
1 <?php
2 
5 
7 {
8  protected Container $dic;
9 
10  protected function setUp(): void
11  {
13  parent::setUp();
14  }
15 
16  public function testConstruct(): void
17  {
18  $sorting = new ilAdvancedMDRecordObjectOrderings();
19  $this->assertTrue($sorting instanceof ilAdvancedMDRecordObjectOrderings);
20  }
21 
22  public function testGlobalRecordSorting(): void
23  {
24  $record_id_reflection = new ReflectionMethod(ilAdvancedMDRecord::class, 'setRecordId');
25  $record_id_reflection->setAccessible(true);
26 
27  $ids = [1, 2, 3, 4, 5];
28  $positions = array_reverse($ids);
29  $records = [];
30  foreach ($ids as $id) {
31  $record = new ilAdvancedMDRecord();
32  $record->setGlobalPosition(array_shift($positions));
33  $record_id_reflection->invokeArgs($record, [$id]);
34 
35  $records[] = $record;
36  }
37 
38  $sorting = new ilAdvancedMDRecordObjectOrderings();
39  $sorted = $sorting->sortRecords($records);
40  $this->assertTrue(is_array($sorted));
41  foreach ($sorted as $index => $record) {
42  // test reverse ordering (idx + record equals 5)
43  $this->assertEquals(5, $index + $record->getRecordId());
44  }
45  }
46 
51  protected function setGlobalVariable(string $name, $value): void
52  {
53  global $DIC;
54 
55  $GLOBALS[$name] = $value;
56  unset($DIC[$name]);
57  $DIC[$name] = static function (\ILIAS\DI\Container $c) use ($value) {
58  return $value;
59  };
60  }
61 
62  protected function initRecordSortingDependencies(): void
63  {
64  $this->dic = new Container();
65  $GLOBALS['DIC'] = $this->dic;
66  $this->setGlobalVariable('ilDB', $this->createMock(ilDBInterface::class));
67  }
68 }
$c
Definition: cli.php:38
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:31
$index
Definition: metadata.php:145
global $DIC
Definition: feed.php:28
if($format !==null) $name
Definition: metadata.php:247
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23