ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilLSItemsDBTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 {
25  protected function getIconPathForType(string $type): string
26  {
27  return './image/tester/myimage.png';
28  }
29  protected function getCurrentLPMode(int $obj_id): int
30  {
31  return 1;
32  }
33 }
34 
36 {
37  protected ilTree $tree;
42 
43  protected function setUp(): void
44  {
45  $this->tree = $this->createMock(ilTree::class);
46  $this->container_sorting = $this->createMock(ilContainerSorting::class);
47  $this->post_conditions_db = $this->createMock(ilLSPostConditionDB::class);
48  $this->ls_item_online_status = $this->createMock(LSItemOnlineStatus::class);
49  $this->sorting_settings = $this->createMock(ilContainerSortingSettings::class);
50  }
51 
52  public function testCreateObject(): void
53  {
54  $obj = new ilLSItemsDB(
55  $this->tree,
56  $this->container_sorting,
57  $this->post_conditions_db,
58  $this->ls_item_online_status
59  );
60 
61  $this->assertInstanceOf(ilLSItemsDB::class, $obj);
62  }
63 
64  public function testGetLSItemsWithoutData(): void
65  {
66  $this->tree
67  ->expects($this->once())
68  ->method('getChilds')
69  ->with(22)
70  ->willReturn([])
71  ;
72 
73  $this->sorting_settings
74  ->expects($this->once())
75  ->method('setSortMode')
77  ;
78 
79  $this->container_sorting
80  ->expects($this->once())
81  ->method('getSortingSettings')
82  ->willReturn($this->sorting_settings)
83  ;
84  $this->container_sorting
85  ->expects($this->once())
86  ->method('sortItems')
87  ->with(['lsitems' => []])
88  ->willReturn(['lsitems' => []])
89  ;
90 
91  $obj = new ilLSItemsDB(
92  $this->tree,
93  $this->container_sorting,
94  $this->post_conditions_db,
95  $this->ls_item_online_status
96  );
97 
98  $result = $obj->getLSItems(22);
99 
100  $this->assertIsArray($result);
101  $this->assertEmpty($result);
102  }
103 
104  public function testGetLSItemsWithData(): void
105  {
106  $value = [
107  '22' => [
108  'child' => 14,
109  'obj_id' => 16,
110  'type' => 'lsitem',
111  'title' => 'ls_title',
112  'description' => 'tiny_description'
113  ]
114  ];
115 
116  $this->tree
117  ->expects($this->once())
118  ->method('getChilds')
119  ->with(22)
120  ->willReturn($value)
121  ;
122 
123  $this->sorting_settings
124  ->expects($this->once())
125  ->method('setSortMode')
127  ;
128 
129  $this->container_sorting
130  ->expects($this->once())
131  ->method('getSortingSettings')
132  ->willReturn($this->sorting_settings)
133  ;
134  $this->container_sorting
135  ->expects($this->once())
136  ->method('sortItems')
137  ->with(['lsitems' => $value])
138  ->willReturn(['lsitems' => $value])
139  ;
140 
141  $condition = $this->createMock(ilLSPostCondition::class);
142  $condition
143  ->expects($this->once())
144  ->method('getRefId')
145  ->willReturn(14)
146  ;
147 
148  $this->post_conditions_db
149  ->expects($this->once())
150  ->method('select')
151  ->with([22 => 14])
152  ->willReturn(['14' => $condition])
153  ;
154 
155  $this->ls_item_online_status
156  ->expects($this->once())
157  ->method('getOnlineStatus')
158  ->with(14)
159  ->willReturn(true)
160  ;
161 
162  $obj = new ilLSItemsDBStub(
163  $this->tree,
164  $this->container_sorting,
165  $this->post_conditions_db,
166  $this->ls_item_online_status
167  );
168 
169  $result = $obj->getLSItems(22);
170 
171  foreach ($result as $ls_item) {
172  $this->assertEquals('lsitem', $ls_item->getType());
173  $this->assertEquals('ls_title', $ls_item->getTitle());
174  $this->assertEquals('tiny_description', $ls_item->getDescription());
175  $this->assertEquals('./image/tester/myimage.png', $ls_item->getIconPath());
176  $this->assertTrue($ls_item->isOnline());
177  $this->assertEquals(22, $ls_item->getOrderNumber());
178  $this->assertInstanceOf(ilLSPostCondition::class, $ls_item->getPostCondition());
179  $this->assertEquals(14, $ls_item->getRefId());
180  }
181  }
182 
183  public function testStoreItems(): void
184  {
185  $condition = $this->createMock(ilLSPostCondition::class);
186 
187  $ls_item = new LSItem(
188  'ls_item',
189  'ls_title',
190  'ls_description',
191  '',
192  true,
193  22,
194  $condition,
195  14,
196  1
197  );
198 
199  $this->ls_item_online_status
200  ->expects($this->once())
201  ->method('setOnlineStatus')
202  ->with(14, true)
203  ;
204 
205  $this->container_sorting
206  ->expects($this->once())
207  ->method('savePost')
208  ->with([14 => 22])
209  ;
210 
211  $this->post_conditions_db
212  ->expects($this->once())
213  ->method('upsert')
214  ->with([$condition])
215  ;
216 
217  $obj = new ilLSItemsDB(
218  $this->tree,
219  $this->container_sorting,
220  $this->post_conditions_db,
221  $this->ls_item_online_status
222  );
223 
224  $obj->storeItems([$ls_item]);
225  }
226 }
Storage for ilLSPostConditions.
ilContainerSortingSettings $sorting_settings
Class ilLSItemsDB.
Definition: ilLSItemsDB.php:24
ilContainerSorting $container_sorting
ilLSPostConditionDB $post_conditions_db
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Data holding class LSItem .
Definition: LSItem.php:24
getIconPathForType(string $type)
getCurrentLPMode(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
LSItemOnlineStatus $ls_item_online_status