ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilLearningSequenceSettingsDBTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\TestCase;
22
24{
28 protected $db;
29
33 protected $ls_filesystem;
34
35 protected function setUp(): void
36 {
37 $this->db = $this->createMock(ilDBInterface::class);
38 $this->ls_filesystem = $this
39 ->getMockBuilder(ilLearningSequenceFilesystem::class)
40 ->disableOriginalConstructor()
41 ->getMock()
42 ;
43 }
44
45 public function testCreateObject(): void
46 {
47 $obj = new ilLearningSequenceSettingsDB($this->db, $this->ls_filesystem);
48
49 $this->assertInstanceOf(ilLearningSequenceSettingsDB::class, $obj);
50 }
51
53 {
54 $settings = new ilLearningSequenceSettings(333);
55
56 $where = [
57 'obj_id' => ['integer', 333]
58 ];
59
60 $values = [
61 'abstract' => ['text', ''],
62 'extro' => ['text', ''],
63 'abstract_image' => ['text', ''],
64 'extro_image' => ['text', ''],
65 'gallery' => ['integer', false]
66 ];
67
68 $this->db
69 ->expects($this->once())
70 ->method('update')
71 ->with('lso_settings', $values, $where)
72 ;
73
74 $obj = new ilLearningSequenceSettingsDB($this->db, $this->ls_filesystem);
75 $obj->store($settings);
76 }
77
79 {
80 $settings = new ilLearningSequenceSettings(
81 333,
82 'abstract',
83 'extro',
84 'abstract/path',
85 'extro_path',
86 true
87 );
88
89 $where = [
90 'obj_id' => ['integer', 333]
91 ];
92
93 $values = [
94 'abstract' => ['text', 'abstract'],
95 'extro' => ['text', 'extro'],
96 'abstract_image' => ['text', 'abstract/path'],
97 'extro_image' => ['text', 'extro_path'],
98 'gallery' => ['integer', true]
99 ];
100
101 $this->db
102 ->expects($this->once())
103 ->method('update')
104 ->with('lso_settings', $values, $where)
105 ;
106
107 $obj = new ilLearningSequenceSettingsDB($this->db, $this->ls_filesystem);
108 $obj->store($settings);
109 }
110
112 {
113 $settings = new ilLearningSequenceSettings(
114 333,
115 'abstract',
116 'extro',
117 'abstract/path',
118 'extro_path',
119 true
120 );
121 $settings = $settings->withUpload(['upload_info'], 'test');
122
123 $this->ls_filesystem
124 ->expects($this->once())
125 ->method('moveUploaded')
126 ->with('test', ['upload_info'], $settings)
127 ->willReturn($settings)
128 ;
129
130 $where = [
131 'obj_id' => ['integer', 333]
132 ];
133
134 $values = [
135 'abstract' => ['text', 'abstract'],
136 'extro' => ['text', 'extro'],
137 'abstract_image' => ['text', 'abstract/path'],
138 'extro_image' => ['text', 'extro_path'],
139 'gallery' => ['integer', true]
140 ];
141
142 $this->db
143 ->expects($this->once())
144 ->method('update')
145 ->with('lso_settings', $values, $where)
146 ;
147
148 $obj = new ilLearningSequenceSettingsDB($this->db, $this->ls_filesystem);
149 $obj->store($settings);
150 }
151
153 {
154 $settings = new ilLearningSequenceSettings(
155 333,
156 'abstract',
157 'extro',
158 'abstract/path',
159 'extro_path',
160 true
161 );
162 $settings = $settings->withDeletion('test');
163
164 $this->ls_filesystem
165 ->expects($this->once())
166 ->method('delete_image')
167 ->with('test', $settings)
168 ->willReturn($settings)
169 ;
170
171 $where = [
172 'obj_id' => ['integer', 333]
173 ];
174
175 $values = [
176 'abstract' => ['text', 'abstract'],
177 'extro' => ['text', 'extro'],
178 'abstract_image' => ['text', 'abstract/path'],
179 'extro_image' => ['text', 'extro_path'],
180 'gallery' => ['integer', true]
181 ];
182
183 $this->db
184 ->expects($this->once())
185 ->method('update')
186 ->with('lso_settings', $values, $where)
187 ;
188
189 $obj = new ilLearningSequenceSettingsDB($this->db, $this->ls_filesystem);
190 $obj->store($settings);
191 }
192
193 public function testGetSettingsForWithNewObject(): void
194 {
195 $sql =
196 'SELECT abstract, extro, abstract_image, extro_image, gallery' . PHP_EOL
197 . 'FROM lso_settings' . PHP_EOL
198 . 'WHERE obj_id = 333' . PHP_EOL
199 ;
200
201 $values = [
202 'obj_id' => ['integer', 333],
203 'abstract' => ['text', ''],
204 'extro' => ['text', ''],
205 'gallery' => ['integer', false]
206 ];
207
208 $this->db
209 ->expects($this->once())
210 ->method('quote')
211 ->with(333, 'integer')
212 ->willReturn('333')
213 ;
214 $return_statement = $this->getMockBuilder(ilDBStatement::class)->getMock();
215 $this->db
216 ->expects($this->once())
217 ->method('query')
218 ->with($sql)
219 ->willReturn($return_statement)
220 ;
221 $this->db
222 ->expects($this->once())
223 ->method('numRows')
224 ->willReturn(0)
225 ;
226 $this->db
227 ->expects($this->once())
228 ->method('insert')
229 ->with('lso_settings', $values)
230 ;
231
232 $obj = new ilLearningSequenceSettingsDB($this->db, $this->ls_filesystem);
233 $result = $obj->getSettingsFor(333);
234
235 $this->assertEquals(333, $result->getObjId());
236 $this->assertEquals('', $result->getAbstract());
237 $this->assertEquals('', $result->getExtro());
238 $this->assertEquals('', $result->getAbstractImage());
239 $this->assertEquals('', $result->getExtroImage());
240 $this->assertEquals(false, $result->getMembersGallery());
241 }
242
244 {
245 $sql =
246 'SELECT abstract, extro, abstract_image, extro_image, gallery' . PHP_EOL
247 . 'FROM lso_settings' . PHP_EOL
248 . 'WHERE obj_id = 333' . PHP_EOL
249 ;
250
251 $row = [
252 'obj_id' => 333,
253 'abstract' => 'abstract',
254 'extro' => 'extro',
255 'abstract_image' => 'abstract_image',
256 'extro_image' => 'extro_image',
257 'gallery' => true
258 ];
259
260 $this->db
261 ->expects($this->once())
262 ->method('quote')
263 ->with(333, 'integer')
264 ->willReturn('333')
265 ;
266 $return_statement = $this->getMockBuilder(ilDBStatement::class)->getMock();
267 $this->db
268 ->expects($this->once())
269 ->method('query')
270 ->with($sql)
271 ->willReturn($return_statement)
272 ;
273 $this->db
274 ->expects($this->once())
275 ->method('numRows')
276 ->willReturn(1)
277 ;
278 $this->db
279 ->expects($this->once())
280 ->method('fetchAssoc')
281 ->with($return_statement)
282 ->willReturn($row)
283 ;
284
285 $obj = new ilLearningSequenceSettingsDB($this->db, $this->ls_filesystem);
286 $result = $obj->getSettingsFor(333);
287
288 $this->assertEquals(333, $result->getObjId());
289 $this->assertEquals('abstract', $result->getAbstract());
290 $this->assertEquals('extro', $result->getExtro());
291 $this->assertEquals('abstract_image', $result->getAbstractImage());
292 $this->assertEquals('extro_image', $result->getExtroImage());
293 $this->assertEquals(true, $result->getMembersGallery());
294 }
295}
return true
Persistence for Settings (like abstract, extro)
Settings for an LSO (like abstract, extro)