ILIAS  release_8 Revision v8.23
ilStudyProgrammeDeadlineSettingsTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
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\UploadLimitResolver::class),
92  new ILIAS\UI\Implementation\Component\SignalGenerator(),
93  $df,
94  $refinery,
95  $lng
96  );
97 
99  self::VALID_DEADLINE_PERIOD_1,
100  new DateTimeImmutable(self::VALID_DEADLINE_DATE)
101  );
102 
103  $lng->expects($this->atLeastOnce())
104  ->method('txt')
105  ->withConsecutive(
106  ['prg_no_deadline'],
107  ['prg_deadline_period_label'],
108  ['prg_deadline_period_desc'],
109  ['prg_deadline_period'],
110  ['prg_deadline_date_label'],
111  ['prg_deadline_date_desc'],
112  ['prg_deadline_date'],
113  ['prg_deadline_settings']
114  )
115  ->will($this->onConsecutiveCalls(
116  'prg_no_deadline',
117  'prg_deadline_period_label',
118  'prg_deadline_period_desc',
119  'prg_deadline_period',
120  'prg_deadline_date_label',
121  'prg_deadline_date_desc',
122  'prg_deadline_date',
123  'prg_deadline_settings'
124  ))
125  ;
126 
127  $field = $obj->toFormInput(
128  $f,
129  $lng,
130  $refinery,
131  $df
132  );
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 }
Class Factory.
$lng
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Refinery Factory $refinery