ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
SequenceTest.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");
23
27use Psr\Http\Message\ServerRequestInterface;
28use ILIAS\Data\Factory as DataFactory;
29use ILIAS\Refinery\Factory as Refinery;
30
31class SequenceTest extends ILIAS_UI_TestBase
32{
33 protected I\Button\Factory $button_factory;
34 protected I\Button\Standard $button_stub;
35 protected string $button_html;
36 protected I\Symbol\Factory $symbol_factory;
37 protected Refinery $refinery;
38 protected DataFactory $data_factory;
39 protected ServerRequestInterface $request;
40
41 public function setUp(): void
42 {
43 $this->button_stub = $this->createMock(I\Button\Standard::class);
44 $this->button_html = sha1(I\Button\Standard::class);
45 $this->button_stub->method('getCanonicalName')->willReturn($this->button_html);
46 $this->button_stub->method('withSymbol')->willReturn($this->button_stub);
47 $this->button_stub->method('withUnavailableAction')->willReturn($this->button_stub);
48
49 $this->button_factory = $this->createMock(I\Button\Factory::class);
50 $this->button_factory->method('standard')->willReturn($this->button_stub);
51
52 $this->symbol_factory = $this->createMock(I\Symbol\Factory::class);
53
54 $lang = $this->getLanguage();
55 $this->data_factory = new DataFactory();
56 $this->refinery = new Refinery($this->data_factory, $lang);
57
58 $this->request = $this->createMock(ServerRequestInterface::class);
59 $this->request->method("getUri")
60 ->willReturn(new \GuzzleHttp\Psr7\Uri('http://localhost:80/doil'));
61
62 parent::setUp();
63 }
64
65 public function getUIFactory(): NoUIFactory
66 {
67 return new class (
68 $this->button_factory,
69 $this->symbol_factory,
70 ) extends NoUIFactory {
71 public function __construct(
72 protected I\Button\Factory $button_factory,
73 protected I\Symbol\Factory $symbol_factory,
74 ) {
75 }
76
77 public function button(): I\Button\Factory
78 {
79 return $this->button_factory;
80 }
81 public function symbol(): I\Symbol\Factory
82 {
83 return $this->symbol_factory;
84 }
85
86 };
87 }
88
89 protected function getNavigationFactory(): Navigation\Factory
90 {
91 return new Navigation\Factory(
92 $this->data_factory,
93 $this->refinery,
94 $this->createMock(ILIAS\UI\Storage::class)
95 );
96 }
97
98 public function testSequenceNavigationBasics(): void
99 {
100 $sequence = $this->getNavigationFactory()->sequence(
101 $this->createMock(C\Navigation\Sequence\SegmentRetrieval::class)
102 );
103
104 $id = 'some_id';
105 $view_controls = $this->createMock(I\Input\Container\ViewControl\ViewControl::class);
106 $actions = [
107 $this->createMock(I\Button\Standard::class),
108 $this->createMock(I\Button\Standard::class),
109 ];
110
111 $this->assertEquals($view_controls, $sequence->withViewControls($view_controls)->getViewControls());
112 $this->assertEquals($actions, $sequence->withActions(...$actions)->getActions());
113 $this->assertEquals($this->request, $sequence->withRequest($this->request)->getRequest());
114 $this->assertStringContainsString(
115 'sequence_' . $id . '_p=1',
116 $sequence->withId($id)->withRequest($this->request)->getNext(1)->__toString()
117 );
118 }
119
120 public function testSequenceNavigationRendering(): void
121 {
122 $binding = new class () implements C\Navigation\Sequence\SegmentRetrieval {
123 public function getAllPositions(
124 ServerRequestInterface $request,
125 mixed $viewcontrol_values,
126 mixed $filter_values,
127 ): array {
128 return [
129 ['pos 1', 'content 1'],
130 ['pos 2', 'content 2'],
131 ];
132 }
133 public function getSegment(
134 ServerRequestInterface $request,
135 mixed $position_data,
136 mixed $viewcontrol_values,
137 mixed $filter_values,
138 ): I\Legacy\Segment {
139 return new I\Legacy\Segment('title', 'content');
140 }
141 };
142
143 $sequence = $this->getNavigationFactory()->sequence($binding)->withRequest($this->request);
144 $actual_html = $this->getDefaultRenderer(null, [$this->button_stub])
145 ->render($sequence);
146
147 $expected_html = <<<EOT
148 <div class="c-sequence c-sequence--linear">
149 <div class="c-sequence__header">
150
151 <div id="id_3" class="c-sequence__navigation">
152 <div class="c-sequence__navigation--back">
153 {$this->button_html}
154 </div>
155 <div class="c-sequence__navigation--next">
156 {$this->button_html}
157 </div>
158 </div>
159
160 <div class="c-sequence__header__segment">
161 <div class="c-sequence__header__segment__title">
162 <div id="id_2">title</div>
163 </div>
164 </div>
165
166 </div>
167
168 <div class="c-sequence__segment">
169 <div id="id_1" class="c-sequence__segment__contents">
170 content
171 </div>
172 </div>
173
174 </div>
175 EOT;
176
177 $this->assertEquals(
178 $this->brutallyTrimHTML($expected_html),
179 $this->brutallyTrimHTML($actual_html)
180 );
181 }
182
183 public function testSequenceNavigationPositionsFromQuery(): void
184 {
185 $request = $this->request;
186 $request
187 ->method('getQueryParams')
188 ->willReturn(['sequence__p' => 12]);
189 $sequence = $this->getNavigationFactory()->sequence(
190 $this->createMock(C\Navigation\Sequence\SegmentRetrieval::class)
191 )->withRequest($request);
192
193 $this->assertEquals(12, $sequence->getCurrentPosition());
194 $this->assertStringContainsString('_p=11', $sequence->getNext(-1)->__toString());
195 }
196}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Builds data types.
Definition: Factory.php:36
Provides common functionality for UI tests.
Definition: Base.php:337
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
button(string $caption, string $cmd)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
getLanguage()
$lang
Definition: xapiexit.php:25