ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilExercisePlaceHolderValuesTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
26  public function testGetPlaceholderValues(): void
27  {
28  $defaultPlaceholders = $this->getMockBuilder(ilDefaultPlaceholderValues::class)
29  ->disableOriginalConstructor()
30  ->getMock();
31 
32  $language = $this->getMockBuilder(ilLanguage::class)
33  ->disableOriginalConstructor()
34  ->getMock();
35 
36  $language->method('txt')
37  ->willReturn('Some Translation');
38 
39  $objectMock = $this->getMockBuilder(ilObject::class)
40  ->disableOriginalConstructor()
41  ->getMock();
42 
43  $objectMock->expects($this->once())
44  ->method('getTitle')
45  ->willReturn('Some Title');
46 
47  $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
48  ->getMock();
49 
50  $objectHelper->expects($this->once())
51  ->method('getInstanceByObjId')
52  ->with(200)
53  ->willReturn($objectMock);
54 
55  $lpMarksHelper = $this->getMockBuilder(ilCertificateLPMarksHelper::class)
56  ->getMock();
57 
58  $lpMarksHelper->expects($this->once())
59  ->method('lookUpMark')
60  ->willReturn('400');
61 
62  $exerciseMemberHelper = $this->getMockBuilder(ilCertificateExerciseMembersHelper::class)
63  ->getMock();
64 
65  $lpStatusHelper = $this->getMockBuilder(ilCertificateLPStatusHelper::class)
66  ->getMock();
67 
68  $lpStatusHelper->method('lookupStatusChanged')
69  ->willReturn('aaa');
70 
71  $utilHelper = $this->getMockBuilder(ilCertificateUtilHelper::class)
72  ->getMock();
73 
74  $utilHelper->expects($this->exactly(2))
75  ->method('prepareFormOutput')
76  ->willReturn('Some Formatted Output');
77 
78  $dateHelper = $this->getMockBuilder(ilCertificateDateHelper::class)
79  ->getMock();
80 
81  $dateHelper->expects($this->once())
82  ->method('formatDate')
83  ->willReturn('2018-09-10');
84 
85  $dateHelper->expects($this->once())
86  ->method('formatDateTime')
87  ->willReturn('2018-09-10 12:01:33');
88 
89 
90  $placeHolderObject = new ilExercisePlaceholderValues(
91  $defaultPlaceholders,
92  $language,
93  $objectHelper,
94  $lpMarksHelper,
95  $exerciseMemberHelper,
96  $lpStatusHelper,
97  $utilHelper,
98  $dateHelper
99  );
100 
101  $result = $placeHolderObject->getPlaceholderValues(100, 200);
102 
103  $this->assertSame(
104  [
105  'RESULT_MARK' => 'Some Formatted Output',
106  'EXERCISE_TITLE' => 'Some Formatted Output',
107  'DATE_COMPLETED' => '2018-09-10',
108  'DATETIME_COMPLETED' => '2018-09-10 12:01:33'
109  ],
110  $result
111  );
112  }
113 
114  public function testGetPlaceholderValuesForPreview(): void
115  {
116  $defaultPlaceholders = $this->getMockBuilder(ilDefaultPlaceholderValues::class)
117  ->disableOriginalConstructor()
118  ->getMock();
119 
120  $language = $this->getMockBuilder(ilLanguage::class)
121  ->disableOriginalConstructor()
122  ->getMock();
123 
124  $language->method('txt')
125  ->willReturn('Something');
126 
127  $objectMock = $this->getMockBuilder(ilObject::class)
128  ->disableOriginalConstructor()
129  ->getMock();
130 
131  $objectMock->method('getTitle')
132  ->willReturn('SomeTitle');
133 
134  $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
135  ->getMock();
136 
137  $objectHelper->method('getInstanceByObjId')
138  ->willReturn($objectMock);
139 
140  $lpMarksHelper = $this->getMockBuilder(ilCertificateLPMarksHelper::class)
141  ->getMock();
142 
143  $exerciseMemberHelper = $this->getMockBuilder(ilCertificateExerciseMembersHelper::class)
144  ->getMock();
145 
146  $lpStatusHelper = $this->getMockBuilder(ilCertificateLPStatusHelper::class)
147  ->getMock();
148 
149  $utilHelper = $this->getMockBuilder(ilCertificateUtilHelper::class)
150  ->getMock();
151 
152  $utilHelper->method('prepareFormOutput')
153  ->willReturnCallback(function ($input) {
154  return $input;
155  });
156 
157  $dateHelper = $this->getMockBuilder(ilCertificateDateHelper::class)
158  ->getMock();
159 
160  $defaultPlaceholders
161  ->expects($this->atLeastOnce())
162  ->method('getPlaceholderValuesForPreview')
163  ->willReturn(['SOME_PLACEHOLDER' => 'something']);
164 
165  $placeHolderObject = new ilExercisePlaceholderValues(
166  $defaultPlaceholders,
167  $language,
168  $objectHelper,
169  $lpMarksHelper,
170  $exerciseMemberHelper,
171  $lpStatusHelper,
172  $utilHelper,
173  $dateHelper
174  );
175 
176  $result = $placeHolderObject->getPlaceholderValuesForPreview(100, 10);
177 
178  $this->assertEquals(
179  [
180  'SOME_PLACEHOLDER' => 'something',
181  'RESULT_PASSED' => 'Something',
182  'EXERCISE_TITLE' => 'SomeTitle',
183  'RESULT_MARK' => 'Something'
184  ],
185  $result
186  );
187  }
188 }
Class ilCertificateBaseTestCase.