ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ConfirmationTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\LegalDocuments\test\ContainerMock;
24use PHPUnit\Framework\TestCase;
26use ilLanguage;
27
28require_once __DIR__ . '/../ContainerMock.php';
29
30class ConfirmationTest extends TestCase
31{
32 use ContainerMock;
33
34 public function testConstruct(): void
35 {
36 $this->assertInstanceOf(Confirmation::class, new Confirmation($this->mock(ilLanguage::class), $this->fail(...)));
37 }
38
39 public function testRender(): void
40 {
41 $confirmation = $this->confirmationGUIReplacement();
42 $language = $this->mock(ilLanguage::class);
43 $language->expects(self::exactly(2))->method('txt')->willReturnCallback(static fn(string $key): string => 'translated ' . $key);
44
45 $instance = new Confirmation($language, static fn() => $confirmation);
46 $this->assertSame('rendered string', $instance->render('dummy link', 'submit', 'cancel', 'Hi', [
47 'foo' => 'bar',
48 7 => 'baz',
49 ]));
50
51 $this->assertSame('dummy link', $confirmation->link);
52 $this->assertSame('submit', $confirmation->submit_command);
53 $this->assertSame('cancel', $confirmation->cancel_command);
54 $this->assertSame('translated confirm', $confirmation->submit_label);
55 $this->assertSame('translated cancel', $confirmation->cancel_label);
56 $this->assertSame('Hi', $confirmation->header_text);
57 $this->assertSame([['ids[]', 'foo', 'bar'], ['ids[]', '7', 'baz']], $confirmation->items);
58 }
59
61 {
62 return new class () {
63 public string $link;
64 public string $confirm_command;
65 public string $cancel_command;
66 public string $header_text;
67 public array $items = [];
68 public string $cancel_label;
69 public string $submit_label;
70 public string $submit_command;
71
72 public function setFormAction(string $link): void
73 {
74 $this->link = $link;
75 }
76 public function setConfirm(string $label, string $command): void
77 {
78 $this->submit_label = $label;
79 $this->submit_command = $command;
80 }
81 public function setCancel(string $label, string $command): void
82 {
83 $this->cancel_label = $label;
84 $this->cancel_command = $command;
85 }
86 public function setHeaderText(string $text): void
87 {
88 $this->header_text = $text;
89 }
90 public function addItem(string $a, string $b, string $c): void
91 {
92 $this->items[] = [$a, $b, $c];
93 }
94 public function getHTML(): string
95 {
96 return 'rendered string';
97 }
98 };
99 }
100}
language handling
$c
Definition: deliver.php:25
link(string $caption, string $href, bool $new_viewport=false)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples