ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilCertificateTemplateImportActionTest.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
8 {
10  {
11  $placeholderDescriptionObject = $this->getMockBuilder('ilCertificatePlaceholderDescription')
12  ->getMock();
13 
14  $logger = $this->getMockBuilder('ilLogger')
15  ->disableOriginalConstructor()
16  ->getMock();
17 
18  $filesystem = $this->getMockBuilder('ILIAS\Filesystem\Filesystem')
19  ->getMock();
20 
21  $filesystem
22  ->expects($this->never())
23  ->method('deleteDir');
24 
25  $templateRepository = $this->getMockBuilder('ilCertificateTemplateRepository')
26  ->disableOriginalConstructor()
27  ->getMock();
28 
29  $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
30  ->getMock();
31 
32  $objectHelper->method('lookupType')
33  ->willReturn('crs');
34 
35  $utilHelper = $this->getMockBuilder('ilCertificateUtilHelper')
36  ->getMock();
37 
38  $utilHelper
39  ->method('moveUploadedFile')
40  ->willReturn(true);
41 
42  $utilHelper
43  ->expects($this->once())
44  ->method('unzip');
45 
46  $utilHelper
47  ->method('getDir')
48  ->willReturn(array(
49  array(
50  'type' => 'file',
51  'entry' => 'background.jpg'
52  ),
53  array(
54  'type' => 'file',
55  'entry' => 'certificate.xml'
56  )
57  ));
58 
59  $utilHelper
60  ->expects($this->once())
61  ->method('convertImage');
62 
63  $database = $this->getMockBuilder('ilDBInterface')
64  ->disableOriginalConstructor()
65  ->getMock();
66 
68  100,
69  'some/path/certiicate.xml',
70  $placeholderDescriptionObject,
71  $logger,
72  $filesystem,
73  $templateRepository,
74  $objectHelper,
75  $utilHelper,
76  $database,
77  'someInstallationId'
78  );
79 
80  $result = $action->import(
81  'someZipFile.zip',
82  'some/path/',
83  'some/root/path',
84  'v5.4.0',
85  'someInstallationId'
86  );
87 
88  $this->assertEquals(true, $result);
89  }
90 
92  {
93  $placeholderDescriptionObject = $this->getMockBuilder('ilCertificatePlaceholderDescription')
94  ->getMock();
95 
96  $logger = $this->getMockBuilder('ilLogger')
97  ->disableOriginalConstructor()
98  ->getMock();
99 
100  $filesystem = $this->getMockBuilder('ILIAS\Filesystem\Filesystem')
101  ->getMock();
102 
103  $filesystem
104  ->expects($this->never())
105  ->method('deleteDir');
106 
107  $templateRepository = $this->getMockBuilder('ilCertificateTemplateRepository')
108  ->disableOriginalConstructor()
109  ->getMock();
110 
111  $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
112  ->getMock();
113 
114  $objectHelper->method('lookupType')
115  ->willReturn('crs');
116 
117  $utilHelper = $this->getMockBuilder('ilCertificateUtilHelper')
118  ->getMock();
119 
120  $utilHelper
121  ->method('moveUploadedFile')
122  ->willReturn(true);
123 
124  $utilHelper
125  ->expects($this->once())
126  ->method('unzip');
127 
128  $utilHelper
129  ->method('getDir')
130  ->willReturn(array(
131  array(
132  'type' => 'file',
133  'entry' => 'certificate.xml'
134  )
135  ));
136 
137  $database = $this->getMockBuilder('ilDBInterface')
138  ->disableOriginalConstructor()
139  ->getMock();
140 
142  100,
143  'some/path/certiicate.xml',
144  $placeholderDescriptionObject,
145  $logger,
146  $filesystem,
147  $templateRepository,
148  $objectHelper,
149  $utilHelper,
150  $database,
151  'someInstallationId'
152  );
153 
154  $result = $action->import(
155  'someZipFile.zip',
156  'some/path/',
157  'some/root/path',
158  'v5.4.0',
159  'someInstallationId'
160  );
161 
162  $this->assertEquals(true, $result);
163  }
164 
166  {
167  $placeholderDescriptionObject = $this->getMockBuilder('ilCertificatePlaceholderDescription')
168  ->getMock();
169 
170  $logger = $this->getMockBuilder('ilLogger')
171  ->disableOriginalConstructor()
172  ->getMock();
173 
174  $filesystem = $this->getMockBuilder('ILIAS\Filesystem\Filesystem')
175  ->getMock();
176 
177  $filesystem
178  ->expects($this->once())
179  ->method('deleteDir');
180 
181  $templateRepository = $this->getMockBuilder('ilCertificateTemplateRepository')
182  ->disableOriginalConstructor()
183  ->getMock();
184 
185  $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
186  ->getMock();
187 
188  $utilHelper = $this->getMockBuilder('ilCertificateUtilHelper')
189  ->getMock();
190 
191  $utilHelper
192  ->method('moveUploadedFile')
193  ->willReturn(true);
194 
195  $utilHelper
196  ->expects($this->once())
197  ->method('unzip');
198 
199  $utilHelper
200  ->method('getDir')
201  ->willReturn(array());
202 
203  $database = $this->getMockBuilder('ilDBInterface')
204  ->disableOriginalConstructor()
205  ->getMock();
206 
208  100,
209  'some/path/certiicate.xml',
210  $placeholderDescriptionObject,
211  $logger,
212  $filesystem,
213  $templateRepository,
214  $objectHelper,
215  $utilHelper,
216  $database
217  );
218 
219  $result = $action->import(
220  'someZipFile.zip',
221  'some/path/',
222  'some/root/path',
223  'v5.4.0',
224  'someInstallationId'
225  );
226 
227  $this->assertEquals(false, $result);
228  }
229 
230  public function testZipfileCouldNoBeMoved()
231  {
232  $placeholderDescriptionObject = $this->getMockBuilder('ilCertificatePlaceholderDescription')
233  ->disableOriginalConstructor()
234  ->getMock();
235 
236  $logger = $this->getMockBuilder('ilLogger')
237  ->disableOriginalConstructor()
238  ->getMock();
239 
240  $filesystem = $this->getMockBuilder('ILIAS\Filesystem\Filesystem')
241  ->getMock();
242 
243  $filesystem
244  ->expects($this->once())
245  ->method('deleteDir');
246 
247  $templateRepository = $this->getMockBuilder('ilCertificateTemplateRepository')
248  ->disableOriginalConstructor()
249  ->getMock();
250 
251  $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
252  ->getMock();
253 
254  $utilHelper = $this->getMockBuilder('ilCertificateUtilHelper')
255  ->getMock();
256 
257  $utilHelper
258  ->method('moveUploadedFile')
259  ->willReturn(false);
260 
261  $database = $this->getMockBuilder('ilDBInterface')
262  ->disableOriginalConstructor()
263  ->getMock();
264 
266  100,
267  'some/path/certiicate.xml',
268  $placeholderDescriptionObject,
269  $logger,
270  $filesystem,
271  $templateRepository,
272  $objectHelper,
273  $utilHelper,
274  $database,
275  'someInstallationId'
276  );
277 
278  $result = $action->import(
279  'someZipFile.zip',
280  'some/path/',
281  'some/root/path',
282  'v5.4.0',
283  'someInstallationId'
284  );
285 
286  $this->assertEquals(false, $result);
287  }
288 }
$result
$action
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.