ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
LinkInputTest.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;
32
34{
35 use CommonFieldRendering;
36
38
39 public function setUp(): void
40 {
41 $this->name_source = new DefNamesource();
42 }
43
44 public function testImplementsFactoryInterface(): void
45 {
46 $factory = $this->getFieldFactory();
47 $url = $factory->link("Test Label", "Test Byline");
48
49 $this->assertInstanceOf(Field\Link::class, $url);
50 }
51
52 public function testRendering(): void
53 {
54 $factory = $this->getFieldFactory();
55 $label = "Test Label";
56 $byline = "Test Byline";
57 $link = $factory->link($label, $byline)->withNameFrom($this->name_source);
58
59 $f1 = $this->getFormWrappedHtml(
60 'text-field-input',
61 'ui_link_label',
62 '<input id="id_1" type="text" name="name_0/label_1" class="c-field-text" />',
63 null,
64 'id_1',
65 null,
66 'name_0/label_1'
67 );
68 $f2 = $this->getFormWrappedHtml(
69 'url-field-input',
70 'ui_link_url',
71 '<input id="id_2" type="url" name="name_0/url_2" class="c-field-url" />',
72 null,
73 'id_2',
74 null,
75 'name_0/url_2'
76 );
77
78 $expected = $this->getFormWrappedHtml(
79 'link-field-input',
80 $label,
81 $f1 . $f2,
82 $byline
83 );
84 $this->assertEquals($expected, $this->render($link));
85 }
86
87 public function testCommonRendering(): void
88 {
89 $f = $this->getFieldFactory();
90 $label = "label";
91 $link = $f->link($label, null)->withNameFrom($this->name_source);
92
93 $this->testWithError($link);
94 $this->testWithNoByline($link);
95 $this->testWithRequired($link);
96 $this->testWithDisabled($link);
97 $this->testWithAdditionalOnloadCodeRendersId($link);
98 }
99
100 public function testProducesNullWhenNoDataExists(): void
101 {
102 $f = $this->getFieldFactory();
103 $input = $f->link("", "")
104 ->withNameFrom(new class () implements NameSource {
105 public function getNewName(): string
106 {
107 return "name";
108 }
109 public function getNewDedicatedName(): string
110 {
111 return "dedicated_name";
112 }
113 });
114 $input = $input->withInput(new class () implements InputData {
115 public function getOr($_, $default): string
116 {
117 return "";
118 }
119 public function get($_): string
120 {
121 return "";
122 }
123 public function has($name): bool
124 {
125 return true;
126 }
127
128 });
129 $result = $input->getContent();
130
131 $this->assertNull($result->value());
132 }
133}
Factory for Date Formats.
Definition: Factory.php:27
Provides common functionality for UI tests.
Definition: Base.php:337
testProducesNullWhenNoDataExists()
DefNamesource $name_source
testImplementsFactoryInterface()
Describes how Input-Elements want to interact with posted data.
Definition: InputData.php:30
Describes a source for input names.
Definition: NameSource.php:27
has(string $class_name)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
$url
Definition: shib_logout.php:68