ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
RatingInputTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once(__DIR__ . "/../../../../../../../vendor/composer/vendor/autoload.php");
22 require_once(__DIR__ . "/../../../Base.php");
23 require_once(__DIR__ . "/CommonFieldRendering.php");
24 
31 
33 {
35 
37 
38  public function setUp(): void
39  {
40  $this->name_source = new DefNamesource();
41  }
42 
43  protected function buildRating(): \ILIAS\UI\Component\Input\Container\Form\FormInput
44  {
45  $f = $this->getFieldFactory();
46  $label = "label";
47  $byline = "byline";
48  return $f
49  ->rating($label, $byline)
50  ->withNameFrom($this->name_source);
51  }
52 
53  public function testRatingImplementsFactoryInterface(): void
54  {
55  $f = $this->getFieldFactory();
56  $rating = $f->rating("label", "byline");
57  $this->assertInstanceOf(\ILIAS\UI\Component\Input\Container\Form\FormInput::class, $rating);
58  $this->assertInstanceOf(Field\Rating::class, $rating);
59  }
60 
61  public function testRatingRenderBasic(): void
62  {
63  $rating = $this->buildRating();
64  $expected = $this->getFormWrappedHtml(
65  'rating-field-input',
66  'label',
67  '
68  <fieldset class="input-group il-input-rating">
69  <legend class="il-input-rating__text" id="id_1_desc"></legend>
70  <div class="il-input-rating__stars" role="radiogroup">
71  <div class="il-input-rating__options">
72  <input aria-describedby="id_1_desc" type="radio" id="id_1-5" name="name_0" value="5" class="il-input-rating-scaleoption" />
73  <label class="glyphicon-star il-input-rating-star" for="id_1-5" aria-label="5stars"></label>
74 
75  <input aria-describedby="id_1_desc" type="radio" id="id_1-4" name="name_0" value="4" class="il-input-rating-scaleoption" />
76  <label class="glyphicon-star il-input-rating-star" for="id_1-4" aria-label="4stars"></label>
77 
78  <input aria-describedby="id_1_desc" type="radio" id="id_1-3" name="name_0" value="3" class="il-input-rating-scaleoption" />
79  <label class="glyphicon-star il-input-rating-star" for="id_1-3" aria-label="3stars"></label>
80 
81  <input aria-describedby="id_1_desc" type="radio" id="id_1-2" name="name_0" value="2" class="il-input-rating-scaleoption" />
82  <label class="glyphicon-star il-input-rating-star" for="id_1-2" aria-label="2stars"></label>
83 
84  <input aria-describedby="id_1_desc" type="radio" id="id_1-1" name="name_0" value="1" class="il-input-rating-scaleoption" />
85  <label class="glyphicon-star il-input-rating-star" for="id_1-1" aria-label="1stars"></label>
86  </div>
87  <div class="il-input-rating__none">
88  <label for="id_1-0" aria-label="reset_stars">reset_stars</label>
89  <input aria-describedby="id_1_desc" type="radio" id="id_1-0" name="name_0" value="0" checked="checked"/>
90  </div>
91  </div>
92  </fieldset>
93  ',
94  'byline',
95  null
96  );
97  $this->assertEquals($expected, $this->render($rating));
98  }
99 
100  public function testRatingRenderFull(): void
101  {
102  $rating = $this->buildRating()
103  ->withAdditionalText('question text')
104  ->withDisabled(true)
105  ->withValue(FiveStarRatingScale::GOOD)
106  ->withCurrentAverage(3);
107 
108  $expected = $this->brutallyTrimHTML(
109  '<fieldset class="c-input" data-il-ui-component="rating-field-input" data-il-ui-input-name="name_0" disabled="disabled" tabindex="0">
110  <label>label</label>
111  <div class="c-input__field">
112 
113  <fieldset class="input-group il-input-rating disabled">
114  <legend class="il-input-rating__text" id="id_1_desc">question text</legend>
115 
116  <div class="il-input-rating__stars" role="radiogroup">
117 
118  <div class="il-input-rating__options" title="rating_average">
119 
120  <div class="il-input-rating__average">
121  <div class="il-input-rating__average_value" style="width:60%;"></div>
122  </div>
123 
124  <input aria-describedby="id_1_desc" type="radio" id="id_1-5" name="name_0" value="5" class="il-input-rating-scaleoption" disabled="disabled"/>
125  <label class="glyphicon-star il-input-rating-star" for="id_1-5" aria-label="5stars"></label>
126 
127  <input aria-describedby="id_1_desc" type="radio" id="id_1-4" name="name_0" value="4" class="il-input-rating-scaleoption" disabled="disabled" checked="checked"/>
128  <label class="glyphicon-star il-input-rating-star" for="id_1-4" aria-label="4stars"></label>
129 
130  <input aria-describedby="id_1_desc" type="radio" id="id_1-3" name="name_0" value="3" class="il-input-rating-scaleoption" disabled="disabled"/>
131  <label class="glyphicon-star il-input-rating-star" for="id_1-3" aria-label="3stars"></label>
132 
133  <input aria-describedby="id_1_desc" type="radio" id="id_1-2" name="name_0" value="2" class="il-input-rating-scaleoption" disabled="disabled"/>
134  <label class="glyphicon-star il-input-rating-star" for="id_1-2" aria-label="2stars"></label>
135 
136  <input aria-describedby="id_1_desc" type="radio" id="id_1-1" name="name_0" value="1" class="il-input-rating-scaleoption" disabled="disabled"/>
137  <label class="glyphicon-star il-input-rating-star" for="id_1-1" aria-label="1stars"></label>
138  </div>
139 
140  <div class="il-input-rating__none">
141  <label for="id_1-0" aria-label="reset_stars">reset_stars</label>
142  <input aria-describedby="id_1_desc" type="radio" id="id_1-0" name="name_0" value="0" />
143  </div>
144 
145  </div>
146  </fieldset>
147 
148  </div>
149  <div class="c-input__help-byline">byline</div>
150  </fieldset>'
151  );
152 
153  $this->assertEquals($expected, $this->render($rating));
154  }
155 
156  public function testCommonRendering(): void
157  {
158  $f = $this->getFieldFactory();
159  $rating = $f->rating("label", null)->withNameFrom($this->name_source);
160 
161  $this->testWithError($rating);
162  $this->testWithNoByline($rating);
163  $this->testWithRequired($rating);
164  $this->testWithDisabled($rating);
165  $this->testWithAdditionalOnloadCodeRendersId($rating);
166  }
167 
168  public function testRatingAverage(): void
169  {
170  $rating = $this->buildRating();
171  $this->assertNull($rating->getCurrentAverage());
172  $this->assertEquals(2.1, $rating->withCurrentAverage(2.1)->getCurrentAverage());
173  }
174 
175  public function testRatingAverageException(): void
176  {
177  $this->expectException(\InvalidArgumentException::class);
178  $rating = $this->buildRating()->withCurrentAverage(7);
179  }
180 
181 
182 }
FiveStarRatingScale
This is the scale for the Rating Input.
testRatingImplementsFactoryInterface()
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...
Definition: Checkbox.php:21
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This describes inputs that can be used in forms.
Definition: FormInput.php:32
DefNamesource $name_source