ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilStudyProgrammeValidityOfAchievedQualificationSettingsTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 {
25  private const VALID_QUALIFICATION_PERIOD_1 = 1;
26  private const VALID_QUALIFICATION_PERIOD_2 = 2;
27  private const INVALID_QUALIFICATION_PERIOD = -1;
28  private const VALID_QUALIFICATION_DATE = '2019-02-14';
29  private const VALID_RESTART_PERIOD_1 = 1;
30  private const VALID_RESTART_PERIOD_2 = 2;
31  private const INVALID_RESTART_PERIOD = -1;
32 
33  public function testSuccessfulCreate(): void
34  {
36  self::VALID_QUALIFICATION_PERIOD_1,
37  new DateTimeImmutable(self::VALID_QUALIFICATION_DATE),
38  self::VALID_RESTART_PERIOD_1,
39  true
40  );
41 
42  $this->assertEquals(self::VALID_QUALIFICATION_PERIOD_1, $obj->getQualificationPeriod());
43  $this->assertEquals(
44  self::VALID_QUALIFICATION_DATE,
45  $obj->getQualificationDate()->format('Y-m-d')
46  );
47  $this->assertEquals(self::VALID_RESTART_PERIOD_1, $obj->getRestartPeriod());
48  }
49 
51  {
52  try {
54  self::INVALID_QUALIFICATION_PERIOD,
55  new DateTimeImmutable(self::VALID_QUALIFICATION_DATE),
56  self::VALID_RESTART_PERIOD_1,
57  true
58  );
59  $this->fail();
60  } catch (InvalidArgumentException $e) {
61  $this->assertTrue(true);
62  }
63  }
64 
66  {
67  try {
69  self::VALID_QUALIFICATION_PERIOD_1,
70  new DateTimeImmutable(self::VALID_QUALIFICATION_DATE),
71  self::INVALID_RESTART_PERIOD,
72  true
73  );
74  $this->fail();
75  } catch (InvalidArgumentException $e) {
76  $this->assertTrue(true);
77  }
78  }
79 
80  public function testSuccessfulWithQualificationPeriod(): void
81  {
83  self::VALID_QUALIFICATION_PERIOD_1,
84  new DateTimeImmutable(self::VALID_QUALIFICATION_DATE),
85  self::VALID_RESTART_PERIOD_1,
86  true
87  );
88 
89  $new = $obj->withQualificationPeriod(self::VALID_QUALIFICATION_PERIOD_2);
90 
91  $this->assertEquals(self::VALID_QUALIFICATION_PERIOD_1, $obj->getQualificationPeriod());
92  $this->assertEquals(self::VALID_QUALIFICATION_PERIOD_2, $new->getQualificationPeriod());
93  }
94 
95  public function testFailWithQualificationPeriod(): void
96  {
98  self::VALID_QUALIFICATION_PERIOD_1,
99  new DateTimeImmutable(self::VALID_QUALIFICATION_DATE),
100  self::VALID_RESTART_PERIOD_1,
101  true
102  );
103 
104  try {
105  $obj->withQualificationPeriod(self::INVALID_QUALIFICATION_PERIOD);
106  $this->fail();
107  } catch (InvalidArgumentException $e) {
108  $this->assertTrue(true);
109  }
110  }
111 
112  public function testSuccessfulWithRestartPeriod(): void
113  {
115  self::VALID_QUALIFICATION_PERIOD_1,
116  new DateTimeImmutable(self::VALID_QUALIFICATION_DATE),
117  self::VALID_RESTART_PERIOD_1,
118  true
119  );
120 
121  $new = $obj->withRestartPeriod(self::VALID_RESTART_PERIOD_2);
122 
123  $this->assertEquals(self::VALID_RESTART_PERIOD_1, $obj->getRestartPeriod());
124  $this->assertEquals(self::VALID_RESTART_PERIOD_2, $new->getRestartPeriod());
125  }
126 
127  public function testFailWithRestartPeriod(): void
128  {
130  self::VALID_QUALIFICATION_PERIOD_1,
131  new DateTimeImmutable(self::VALID_QUALIFICATION_DATE),
132  self::VALID_RESTART_PERIOD_1,
133  true
134  );
135 
136  try {
137  $obj->withRestartPeriod(self::INVALID_RESTART_PERIOD);
138  $this->fail();
139  } catch (InvalidArgumentException $e) {
140  $this->assertTrue(true);
141  }
142  }
143 
144  public function testToFormInput(): void
145  {
146  $lng = $this->createMock(ilLanguage::class);
147  $df = new ILIAS\Data\Factory();
149 
151  $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
152  new ILIAS\UI\Implementation\Component\SignalGenerator(),
153  $df,
154  $refinery,
155  $lng
156  );
157 
159  self::VALID_QUALIFICATION_PERIOD_1,
160  new DateTimeImmutable(self::VALID_QUALIFICATION_DATE),
161  self::VALID_RESTART_PERIOD_1,
162  true
163  );
164 
165  $lng_consecutive_calls = [];
166  $lng->expects($this->atLeastOnce())
167  ->method('txt')
168  ->willReturnCallback(
169  function ($txt) use (&$lng_consecutive_calls) {
170  $lng_consecutive_calls[] = $txt;
171  return $txt;
172  }
173  );
174 
175  $expected_consecutive_calls = [
176  'prg_no_validity_qualification',
177  'vq_period_label',
178  'validity_qualification_period_desc',
179  'validity_qualification_period',
180  'vq_date_label',
181  'validity_qualification_date_desc',
182  'validity_qualification_date',
183  'prg_no_restart',
184  'restart_period_label',
185  'restart_period_desc',
186  'restart_recheck_label',
187  'restart_recheck_desc',
188  'restart_period',
189  'optgrp_label_validity',
190  'optgrp_label_restart',
191  'prg_validity_of_qualification'
192  ];
193 
194  $field = $obj->toFormInput(
195  $f,
196  $lng,
197  $refinery,
198  $df
199  );
200 
201  $this->assertEquals($expected_consecutive_calls, $lng_consecutive_calls);
202 
203  $date_value = $field->getInputs()['validity_qualification']->getValue()[1]['vq_date'];
204  $date = (new DateTimeImmutable($date_value))->format('Y-m-d');
205 
206  $this->assertEquals(self::VALID_QUALIFICATION_DATE, $date);
207 
208  $restart_field = $field->getInputs()['restart']->getValue()[1]['vq_restart_period'];
209 
210  $this->assertEquals(self::VALID_RESTART_PERIOD_1, $restart_field);
211  }
212 
213  public function testWithRestartRecheck(): void
214  {
216  self::VALID_QUALIFICATION_PERIOD_1,
217  new DateTimeImmutable(self::VALID_QUALIFICATION_DATE),
218  self::VALID_RESTART_PERIOD_1,
219  true
220  );
221 
222  $this->assertTrue($obj->getRestartRecheck());
223  $this->assertFalse($obj->withRestartRecheck(false)->getRestartRecheck());
224  }
225 }
Interface Observer Contains several chained tasks and infos about them.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$txt
Definition: error.php:31
global $lng
Definition: privfeed.php:31