ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ColorSelectTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once(__DIR__ . "/../../../../../../../vendor/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../../Base.php");
23require_once(__DIR__ . "/InputTest.php");
24require_once(__DIR__ . "/CommonFieldRendering.php");
25
28use ILIAS\Data;
29use ILIAS\Refinery\Factory as Refinery;
31
33{
34 use CommonFieldRendering;
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
Builds data types.
Definition: Factory.php:36
Definition: UI.php:24
Provides common functionality for UI tests.
Definition: Base.php:337
This describes commonalities between all inputs.
Definition: Input.php:47
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.