ILIAS  release_8 Revision v8.24
LinkInputTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once(__DIR__ . "/../../../../../libs/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../../Base.php");
23require_once(__DIR__ . "/InputTest.php");
24
27use ILIAS\Data;
31
33{
35
36 public function setUp(): void
37 {
38 $this->name_source = new DefNamesource();
39 }
40
41 protected function buildFactory(): Factory
42 {
43 $data_factory = new Data\Factory();
44 $language = $this->createMock(ilLanguage::class);
45 $language->method("txt")
46 ->will($this->returnArgument(0));
47
48 return new Factory(
49 $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
50 new SignalGenerator(),
51 $data_factory,
52 new ILIAS\Refinery\Factory($data_factory, $language),
53 $language
54 );
55 }
56
57 public function testImplementsFactoryInterface(): void
58 {
59 $factory = $this->buildFactory();
60 $url = $factory->link("Test Label", "Test Byline");
61
62 $this->assertInstanceOf(Field\Link::class, $url);
63 }
64
65 public function testRendering(): void
66 {
67 $factory = $this->buildFactory();
68 $renderer = $this->getDefaultRenderer();
69 $label = "Test Label";
70 $byline = "Test Byline";
71 $url = $factory->link($label, $byline)->withNameFrom($this->name_source);
72 $html = $this->normalizeHTML($renderer->render($url));
73
74 $expected = '
75 <div class="form-group row">
76 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">ui_link_label</label>
77 <div class="col-sm-8 col-md-9 col-lg-10">
78 <input id="id_1" type="text" name="name_0/label_1" class="form-control form-control-sm" />
79 </div>
80 </div>
81 <div class="form-group row">
82 <label for="id_2" class="control-label col-sm-4 col-md-3 col-lg-2">ui_link_url</label>
83 <div class="col-sm-8 col-md-9 col-lg-10">
84 <input id="id_2" type="url" name="name_0/url_2" class="form-control form-control-sm" />
85 </div>
86 </div>';
87
88 $this->assertEquals(
89 $this->brutallyTrimHTML($expected),
90 $this->brutallyTrimHTML($html)
91 );
92 }
93
94 public function testProducesNullWhenNoDataExists(): void
95 {
96 $f = $this->buildFactory();
97 $input = $f->link("", "")
98 ->withNameFrom(new class () implements NameSource {
99 public function getNewName(): string
100 {
101 return "name";
102 }
103 public function getNewDedicatedName(): string
104 {
105 return "dedicated_name";
106 }
107 });
108 $input = $input->withInput(new class () implements InputData {
109 public function getOr($_, $default): string
110 {
111 return "";
112 }
113 public function get($_): string
114 {
115 return "";
116 }
117 public function has($name): bool
118 {
119 return true;
120 }
121
122 });
123 $result = $input->getContent();
124
125 $this->assertNull($result->value());
126 }
127}
Factory for Date Formats.
Definition: Factory.php:27
Builds data types.
Definition: Factory.php:21
Provides common functionality for UI tests.
Definition: Base.php:299
normalizeHTML(string $html)
Definition: Base.php:422
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:444
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
testProducesNullWhenNoDataExists()
DefNamesource $name_source
testImplementsFactoryInterface()
This is a legacy support of Component\Input\Field\Input that has been moved to Component\Input\Contai...
Definition: Input.php:32
Describes how Input-Elements want to interact with posted data.
Definition: InputData.php:30
Describes a source for input names.
Definition: NameSource.php:27
$factory
Definition: metadata.php:75
if($format !==null) $name
Definition: metadata.php:247
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$url