ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ColorSelectTest.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__ . "/InputTest.php");
24 require_once(__DIR__ . "/CommonFieldRendering.php");
25 
28 use ILIAS\Data;
31 
33 {
35 
37 
38  public function setUp(): void
39  {
40  $this->name_source = new DefNamesource();
41  }
42 
43  public function testImplementsFactoryInterface(): void
44  {
45  $f = $this->getFieldFactory();
46  $cp = $f->colorSelect("label", "byline");
47  $this->assertInstanceOf(\ILIAS\UI\Component\Input\Container\Form\FormInput::class, $cp);
48  $this->assertInstanceOf(Field\ColorSelect::class, $cp);
49  }
50 
51  public function testRender(): void
52  {
53  $f = $this->getFieldFactory();
54  $label = "label";
55  $byline = "byline";
56  $cp = $f->colorSelect($label, $byline)->withNameFrom($this->name_source);
57 
58  $expected = $this->getFormWrappedHtml(
59  'color-select-field-input',
60  $label,
61  '<input id="id_1" type="color" name="name_0" value="" class="c-field-color-select"/>',
62  $byline,
63  'id_1'
64  );
65  $this->assertEquals($expected, $this->render($cp));
66  }
67 
68  public function testCommonRendering(): void
69  {
70  $f = $this->getFieldFactory();
71  $label = "label";
72  $color_select = $f->colorSelect($label, null)->withNameFrom($this->name_source);
73 
74  $this->testWithError($color_select);
75  $this->testWithNoByline($color_select);
76  $this->testWithRequired($color_select);
77  $this->testWithDisabled($color_select);
78  $this->testWithAdditionalOnloadCodeRendersId($color_select);
79  }
80 
81  public function testRenderValue(): void
82  {
83  $f = $this->getFieldFactory();
84  $label = "label";
85  $byline = "byline";
86  $value = "value_0";
87  $cp = $f->colorSelect($label, $byline)
88  ->withValue($value)
89  ->withNameFrom($this->name_source);
90 
91  $expected = $this->getFormWrappedHtml(
92  'color-select-field-input',
93  $label,
94  '<input id="id_1" type="color" name="name_0" value="value_0" class="c-field-color-select"/>',
95  $byline,
96  'id_1'
97  );
98  $this->assertEquals($expected, $this->render($cp));
99  }
100 
101  public function testValueRequired(): void
102  {
103  $f = $this->getFieldFactory();
104  $label = "label";
105  $byline = "byline";
106  $name = "name_0";
107  $cp = $f->colorSelect($label, $byline)
108  ->withNameFrom($this->name_source)
109  ->withRequired(true);
110 
111  $cp1 = $cp->withInput(new DefInputData([$name => "#FFF"]));
112  $value1 = $cp1->getContent();
113  $this->assertTrue($value1->isOk());
114 
115  $cp2 = $cp->withInput(new DefInputData([$name => "#00"]));
116  $value2 = $cp2->getContent();
117  $this->assertTrue($value2->isError());
118 
119  $cp3 = $cp->withInput(new DefInputData([$name => ""]));
120  $value2 = $cp3->getContent();
121  $this->assertTrue($value2->isError());
122  }
123 
124  public function testNullValue(): void
125  {
126  $f = $this->getFieldFactory();
127  $color_select = $f->colorSelect("label", "byline");
128  $this->expectException(\InvalidArgumentException::class);
129  $color_select->withValue(null);
130  }
131 }
DefNamesource $name_source
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