ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilXlsFoParserTest.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  $formData = array(
12  'certificate_text' => '<xml> Some Context </xml>',
13  'margin_body' => array(
14  'top' => '1cm',
15  'right' => '2cm',
16  'bottom' => '3cm',
17  'left' => '4cm'
18  ),
19  'pageformat' => 'a4'
20  );
21 
22  $settings = $this->getMockBuilder('ilSetting')
23  ->disableOriginalConstructor()
24  ->getMock();
25 
26  $settings->method('get')
27  ->willReturn('Something');
28 
29  $pageFormats = $this->getMockBuilder('ilPageFormats')
30  ->disableOriginalConstructor()
31  ->getMock();
32 
33  $pageFormats->method('fetchPageFormats')
34  ->willReturn(array(
35  'a4' => array(
36  'name' => 'A4',
37  'value' => 'a4',
38  'width' => '210mm',
39  'height' => '297mm'
40  ),
41  ));
42 
43  $xmlChecker = $this->getMockBuilder('ilXMLChecker')
44  ->getMock();
45 
46  $utilHelper = $this->getMockBuilder('ilCertificateUtilHelper')
47  ->getMock();
48 
49  $utilHelper->method('stripSlashes')
50  ->willReturnOnConsecutiveCalls(
51  '297mm',
52  '210mm',
53  '1cm',
54  '2cm',
55  '3cm',
56  '4cm'
57  );
58 
59  $xlstProcess = $this->getMockBuilder('ilCertificateXlstProcess')
60  ->getMock();
61 
62  $xlstProcess->method('process')
63  ->with(
64  array(
65  '/_xml' => '<html><body><xml> Some Context </xml></body></html>',
66  '/_xsl' => '<xml>Some XLS Content</xml>'
67  ),
68  array(
69  'pageheight' => '297mm',
70  'pagewidth' => '210mm',
71  'backgroundimage' => '[BACKGROUND_IMAGE]',
72  'marginbody' => '1cm 2cm 3cm 4cm'
73  )
74  )
75  ->willReturn('Something Processed');
76 
77  $language = $this->getMockBuilder('ilLanguage')
78  ->disableOriginalConstructor()
79  ->getMock();
80 
81  $certificateXlsFileLoader = $this->getMockBuilder('ilCertificateXlsFileLoader')
82  ->getMock();
83 
84  $certificateXlsFileLoader->method('getXlsCertificateContent')
85  ->willReturn('<xml>Some XLS Content</xml>');
86 
87  $xlsFoParser = new ilXlsFoParser(
88  $settings,
89  $pageFormats,
90  $xmlChecker,
91  $utilHelper,
92  $xlstProcess,
93  $language,
94  $certificateXlsFileLoader
95  );
96 
97  $output = $xlsFoParser->parse($formData);
98 
99  $this->assertEquals('Something Processed', $output);
100  }
101 
106  {
107  $formData = array(
108  'certificate_text' => '<xml> Some Context </xml>',
109  'margin_body' => array(
110  'top' => '1cm',
111  'right' => '2cm',
112  'bottom' => '3cm',
113  'left' => '4cm'
114  ),
115  'pageformat' => 'custom'
116  );
117 
118  $settings = $this->getMockBuilder('ilSetting')
119  ->disableOriginalConstructor()
120  ->getMock();
121 
122  $settings->method('get')
123  ->willReturn('Something');
124 
125  $pageFormats = $this->getMockBuilder('ilPageFormats')
126  ->disableOriginalConstructor()
127  ->getMock();
128 
129  $pageFormats->method('fetchPageFormats')
130  ->willReturn(array(
131  'a4' => array(
132  'name' => 'A4',
133  'value' => 'a4',
134  'width' => '210mm',
135  'height' => '297mm'
136  ),
137  ));
138 
139  $xmlChecker = $this->getMockBuilder('ilXMLChecker')
140  ->getMock();
141 
142  $xmlChecker->method('hasError')
143  ->willReturn(true);
144 
145  $utilHelper = $this->getMockBuilder('ilCertificateUtilHelper')
146  ->getMock();
147 
148  $xlstProcess = $this->getMockBuilder('ilCertificateXlstProcess')
149  ->getMock();
150 
151  $language = $this->getMockBuilder('ilLanguage')
152  ->disableOriginalConstructor()
153  ->getMock();
154 
155  $certificateXlsFileLoader = $this->getMockBuilder('ilCertificateXlsFileLoader')
156  ->getMock();
157 
158  $certificateXlsFileLoader->method('getXlsCertificateContent')
159  ->willReturn('<xml>Some XLS Content</xml>');
160 
161  $xlsFoParser = new ilXlsFoParser(
162  $settings,
163  $pageFormats,
164  $xmlChecker,
165  $utilHelper,
166  $xlstProcess,
167  $language,
168  $certificateXlsFileLoader
169  );
170 
171  $xlsFoParser->parse($formData);
172 
173  $this->fail();
174  }
175 
177  {
178  $formData = array(
179  'certificate_text' => '<xml> Some Context </xml>',
180  'margin_body' => array(
181  'top' => '1cm',
182  'right' => '2cm',
183  'bottom' => '3cm',
184  'left' => '4cm'
185  ),
186  'pageformat' => 'custom',
187  'pagewidth' => '210mm',
188  'pageheight' => '297mm'
189  );
190 
191  $settings = $this->getMockBuilder('ilSetting')
192  ->disableOriginalConstructor()
193  ->getMock();
194 
195  $settings->method('get')
196  ->willReturn('Something');
197 
198  $pageFormats = $this->getMockBuilder('ilPageFormats')
199  ->disableOriginalConstructor()
200  ->getMock();
201 
202  $pageFormats->method('fetchPageFormats')
203  ->willReturn(array(
204  'a4' => array(
205  'name' => 'A4',
206  'value' => 'a4',
207  'width' => '210mm',
208  'height' => '297mm'
209  ),
210  ));
211 
212  $xmlChecker = $this->getMockBuilder('ilXMLChecker')
213  ->getMock();
214 
215  $utilHelper = $this->getMockBuilder('ilCertificateUtilHelper')
216  ->getMock();
217 
218  $utilHelper->method('stripSlashes')
219  ->willReturnOnConsecutiveCalls(
220  '297mm',
221  '210mm',
222  '1cm',
223  '2cm',
224  '3cm',
225  '4cm'
226  );
227 
228  $xlstProcess = $this->getMockBuilder('ilCertificateXlstProcess')
229  ->getMock();
230 
231  $xlstProcess->method('process')
232  ->with(
233  array(
234  '/_xml' => '<html><body><xml> Some Context </xml></body></html>',
235  '/_xsl' => '<xml>Some XLS Content</xml>'
236  ),
237  array(
238  'pageheight' => '297mm',
239  'pagewidth' => '210mm',
240  'backgroundimage' => '[BACKGROUND_IMAGE]',
241  'marginbody' => '1cm 2cm 3cm 4cm'
242  )
243  )
244  ->willReturn('Something Processed');
245 
246  $language = $this->getMockBuilder('ilLanguage')
247  ->disableOriginalConstructor()
248  ->getMock();
249 
250  $certificateXlsFileLoader = $this->getMockBuilder('ilCertificateXlsFileLoader')
251  ->getMock();
252 
253  $certificateXlsFileLoader->method('getXlsCertificateContent')
254  ->willReturn('<xml>Some XLS Content</xml>');
255 
256  $xlsFoParser = new ilXlsFoParser(
257  $settings,
258  $pageFormats,
259  $xmlChecker,
260  $utilHelper,
261  $xlstProcess,
262  $language,
263  $certificateXlsFileLoader
264  );
265 
266  $output = $xlsFoParser->parse($formData);
267 
268  $this->assertEquals('Something Processed', $output);
269  }
270 
272  {
273  $formData = array(
274  'certificate_text' => '<xml> Some Context </xml>',
275  'margin_body' => array(
276  'top' => '1cm',
277  'right' => '2cm',
278  'bottom' => '3cm',
279  'left' => '4cm'
280  ),
281  'pageformat' => 'custom',
282  'pagewidth' => '210mm',
283  'pageheight' => '297mm'
284  );
285 
286  $settings = $this->getMockBuilder('ilSetting')
287  ->disableOriginalConstructor()
288  ->getMock();
289 
290  $settings->method('get')
291  ->willReturn('Something');
292 
293  $pageFormats = $this->getMockBuilder('ilPageFormats')
294  ->disableOriginalConstructor()
295  ->getMock();
296 
297  $pageFormats->method('fetchPageFormats')
298  ->willReturn(array(
299  'a4' => array(
300  'name' => 'A4',
301  'value' => 'a4',
302  'width' => '21,0mm',
303  'height' => '29,7mm'
304  ),
305  ));
306 
307  $xmlChecker = $this->getMockBuilder('ilXMLChecker')
308  ->getMock();
309 
310  $utilHelper = $this->getMockBuilder('ilCertificateUtilHelper')
311  ->getMock();
312 
313  $utilHelper->method('stripSlashes')
314  ->willReturnOnConsecutiveCalls(
315  '29,7mm',
316  '21,0mm',
317  '1cm',
318  '2cm',
319  '3cm',
320  '4cm'
321  );
322 
323  $xlstProcess = $this->getMockBuilder('ilCertificateXlstProcess')
324  ->getMock();
325 
326  $xlstProcess->method('process')
327  ->with(
328  array(
329  '/_xml' => '<html><body><xml> Some Context </xml></body></html>',
330  '/_xsl' => '<xml>Some XLS Content</xml>'
331  ),
332  array(
333  'pageheight' => '29.7mm',
334  'pagewidth' => '21.0mm',
335  'backgroundimage' => '[BACKGROUND_IMAGE]',
336  'marginbody' => '1cm 2cm 3cm 4cm'
337  )
338  )
339  ->willReturn('Something Processed');
340 
341  $language = $this->getMockBuilder('ilLanguage')
342  ->disableOriginalConstructor()
343  ->getMock();
344 
345  $certificateXlsFileLoader = $this->getMockBuilder('ilCertificateXlsFileLoader')
346  ->getMock();
347 
348  $certificateXlsFileLoader->method('getXlsCertificateContent')
349  ->willReturn('<xml>Some XLS Content</xml>');
350 
351  $xlsFoParser = new ilXlsFoParser(
352  $settings,
353  $pageFormats,
354  $xmlChecker,
355  $utilHelper,
356  $xlstProcess,
357  $language,
358  $certificateXlsFileLoader
359  );
360 
361  $output = $xlsFoParser->parse($formData);
362 
363  $this->assertEquals('Something Processed', $output);
364  }
365 }
testParseButXmlCheckerFindsAnError()
Exception
testCommasWillBeConvertedToPointInDecimalSepartor()