ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilStudyProgrammeAssessmentSettingsTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 
27 {
28  private const VALID_POINTS_1 = 22;
29  private const VALID_POINTS_2 = 44;
30  private const INVALID_POINTS = -11;
31  private const VALID_STATUS_1 = 20;
32  private const VALID_STATUS_2 = 30;
33  private const INVALID_STATUS = -1;
34 
35  public function testSuccessfulCreate(): void
36  {
37  $obj = new ilStudyProgrammeAssessmentSettings(self::VALID_POINTS_1, self::VALID_STATUS_1);
38 
39  $this->assertEquals(self::VALID_POINTS_1, $obj->getPoints());
40  $this->assertEquals(self::VALID_STATUS_1, $obj->getStatus());
41  }
42 
43  public function testFailCreateWithInvalidPoints(): void
44  {
45  try {
46  new ilStudyProgrammeAssessmentSettings(self::INVALID_POINTS, self::VALID_STATUS_1);
47  $this->fail();
48  } catch (InvalidArgumentException $e) {
49  $this->assertTrue(true);
50  }
51  }
52 
53  public function testFailCreateWithInvalidStatus(): void
54  {
55  try {
56  new ilStudyProgrammeAssessmentSettings(self::VALID_POINTS_1, self::INVALID_STATUS);
57  $this->fail();
58  } catch (InvalidArgumentException $e) {
59  $this->assertTrue(true);
60  }
61  }
62 
64  {
65  try {
66  new ilStudyProgrammeAssessmentSettings(self::INVALID_POINTS, self::INVALID_STATUS);
67  $this->fail();
68  } catch (InvalidArgumentException $e) {
69  $this->assertTrue(true);
70  }
71  }
72 
73  public function testSuccessfulWithPoints(): void
74  {
75  $obj = new ilStudyProgrammeAssessmentSettings(self::VALID_POINTS_1, self::VALID_STATUS_1);
76 
77  $new = $obj->withPoints(self::VALID_POINTS_2);
78 
79  $this->assertEquals(self::VALID_POINTS_1, $obj->getPoints());
80  $this->assertEquals(self::VALID_POINTS_2, $new->getPoints());
81  }
82 
83  public function testFailWithPoints(): void
84  {
85  $obj = new ilStudyProgrammeAssessmentSettings(self::VALID_POINTS_1, self::VALID_STATUS_1);
86 
87  try {
88  $obj->withPoints(self::INVALID_POINTS);
89  $this->fail();
90  } catch (InvalidArgumentException $e) {
91  $this->assertTrue(true);
92  }
93  }
94 
95  public function testSuccessfulWithStatus(): void
96  {
97  $obj = new ilStudyProgrammeAssessmentSettings(self::VALID_POINTS_1, self::VALID_STATUS_1);
98 
99  $new = $obj->withStatus(self::VALID_STATUS_2);
100 
101  $this->assertEquals(self::VALID_STATUS_1, $obj->getStatus());
102  $this->assertEquals(self::VALID_STATUS_2, $new->getStatus());
103  }
104 
105  public function testFailWithStatus(): void
106  {
107  $obj = new ilStudyProgrammeAssessmentSettings(self::VALID_POINTS_1, self::VALID_STATUS_1);
108 
109  try {
110  $obj->withStatus(self::INVALID_STATUS);
111  $this->fail();
112  } catch (InvalidArgumentException $e) {
113  $this->assertTrue(true);
114  }
115  }
116 
117  public function testToFormInput(): void
118  {
119  $lng = $this->createMock(ilLanguage::class);
120  $df = new ILIAS\Data\Factory();
122 
124  $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
125  new ILIAS\UI\Implementation\Component\SignalGenerator(),
126  $df,
127  $refinery,
128  $lng
129  );
130 
131  $obj = new ilStudyProgrammeAssessmentSettings(self::VALID_POINTS_1, self::VALID_STATUS_1);
132 
133  $lng_consecutive_calls = [];
134  $lng->expects($this->atLeastOnce())
135  ->method('txt')
136  ->willReturnCallback(
137  function ($txt) use (&$lng_consecutive_calls) {
138  $lng_consecutive_calls[] = $txt;
139  return $txt;
140  }
141  );
142 
143  $expected_consecutive_calls = [
144  'prg_points',
145  'prg_points_byline',
146  'prg_status',
147  'prg_status_draft',
148  'prg_status_active',
149  'prg_status_outdated',
150  'prg_status_byline',
151  'prg_assessment'
152  ];
153 
154  $field = $obj->toFormInput(
155  $f,
156  $lng,
157  $refinery
158  );
159 
160  $this->assertEquals($expected_consecutive_calls, $lng_consecutive_calls);
161 
162  $this->assertInstanceOf(
163  Section::class,
164  $field
165  );
166 
167  $inputs = $field->getInputs();
168 
169  $this->assertInstanceOf(
170  Numeric::class,
171  $inputs['points']
172  );
173 
174  $this->assertInstanceOf(
175  Select::class,
176  $inputs['status']
177  );
178  }
179 }
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