ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
StandardToastTest.php
Go to the documentation of this file.
1 <?php
18 declare(strict_types=1);
19 
24 
25 require_once(__DIR__ . "/BaseToastSetUp.php");
26 
28 {
29  public function testStandardToast(): void
30  {
31  $id = $this->createMock(IdentificationInterface::class);
32 
33  $standard_toast = $this->factory->standard(
34  $id,
35  'Toast Title'
36  );
37 
38  $this->assertInstanceOf(StandardToastItem::class, $standard_toast);
39  $this->assertEquals('Toast Title', $standard_toast->getTitle());
40  $this->assertEquals([], $standard_toast->getAllToastActions());
41  $this->assertCount(0, $standard_toast->getAllToastActions());
42  $this->assertCount(0, $standard_toast->getAdditionalToastActions());
43 
44  $handle = (fn(): true => true);
45 
46  $standard_toast = $standard_toast->withShownCallable($handle);
47  $this->assertCount(1, $standard_toast->getAllToastActions());
48  $this->assertCount(0, $standard_toast->getAdditionalToastActions());
49 
50  $standard_toast = $standard_toast->withClosedCallable($handle);
51  $this->assertCount(2, $standard_toast->getAllToastActions());
52  $this->assertCount(0, $standard_toast->getAdditionalToastActions());
53 
54  $standard_toast = $standard_toast->withVanishedCallable($handle);
55  $this->assertCount(3, $standard_toast->getAllToastActions());
56  $this->assertCount(0, $standard_toast->getAdditionalToastActions());
57 
58  $standard_toast = $standard_toast->withAdditionToastAction($this->factory->action('one', 'One', $handle));
59  $this->assertCount(4, $standard_toast->getAllToastActions());
60  $this->assertCount(1, $standard_toast->getAdditionalToastActions());
61 
62  $standard_toast = $standard_toast->withAdditionToastAction($this->factory->action('two', 'Two', $handle));
63  $this->assertCount(5, $standard_toast->getAllToastActions());
64  $this->assertCount(2, $standard_toast->getAdditionalToastActions());
65 
66  // double add
67  $this->expectException(\InvalidArgumentException::class);
68  $standard_toast = $standard_toast->withAdditionToastAction($this->factory->action('two', 'Two', $handle));
69  }
70 
71  public static function reservedActionsProvider(): array
72  {
73  $action = (fn(): true => true);
74 
75  return [
76  [new ToastAction('shown', 'shown', $action)],
77  [new ToastAction('closed', 'closed', $action)],
78  [new ToastAction('vanished', 'vanished', $action)],
79  ];
80  }
81 
82  #[DataProvider('reservedActionsProvider')]
83  public function testReservedActions(ToastAction $action): void
84  {
85  $id = $this->createMock(IdentificationInterface::class);
86 
87  $standard_toast = $this->factory->standard(
88  $id,
89  'Toast Title'
90  );
91 
92  $this->expectException(\InvalidArgumentException::class);
93  $standard_toast = $standard_toast->withAdditionToastAction($action);
94  }
95 }
factory()
testReservedActions(ToastAction $action)
static reservedActionsProvider()
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23