ILIAS  release_7 Revision v7.30-3-g800a261c036
ilCoursePlaceholderValuesTest.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 testGetPlaceholderValues()
10 {
11 $customUserFieldsPlaceholderValues = $this->getMockBuilder("ilObjectCustomUserFieldsPlaceholderValues")
12 ->disableOriginalConstructor()
13 ->getMock();
14
15 $customUserFieldsPlaceholderValues->method('getPlaceholderValues')
16 ->willReturn(array());
17
18 $defaultPlaceholderValues = $this->getMockBuilder('ilDefaultPlaceholderValues')
19 ->disableOriginalConstructor()
20 ->getMock();
21
22 $defaultPlaceholderValues->method('getPlaceholderValues')
23 ->willReturn(array());
24
25 $language = $this->getMockBuilder('ilLanguage')
26 ->disableOriginalConstructor()
27 ->getMock();
28
29 $language->method('txt')
30 ->willReturn('Something');
31
32 $objectMock = $this->getMockBuilder('ilObject')
33 ->disableOriginalConstructor()
34 ->getMock();
35
36 $objectMock->method('getTitle')
37 ->willReturn('Some Title');
38
39 $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
40 ->getMock();
41
42 $objectHelper->method('getInstanceByObjId')
43 ->willReturn($objectMock);
44
45 $participantsHelper = $this->getMockBuilder('ilCertificateParticipantsHelper')
46 ->getMock();
47
48 $participantsHelper->method('getDateTimeOfPassed')
49 ->willReturn('2018-09-10');
50
51 $ilUtilHelper = $this->getMockBuilder('ilCertificateUtilHelper')
52 ->getMock();
53
54 $ilUtilHelper->method('prepareFormOutput')
55 ->willReturn('Some Title');
56
57 $ilDateHelper = $this->getMockBuilder('ilCertificateDateHelper')
58 ->getMock();
59
60 $ilDateHelper->method('formatDate')
61 ->willReturn('2018-09-10');
62
63 $ilDateHelper->method('formatDateTime')
64 ->willReturn('2018-09-10 10:32:00');
65
66 $valuesObject = new ilCoursePlaceholderValues(
67 $customUserFieldsPlaceholderValues,
68 $defaultPlaceholderValues,
69 $language,
70 $objectHelper,
71 $participantsHelper,
72 $ilUtilHelper,
73 $ilDateHelper
74 );
75
76 $placeholderValues = $valuesObject->getPlaceholderValues(100, 200);
77
78 $this->assertEquals(
79 array(
80 'COURSE_TITLE' => 'Some Title',
81 'DATE_COMPLETED' => '2018-09-10',
82 'DATETIME_COMPLETED' => '2018-09-10 10:32:00'
83 ),
84 $placeholderValues
85 );
86 }
87
89 {
90 $customUserFieldsPlaceholderValues = $this->getMockBuilder("ilObjectCustomUserFieldsPlaceholderValues")
91 ->disableOriginalConstructor()
92 ->getMock();
93
94 $customUserFieldsPlaceholderValues->method('getPlaceholderValuesForPreview')
95 ->willReturn(
96 array(
97 'SOME_PLACEHOLDER' => 'ANYTHING',
98 'SOME_OTHER_PLACEHOLDER' => '2018-09-10',
99 )
100 );
101
102 $defaultPlaceholderValues = $this->getMockBuilder('ilDefaultPlaceholderValues')
103 ->disableOriginalConstructor()
104 ->getMock();
105
106 $defaultPlaceholderValues->method('getPlaceholderValuesForPreview')
107 ->willReturn(
108 array(
109 'SOME_PLACEHOLDER' => 'ANYTHING',
110 'SOME_OTHER_PLACEHOLDER' => '2018-09-10',
111 )
112 );
113
114 $language = $this->getMockBuilder('ilLanguage')
115 ->disableOriginalConstructor()
116 ->getMock();
117
118 $language->method('txt')
119 ->willReturn('Something');
120
121 $objectMock = $this->getMockBuilder('ilObject')
122 ->disableOriginalConstructor()
123 ->getMock();
124
125 $objectMock->method('getTitle')
126 ->willReturn('SomeTitle');
127
128 $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
129 ->getMock();
130
131 $objectHelper->method('getInstanceByObjId')
132 ->willReturn($objectMock);
133
134 $participantsHelper = $this->getMockBuilder('ilCertificateParticipantsHelper')
135 ->getMock();
136
137 $utilHelper = $this->getMockBuilder('ilCertificateUtilHelper')
138 ->getMock();
139
140 $utilHelper->method('prepareFormOutput')
141 ->willReturnCallback(function ($input) {
142 return $input;
143 });
144
145 $valuesObject = new ilCoursePlaceholderValues(
146 $customUserFieldsPlaceholderValues,
147 $defaultPlaceholderValues,
148 $language,
149 $objectHelper,
150 $participantsHelper,
151 $utilHelper
152 );
153
154 $placeholderValues = $valuesObject->getPlaceholderValuesForPreview(100, 10);
155
156 $this->assertEquals(
157 array(
158 'SOME_PLACEHOLDER' => 'ANYTHING',
159 'SOME_OTHER_PLACEHOLDER' => '2018-09-10',
160 'COURSE_TITLE' => 'SomeTitle'
161 ),
162 $placeholderValues
163 );
164 }
165}
An exception for terminatinating execution or to throw for unit testing.
Class ilCertificateBaseTestCase.