ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilCoursePlaceholderDescriptionTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Course\Certificate;
22 
23 use ilLanguage;
24 use ilTemplate;
29 
33 class ilCoursePlaceholderDescriptionTest extends TestCase
34 {
35  public function testPlaceholderGetHtmlDescription(): void
36  {
37  $languageMock = $this->getMockBuilder(ilLanguage::class)
38  ->disableOriginalConstructor()
39  ->onlyMethods(['txt', 'loadLanguageModule'])
40  ->getMock();
41 
42  $templateMock = $this->getMockBuilder(ilTemplate::class)
43  ->disableOriginalConstructor()
44  ->getMock();
45 
46  $templateMock->method('get')
47  ->willReturn('');
48 
49  $userDefinePlaceholderMock = $this->getMockBuilder(ilUserDefinedFieldsPlaceholderDescription::class)
50  ->disableOriginalConstructor()
51  ->getMock();
52 
53  $userDefinePlaceholderMock->method('createPlaceholderHtmlDescription')
54  ->willReturn('');
55 
56  $userDefinePlaceholderMock->method('getPlaceholderDescriptions')
57  ->willReturn([]);
58 
59  $customUserPlaceholderObject = $this->getMockBuilder(ilObjectCustomUserFieldsPlaceholderDescription::class)
60  ->disableOriginalConstructor()
61  ->getMock();
62 
63  $customUserPlaceholderObject->method('getPlaceholderDescriptions')
64  ->willReturn([
65  '+SOMETHING' => 'SOMEWHAT',
66  '+SOMETHING_ELSE' => 'ANYTHING'
67  ]);
68 
69  $customUserPlaceholderObject->method('createPlaceholderHtmlDescription')
70  ->willReturn('');
71 
72  $placeholderDescriptionObject = new CoursePlaceholderDescription(200, null, $languageMock, $userDefinePlaceholderMock, $customUserPlaceholderObject);
73 
74  $html = $placeholderDescriptionObject->createPlaceholderHtmlDescription($templateMock);
75 
76  $this->assertSame('', $html);
77  }
78 
79  public function testPlaceholderDescriptions(): void
80  {
81  $languageMock = $this->getMockBuilder(ilLanguage::class)
82  ->disableOriginalConstructor()
83  ->onlyMethods(['txt'])
84  ->getMock();
85 
86  $languageMock->expects($this->exactly(3))
87  ->method('txt')
88  ->willReturn('Something translated');
89 
90  $defaultPlaceholder = $this->getMockBuilder(ilDefaultPlaceholderDescription::class)
91  ->disableOriginalConstructor()
92  ->getMock();
93 
94  $defaultPlaceholder->method('getPlaceholderDescriptions')
95  ->willReturn(
96  [
97  'SOMETHING' => 'SOMEWHAT',
98  'SOMETHING_ELSE' => 'ANYTHING'
99  ]
100  );
101 
102  $customUserPlaceholderObject = $this->getMockBuilder(ilObjectCustomUserFieldsPlaceholderDescription::class)
103  ->disableOriginalConstructor()
104  ->getMock();
105 
106  $customUserPlaceholderObject->method('getPlaceholderDescriptions')
107  ->willReturn(
108  [
109  '+SOMETHING' => 'SOMEWHAT',
110  '+SOMETHING_ELSE' => 'ANYTHING'
111  ]
112  );
113 
114  $placeholderDescriptionObject = new CoursePlaceholderDescription(200, $defaultPlaceholder, $languageMock, null, $customUserPlaceholderObject);
115 
116  $placeHolders = $placeholderDescriptionObject->getPlaceholderDescriptions();
117 
118  $this->assertEquals(
119  [
120  'COURSE_TITLE' => 'Something translated',
121  'SOMETHING' => 'SOMEWHAT',
122  'SOMETHING_ELSE' => 'ANYTHING',
123  '+SOMETHING' => 'SOMEWHAT',
124  '+SOMETHING_ELSE' => 'ANYTHING',
125  'DATE_COMPLETED' => 'Something translated',
126  'DATETIME_COMPLETED' => 'Something translated'
127  ],
128  $placeHolders
129  );
130  }
131 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null