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