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