ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilTestPlaceHolderValuesTest.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{
9 public function testA()
10 {
11 $defaultPlaceholderValues = $this->getMockBuilder('ilDefaultPlaceholderValues')
12 ->disableOriginalConstructor()
13 ->getMock();
14
15 $language = $this->getMockBuilder('ilLanguage')
16 ->disableOriginalConstructor()
17 ->getMock();
18
19 $language->method('txt')
20 ->willReturn('Some Translation');
21
22 $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
23 ->getMock();
24
25 $testObject = $this->getMockBuilder('ilObjTest')
26 ->disableOriginalConstructor()
27 ->getMock();
28
29 $testObject->method('getActiveIdOfUser')
30 ->willReturn(999);
31
32 $testObject->method('getTestResult')
33 ->willReturn(
34 array(
35 'test' => array(
36 'passed' => true,
37 'total_max_points' => 70,
38 'total_reached_points' => 50
39 )
40 )
41 );
42
43 $testObject->method('getTestResult')
44 ->willReturn(array());
45
46
47 $testObject->method('getTitle')
48 ->willReturn(' Some Title');
49
50 $markSchema = $this->getMockBuilder('ASS_MarkSchema')
51 ->disableOriginalConstructor()
52 ->getMock();
53
54 $matchingMark = $this->getMockBuilder('ASS_Mark')
55 ->getMock();
56
57 $matchingMark->method('getShortName')
58 ->willReturn('aaa');
59
60 $matchingMark->method('getOfficialName')
61 ->willReturn('bbb');
62
63 $markSchema->method('getMatchingMark')
64 ->willReturn($matchingMark);
65
66 $testObject->method('getMarkSchema')
67 ->willReturn($markSchema);
68
69 $objectHelper->method('getInstanceByObjId')
70 ->willReturn($testObject);
71
72 $testObjectHelper = $this->getMockBuilder('ilCertificateTestObjectHelper')
73 ->getMock();
74
75 $userObjectHelper = $this->getMockBuilder('ilCertificateUserObjectHelper')
76 ->getMock();
77
78 $userObjectHelper->method('lookupFields')
79 ->willReturn(array('usr_id' => 10));
80
81 $lpStatusHelper = $this->getMockBuilder('ilCertificateLPStatusHelper')
82 ->getMock();
83
84 $lpStatusHelper->method('lookupStatusChanged')
85 ->willReturn('2018-01-12');
86
87 $utilHelper = $this->getMockBuilder('ilCertificateUtilHelper')
88 ->getMock();
89
90 $utilHelper->method('prepareFormOutput')
91 ->willReturn('Formatted Output');
92
93 $dateHelper = $this->getMockBuilder('ilCertificateDateHelper')
94 ->getMock();
95
96 $dateHelper->method('formatDate')
97 ->willReturn('2018-01-12');
98
99 $dateHelper->method('formatDateTime')
100 ->willReturn('2018-01-12 10:32:01');
101
102 $placeholdervalues = new ilTestPlaceholderValues(
103 $defaultPlaceholderValues,
104 $language,
105 $objectHelper,
106 $testObjectHelper,
107 $userObjectHelper,
108 $lpStatusHelper,
109 $utilHelper,
110 $dateHelper
111 );
112
113 $result = $placeholdervalues->getPlaceholderValues(10, 200);
114
115 $this->assertEquals(array(
116 'RESULT_PASSED' => 'Formatted Output',
117 'RESULT_POINTS' => 'Formatted Output',
118 'RESULT_PERCENT' => '71.43%',
119 'MAX_POINTS' => 'Formatted Output',
120 'RESULT_MARK_SHORT' => 'Formatted Output',
121 'RESULT_MARK_LONG' => 'Formatted Output',
122 'TEST_TITLE' => 'Formatted Output',
123 'DATE_COMPLETED' => '2018-01-12',
124 'DATETIME_COMPLETED' => '2018-01-12 10:32:01'
125
126 ), $result);
127 }
128
130 {
131 $defaultPlaceholderValues = $this->getMockBuilder('ilDefaultPlaceholderValues')
132 ->disableOriginalConstructor()
133 ->getMock();
134
135 $defaultPlaceholderValues->method('getPlaceholderValuesForPreview')
136 ->willReturn(
137 array(
138 'SOME_PLACEHOLDER' => 'something',
139 'SOME_OTHER_PLACEHOLDER' => 'something else',
140 )
141 );
142
143 $language = $this->getMockBuilder('ilLanguage')
144 ->disableOriginalConstructor()
145 ->getMock();
146
147 $language->method('txt')
148 ->willReturn('Something');
149
150 $objectMock = $this->getMockBuilder('ilObject')
151 ->disableOriginalConstructor()
152 ->getMock();
153
154 $objectMock->method('getTitle')
155 ->willReturn('SomeTitle');
156
157 $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
158 ->getMock();
159
160 $objectHelper->method('getInstanceByObjId')
161 ->willReturn($objectMock);
162
163 $testObjectHelper = $this->getMockBuilder('ilCertificateTestObjectHelper')
164 ->getMock();
165
166 $userObjectHelper = $this->getMockBuilder('ilCertificateUserObjectHelper')
167 ->getMock();
168
169 $lpStatusHelper = $this->getMockBuilder('ilCertificateLPStatusHelper')
170 ->getMock();
171
172 $utilHelper = $this->getMockBuilder('ilCertificateUtilHelper')
173 ->getMock();
174
175 $utilHelper->method('prepareFormOutput')
176 ->willReturnCallback(function ($input) {
177 return $input;
178 });
179
180 $dateHelper = $this->getMockBuilder('ilCertificateDateHelper')
181 ->getMock();
182
183 $placeholdervalues = new ilTestPlaceholderValues(
184 $defaultPlaceholderValues,
185 $language,
186 $objectHelper,
187 $testObjectHelper,
188 $userObjectHelper,
189 $lpStatusHelper,
190 $utilHelper,
191 $dateHelper
192 );
193
194 $result = $placeholdervalues->getPlaceholderValuesForPreview(100, 10);
195
196 $this->assertEquals(
197 array(
198 'SOME_PLACEHOLDER' => 'something',
199 'SOME_OTHER_PLACEHOLDER' => 'something else',
200 'RESULT_PASSED' => 'Something',
201 'RESULT_POINTS' => 'Something',
202 'RESULT_PERCENT' => 'Something',
203 'MAX_POINTS' => 'Something',
204 'RESULT_MARK_SHORT' => 'Something',
205 'RESULT_MARK_LONG' => 'Something',
206 'TEST_TITLE' => 'SomeTitle'
207 ),
208 $result
209 );
210 }
211}
$result
An exception for terminatinating execution or to throw for unit testing.