ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilStudyProgrammeDeadlineSettingsTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23use PHPUnit\Framework\TestCase;
24
26{
27 private const VALID_DEADLINE_PERIOD_1 = 11;
28 private const VALID_DEADLINE_PERIOD_2 = 22;
29 private const INVALID_DEADLINE_PERIOD = -1;
30 private const VALID_DEADLINE_DATE = '2019-02-14';
31
32 public function testSuccessfulCreate(): void
33 {
35 self::VALID_DEADLINE_PERIOD_1,
36 new DateTimeImmutable(self::VALID_DEADLINE_DATE)
37 );
38
39 $this->assertEquals(self::VALID_DEADLINE_PERIOD_1, $obj->getDeadlinePeriod());
40 $this->assertEquals(self::VALID_DEADLINE_DATE, $obj->getDeadlineDate()->format('Y-m-d'));
41 }
42
44 {
45 try {
47 self::INVALID_DEADLINE_PERIOD,
48 new DateTimeImmutable(self::VALID_DEADLINE_DATE)
49 );
50 $this->fail();
51 } catch (InvalidArgumentException $e) {
52 $this->assertTrue(true);
53 }
54 }
55
56 public function testSuccessfulWithDeadlinePeriod(): void
57 {
59 self::VALID_DEADLINE_PERIOD_1,
60 new DateTimeImmutable(self::VALID_DEADLINE_DATE)
61 );
62
63 $new = $obj->withDeadlinePeriod(self::VALID_DEADLINE_PERIOD_2);
64
65 $this->assertEquals(self::VALID_DEADLINE_PERIOD_1, $obj->getDeadlinePeriod());
66 $this->assertEquals(self::VALID_DEADLINE_PERIOD_2, $new->getDeadlinePeriod());
67 }
68
69 public function testFailWithDeadlinePeriod(): void
70 {
72 self::VALID_DEADLINE_PERIOD_1,
73 new DateTimeImmutable(self::VALID_DEADLINE_DATE)
74 );
75
76 try {
77 $obj->withDeadlinePeriod(self::INVALID_DEADLINE_PERIOD);
78 $this->fail();
79 } catch (InvalidArgumentException $e) {
80 $this->assertTrue(true);
81 }
82 }
83
84 public function testToFormInput(): void
85 {
86 $lng = $this->createMock(ilLanguage::class);
87 $df = new ILIAS\Data\Factory();
89
91 $this->createMock(\ILIAS\UI\Implementation\Component\Input\Field\Node\Factory::class),
92 $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
93 new ILIAS\UI\Implementation\Component\SignalGenerator(),
94 $df,
96 $lng
97 );
98
100 self::VALID_DEADLINE_PERIOD_1,
101 new DateTimeImmutable(self::VALID_DEADLINE_DATE)
102 );
103
104 $lng_consecutive_calls = [];
105 $lng->expects($this->atLeastOnce())
106 ->method('txt')
107 ->willReturnCallback(
108 function ($txt) use (&$lng_consecutive_calls) {
109 $lng_consecutive_calls[] = $txt;
110 return $txt;
111 }
112 );
113
114 $expected_consecutive_calls = [
115 'prg_no_deadline',
116 'prg_deadline_period_label',
117 'prg_deadline_period_desc',
118 'prg_deadline_period',
119 'prg_deadline_date_label',
120 'prg_deadline_date_desc',
121 'prg_deadline_date',
122 'prg_deadline_settings'
123 ];
124
125 $field = $obj->toFormInput(
126 $f,
127 $lng,
128 $refinery,
129 $df
130 );
131
132 $this->assertEquals($expected_consecutive_calls, $lng_consecutive_calls);
133
134 $switchable_group = $field->getInputs()['prg_deadline'];
135 $this->assertInstanceOf(
136 SwitchableGroup::class,
137 $switchable_group
138 );
139
140 $date_value = $switchable_group->getValue()[1]['deadline_date'];
141 $date = (new DateTimeImmutable($date_value))->format('Y-m-d');
142 $this->assertEquals(self::VALID_DEADLINE_DATE, $date);
143
144 $inputs = $switchable_group->getInputs();
145 foreach ($inputs as $input) {
146 $this->assertInstanceOf(
147 Group::class,
148 $input
149 );
150 }
151 }
152}
Factory for Date Formats.
Definition: Factory.php:27
Builds data types.
Definition: Factory.php:36
$txt
Definition: error.php:31
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:31