19declare(strict_types=1);
21require_once(__DIR__ .
"/../../Base.php");
25use PHPUnit\Framework\MockObject\Stub;
26use PHPUnit\Framework\MockObject\MockObject;
52 protected function setUp(): void
54 $this->uri_stub_value = sha1(\
ILIAS\Data\URI::class);
55 $this->uri_stub = $this->createStub(\
ILIAS\Data\URI::class);
56 $this->uri_stub->method(
'__toString')->willReturn($this->uri_stub_value);
58 $this->glyph_stub_html = sha1(
I\Symbol\Glyph\Glyph::class);
59 $this->glyph_stub = $this->createStub(
I\Symbol\Glyph\Glyph::class);
60 $this->glyph_stub->method(
'getCanonicalName')->willReturn($this->glyph_stub_html);
61 $this->glyph_stub->method(
'withLabel')->willReturnSelf();
63 $this->button_mock_html = sha1(
I\
Button\Standard::class);
64 $this->button_mock = $this->createMock(
I\
Button\Standard::class);
65 $this->button_mock->method(
'getCanonicalName')->willReturn($this->button_mock_html);
67 $this->modal_mock_html = sha1(
I\Modal\RoundTrip::class);
68 $this->modal_mock = $this->createMock(
I\Modal\RoundTrip::class);
69 $this->modal_mock->method(
'getCanonicalName')->willReturn($this->modal_mock_html);
71 $this->image_mock_html = sha1(
I\Image\Image::class);
72 $this->image_mock = $this->createMock(
I\Image\Image::class);
73 $this->image_mock->method(
'getCanonicalName')->willReturn($this->image_mock_html);
75 $this->button_factory_mock = $this->createMock(
I\
Button\Factory::class);
76 $this->button_factory_mock->method(
'standard')->willReturn($this->button_mock);
78 $this->modal_factory_mock = $this->createMock(
I\Modal\Factory::class);
79 $this->modal_factory_mock->method(
'roundtrip')->willReturn($this->modal_mock);
81 $this->image_factory_mock = $this->createMock(
I\Image\Factory::class);
82 $this->image_factory_mock->method(
'responsive')->willReturn($this->image_mock);
84 $this->to_svg_qr_code_mock = $this->createMock(\
ILIAS\Refinery\Transformation::class);
85 $this->from_svg_mock = $this->createMock(\
ILIAS\Refinery\Transformation::class);
92 $glyph_factory_stub = $this->createStub(
I\Symbol\Glyph\Factory::class);
93 $glyph_factory_stub->method($this->anything())->willReturn($this->glyph_stub);
94 $symbol_factory_stub = $this->createStub(
I\Symbol\Factory::class);
95 $symbol_factory_stub->method(
'glyph')->willReturn($glyph_factory_stub);
97 $real_transfer_factory =
new I\Transfer\Factory();
100 $symbol_factory_stub,
104 $real_transfer_factory,
107 protected I\Symbol\Factory $symbol_factory,
108 protected I\
Button\Factory $button_factory,
109 protected I\Modal\Factory $modal_factory,
110 protected I\Image\Factory $image_factory,
111 protected I\Transfer\Factory $transfer_factory,
114 public function symbol(): I\Symbol\Factory
116 return $this->symbol_factory;
118 public function button(): I\Button\Factory
120 return $this->button_factory;
122 public function modal(): I\Modal\Factory
124 return $this->modal_factory;
126 public function image(): I\Image\Factory
128 return $this->image_factory;
130 public function transfer(): I\Transfer\Factory
132 return $this->transfer_factory;
139 $uri_group_stub = $this->createStub(\
ILIAS\Refinery\URI\Group::class);
140 $uri_group_stub->method(
'toSvgQrCode')->willReturn($this->to_svg_qr_code_mock);
141 $uri_group_stub->method(
'fromSvg')->willReturn($this->from_svg_mock);
143 $refinery_stub = $this->createStub(\
ILIAS\Refinery\Factory::class);
144 $refinery_stub->method(
'uri')->willReturn($uri_group_stub);
146 return $refinery_stub;
151 $link_label = sha1(
'testRenderWithClipboardTransferMechanism');
152 $link_transfer = $this->
getUIFactory()->transfer()->link(
153 C\Transfer\TransferMechanism::CLIPBOARD,
158 $renderer = $this->getDefaultRenderer(
null, [$this->glyph_stub]);
160 $expected_transfer_type = C\Transfer\TransferMechanism::CLIPBOARD->value;
162<div
id=
"id_2" class=
"c-transfer c-transfer-link">
163 <label
for=
"id_2_value">$link_label</label>
164 <div
class=
"c-transfer__contents">
165 <input
id=
"id_2_value" class=
"c-transfer__payload visible" type=
"url" value=
"$this->uri_stub_value" readonly=
"readonly">
166 <div
class=
"c-tooltip__container">
167 <
button data-transfer-type=
"$expected_transfer_type" class=
"btn btn-default" aria-label=
"copy_to_clipboard_aria">
168 <span data-transfer-status=
"default" class=
"visible">$this->glyph_stub_html</span>
169 <span data-transfer-status=
"success" data-transfer-message=
"copy_to_clipboard_success" class=
"hidden">$this->glyph_stub_html</span>
170 <span data-transfer-status=
"failure" data-transfer-message=
"copy_to_clipboard_failure" class=
"hidden">$this->glyph_stub_html</span>
171 <span>copy_to_clipboard</span>
173 <div
id=
"id_1" role=
"status" class=
"c-tooltip c-tooltip--hidden">
181 $actual =
$renderer->render($link_transfer);
183 $this->assertSame($this->brutallyTrimHTML($expected), $this->brutallyTrimHTML($actual));
188 $link_label = sha1(
'testRenderWithWebShreTransferMechanism');
189 $link_transfer = $this->
getUIFactory()->transfer()->link(
190 C\Transfer\TransferMechanism::WEB_SHARE,
195 $renderer = $this->getDefaultRenderer(
null, [$this->glyph_stub]);
197 $expected_transfer_type = C\Transfer\TransferMechanism::WEB_SHARE->value;
199<div
id=
"id_2" class=
"c-transfer c-transfer-link">
200 <label
for=
"id_2_value">$link_label</label>
201 <div
class=
"c-transfer__contents">
202 <input
id=
"id_2_value" class=
"c-transfer__payload visible" type=
"url" value=
"$this->uri_stub_value" readonly=
"readonly">
203 <div
class=
"c-tooltip__container">
204 <
button data-transfer-type=
"$expected_transfer_type" class=
"btn btn-default" aria-label=
"open_web_share_api_aria">
205 <span data-transfer-status=
"default" class=
"visible">$this->glyph_stub_html</span>
206 <span data-transfer-status=
"success" data-transfer-message=
"open_web_share_api_success" class=
"hidden">$this->glyph_stub_html</span>
207 <span data-transfer-status=
"failure" data-transfer-message=
"open_web_share_api_failure" class=
"hidden">$this->glyph_stub_html</span>
208 <span>open_web_share_api</span>
210 <div
id=
"id_1" role=
"status" class=
"c-tooltip c-tooltip--hidden">
218 $actual =
$renderer->render($link_transfer);
220 $this->assertSame($this->brutallyTrimHTML($expected), $this->brutallyTrimHTML($actual));
225 $link_label = sha1(
'testRenderWithQrCodeTransferMechanism');
228 $svg_stub = $this->createStub(\
ILIAS\Data\SVG::class);
229 $svg_data_uri =
'data:image/svg+xml;base64,' . base64_encode($link_label);
230 $show_signal = $this->createStub(
C\Signal::class);
233 $this->to_svg_qr_code_mock
234 ->expects($this->once())
235 ->method(
'transform')
236 ->with($this->identicalTo($this->uri_stub))
237 ->willReturn($svg_stub);
239 ->expects($this->once())
240 ->method(
'transform')
241 ->with($this->identicalTo($svg_stub))
242 ->willReturn($svg_data_uri);
245 $this->image_factory_mock
246 ->expects($this->once())
247 ->method(
'responsive')
248 ->with($svg_data_uri, $link_label);
250 ->expects($this->once())
251 ->method(
'withAction')
252 ->with($this->uri_stub_value)
256 $this->modal_factory_mock
257 ->expects($this->once())
258 ->method(
'roundtrip')
259 ->with(
'use_qr_code', [$this->image_mock]);
261 ->expects($this->once())
262 ->method(
'withCancelButtonLabel')
266 ->expects($this->once())
267 ->method(
'withCloseWithKeyboard')
271 ->expects($this->once())
272 ->method(
'getShowSignal')
273 ->willReturn($show_signal);
276 $this->button_factory_mock
277 ->expects($this->once())
279 ->with(
'show_qr_code',
'');
281 ->expects($this->once())
282 ->method(
'withAriaLabel')
283 ->with(
'show_qr_code_aria')
286 ->expects($this->once())
287 ->method(
'withSymbol')
288 ->with($this->identicalTo($this->glyph_stub))
291 ->expects($this->once())
292 ->method(
'withOnClick')
293 ->with($this->identicalTo($show_signal))
296 $link_transfer = $this->
getUIFactory()->transfer()->link(
304 $renderer = $this->getDefaultRenderer(
null, [$this->button_mock, $this->modal_mock]);
307<div
id=
"id_1" class=
"c-transfer c-transfer-link">
308 <label
for=
"id_1_value">$link_label</label>
309 <div
class=
"c-transfer__contents">
310 <input
id=
"id_1_value" class=
"c-transfer__payload visible" type=
"url" value=
"$this->uri_stub_value" readonly=
"readonly">
311 $this->button_mock_html{$this->modal_mock_html}
316 $actual =
$renderer->render($link_transfer);
318 $this->assertSame($this->brutallyTrimHTML($expected), $this->brutallyTrimHTML($actual));
323 $initial = C\Transfer\TransferMechanism::CLIPBOARD;
324 $first = C\Transfer\TransferMechanism::WEB_SHARE;
327 $link_transfer = $this->
getUIFactory()->transfer()->link($initial, $this->uri_stub,
'');
328 $this->assertSame([$initial], array_values($link_transfer->getTransferMechanisms()));
330 $link_transfer = $link_transfer->withAdditionalTransferMechanism($first);
331 $this->assertSame([$initial, $first], array_values($link_transfer->getTransferMechanisms()));
333 $link_transfer = $link_transfer->withAdditionalTransferMechanism($second);
334 $this->assertSame([$initial, $first, $second], array_values($link_transfer->getTransferMechanisms()));
337 $link_transfer = $link_transfer->withAdditionalTransferMechanism($second);
338 $link_transfer = $link_transfer->withAdditionalTransferMechanism($first);
340 $this->assertSame([$initial, $first, $second], array_values($link_transfer->getTransferMechanisms()));
Provides common functionality for UI tests.
testRenderWithClipboardTransferMechanism()
I Modal RoundTrip &MockObject $modal_mock
I Image Factory &MockObject $image_factory_mock
I Symbol Glyph Glyph &Stub $glyph_stub
I Modal Factory &MockObject $modal_factory_mock
ILIAS Refinery Transformation &MockObject $from_svg_mock
ILIAS Data URI &Stub $uri_stub
testWithAdditionalTransferMechanismOrderPreservation()
testRenderWithWebShreTransferMechanism()
ILIAS Refinery Transformation &MockObject $to_svg_qr_code_mock
I Button Factory &MockObject $button_factory_mock
I Button Standard &MockObject $button_mock
I Image Image &MockObject $image_mock
testRenderWithQrCodeTransferMechanism()
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
modal(string $title="", string $cancel_label="")
button(string $caption, string $cmd)
@ QR_CODE
Transfer information by copying its contents to the computers clipboard.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.