ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilCertificatePdfActionTest.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  $logger = $this->getMockBuilder('ilLogger')
12  ->disableOriginalConstructor()
13  ->getMock();
14 
15  $pdfGenerator = $this->getMockBuilder('ilPdfGenerator')
16  ->disableOriginalConstructor()
17  ->setMethods(array('generateCurrentActiveCertificate'))
18  ->getMock();
19 
20  $pdfGenerator->method('generateCurrentActiveCertificate')
21  ->willReturn('Something');
22 
23  $ilUtilHelper = $this->getMockBuilder('ilCertificateUtilHelper')
24  ->getMock();
25 
26  $errorHandler = $this->getMockBuilder('ilErrorHandling')
27  ->disableOriginalConstructor()
28  ->getMock();
29 
30  $pdfAction = new ilCertificatePdfAction(
31  $logger,
32  $pdfGenerator,
33  $ilUtilHelper,
34  'translatedError',
35  $errorHandler
36  );
37 
38  $result = $pdfAction->createPDF(10, 200);
39 
40  $this->assertEquals('Something', $result);
41  }
42 
43  public function testPdfDownloadAction()
44  {
45  $logger = $this->getMockBuilder('ilLogger')
46  ->disableOriginalConstructor()
47  ->getMock();
48 
49  $pdfGenerator = $this->getMockBuilder('ilPdfGenerator')
50  ->disableOriginalConstructor()
51  ->setMethods(array('generateCurrentActiveCertificate', 'generateFileName'))
52  ->getMock();
53 
54  $pdfGenerator->method('generateCurrentActiveCertificate')
55  ->willReturn('Something');
56 
57  $pdfGenerator->method('generateFileName')
58  ->willReturn('some_file_name.pdf');
59 
60  $ilUtilHelper = $this->getMockBuilder('ilCertificateUtilHelper')
61  ->getMock();
62 
63  $ilUtilHelper->method('deliverData')
64  ->with(
65  'Something',
66  'some_file_name.pdf',
67  'application/pdf'
68  );
69 
70  $errorHandler = $this->getMockBuilder('ilErrorHandling')
71  ->disableOriginalConstructor()
72  ->getMock();
73 
74  $pdfAction = new ilCertificatePdfAction(
75  $logger,
76  $pdfGenerator,
77  $ilUtilHelper,
78  'translatedError',
79  $errorHandler
80  );
81  $result = $pdfAction->downloadPdf(10, 200);
82 
83  $this->assertEquals('Something', $result);
84  }
85 
87  {
88  $logger = $this->getMockBuilder('ilLogger')
89  ->disableOriginalConstructor()
90  ->getMock();
91 
92  $pdfGenerator = $this->getMockBuilder('ilPdfGenerator')
93  ->disableOriginalConstructor()
94  ->setMethods(array('generateCurrentActiveCertificate', 'generateFileName'))
95  ->getMock();
96 
97  $pdfGenerator->method('generateCurrentActiveCertificate')
98  ->willReturn('Something');
99 
100  $pdfGenerator->method('generateFileName')
101  ->willReturn('some_file_name.pdf');
102 
103  $ilUtilHelper = $this->getMockBuilder('ilCertificateUtilHelper')
104  ->getMock();
105 
106  $ilUtilHelper->method('deliverData')
107  ->with(
108  'Something',
109  'some_file_name.pdf',
110  'application/pdf'
111  )
112  ->willThrowException(new ilRpcClientException(''));
113 
114 
115  $errorHandler = $this->getMockBuilder('ilErrorHandling')
116  ->getMock();
117 
118  $errorHandler
119  ->expects($this->once())
120  ->method('raiseError');
121 
122  $pdfAction = new ilCertificatePdfAction($logger, $pdfGenerator, $ilUtilHelper, '', $errorHandler);
123 
124  $result = $pdfAction->downloadPdf(10, 200);
125 
126  $this->assertEquals('', $result);
127  }
128 }
$result
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
Class ilRpcClientException.