ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ilStudyProgrammeAssessmentSettingsTest.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2019 Daniel Weise <daniel.weise@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
5 declare(strict_types=1);
6 
8 
10 {
11  const VALID_POINTS_1 = 22;
12  const VALID_POINTS_2 = 44;
13  const INVALID_POINTS = -11;
14  const VALID_STATUS_1 = 20;
15  const VALID_STATUS_2 = 30;
16  const INVALID_STATUS = -1;
17 
18  public function testSuccessfulCreate() : void
19  {
20  $obj = new ilStudyProgrammeAssessmentSettings(self::VALID_POINTS_1, self::VALID_STATUS_1);
21 
22  $this->assertEquals(self::VALID_POINTS_1, $obj->getPoints());
23  $this->assertEquals(self::VALID_STATUS_1, $obj->getStatus());
24  }
25 
26  public function testFailCreateWithInvalidPoints() : void
27  {
28  try {
29  new ilStudyProgrammeAssessmentSettings(self::INVALID_POINTS, self::VALID_STATUS_1);
30  $this->assertTrue(false);
31  } catch (InvalidArgumentException $e) {
32  $this->assertTrue(true);
33  }
34  }
35 
36  public function testFailCreateWithInvalidStatus() : void
37  {
38  try {
39  new ilStudyProgrammeAssessmentSettings(self::VALID_POINTS_1, self::INVALID_STATUS);
40  $this->assertTrue(false);
41  } catch (InvalidArgumentException $e) {
42  $this->assertTrue(true);
43  }
44  }
45 
47  {
48  try {
49  new ilStudyProgrammeAssessmentSettings(self::INVALID_POINTS, self::INVALID_STATUS);
50  $this->assertTrue(false);
51  } catch (InvalidArgumentException $e) {
52  $this->assertTrue(true);
53  }
54  }
55 
56  public function testSuccessfulWithPoints() : void
57  {
58  $obj = new ilStudyProgrammeAssessmentSettings(self::VALID_POINTS_1, self::VALID_STATUS_1);
59 
60  $new = $obj->withPoints(self::VALID_POINTS_2);
61 
62  $this->assertEquals(self::VALID_POINTS_1, $obj->getPoints());
63  $this->assertEquals(self::VALID_POINTS_2, $new->getPoints());
64  }
65 
66  public function testFailWithPoints() : void
67  {
68  $obj = new ilStudyProgrammeAssessmentSettings(self::VALID_POINTS_1, self::VALID_STATUS_1);
69 
70  try {
71  $obj->withPoints(self::INVALID_POINTS);
72  $this->assertTrue(false);
73  } catch (InvalidArgumentException $e) {
74  $this->assertTrue(true);
75  }
76  }
77 
78  public function testSuccessfulWithStatus() : void
79  {
80  $obj = new ilStudyProgrammeAssessmentSettings(self::VALID_POINTS_1, self::VALID_STATUS_1);
81 
82  $new = $obj->withStatus(self::VALID_STATUS_2);
83 
84  $this->assertEquals(self::VALID_STATUS_1, $obj->getStatus());
85  $this->assertEquals(self::VALID_STATUS_2, $new->getStatus());
86  }
87 
88  public function testFailWithStatus() : void
89  {
90  $obj = new ilStudyProgrammeAssessmentSettings(self::VALID_POINTS_1, self::VALID_STATUS_1);
91 
92  try {
93  $obj->withStatus(self::INVALID_STATUS);
94  $this->assertTrue(false);
95  } catch (InvalidArgumentException $e) {
96  $this->assertTrue(true);
97  }
98  }
99 
100  public function testToFormInput() : void
101  {
102  $lng = $this->createMock(ilLanguage::class);
103  $df = new ILIAS\Data\Factory();
104  $refinery = new ILIAS\Refinery\Factory($df, $lng);
105 
107  new ILIAS\UI\Implementation\Component\SignalGenerator(),
108  $df,
109  $refinery,
110  $lng
111  );
112 
113  $obj = new ilStudyProgrammeAssessmentSettings(self::VALID_POINTS_1, self::VALID_STATUS_1);
114 
115  $lng->expects($this->atLeastOnce())
116  ->method('txt')
117  ->withConsecutive(
118  ['prg_points'],
119  ['prg_points_byline'],
120  ['prg_status'],
121  ['prg_status_draft'],
122  ['prg_status_active'],
123  ['prg_status_outdated'],
124  ['prg_status_byline'],
125  ['prg_assessment']
126  )
127  ->will($this->onConsecutiveCalls(
128  'prg_points',
129  'prg_points_byline',
130  'prg_status',
131  'prg_status_draft',
132  'prg_status_active',
133  'prg_status_outdated',
134  'prg_status_byline',
135  'prg_assessment'
136  ))
137  ;
138 
139  $field = $obj->toFormInput(
140  $f,
141  $lng,
142  $refinery
143  );
144 
145  $this->assertInstanceOf(
146  'ILIAS\UI\Implementation\Component\Input\Field\Section',
147  $field
148  );
149 
150  $inputs = $field->getInputs();
151 
152  $this->assertInstanceOf(
153  'ILIAS\UI\Implementation\Component\Input\Field\Numeric',
154  $inputs['points']
155  );
156 
157  $this->assertInstanceOf(
158  'ILIAS\UI\Implementation\Component\Input\Field\Select',
159  $inputs['status']
160  );
161  }
162 }
Class Factory.
Class ChatMainBarProvider .
$lng
Builds data types.
Definition: Factory.php:19