ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ToastTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once("libs/composer/vendor/autoload.php");
22 require_once(__DIR__ . "/../../Base.php");
23 
27 
29 {
31  {
33  }
34 
36  {
38  }
39 
41  {
43  }
44 
45  public function testImplementsFactoryInterface(): void
46  {
47  $f = $this->getToastFactory();
48 
49  $this->assertInstanceOf("ILIAS\\UI\\Component\\Toast\\Factory", $f);
50 
51  $this->assertInstanceOf("ILIAS\\UI\\Component\\Toast\\Toast", $f->standard('', $this->getIconFactory()->standard('', '')));
52  $this->assertInstanceOf("ILIAS\\UI\\Component\\Toast\\Container", $f->container());
53  }
54 
58  public function testToast(string $title, string $description, string $action): void
59  {
60  $toast = $this->getToastFactory()->standard($title, $this->getIconFactory()->standard('', ''))
61  ->withDescription($description)
62  ->withAction($action)
63  ->withAdditionalLink($this->getLinkFactory()->standard('', ''));
64 
65  $this->assertNotNull($toast);
66  $this->assertEquals($title, $toast->getTitle());
67  $this->assertEquals($description, $toast->getDescription());
68  $this->assertEquals($action, $toast->getAction());
69  $this->assertCount(1, $toast->getLinks());
70  $this->assertInstanceOf(Link::class, $toast->getLinks()[0]);
71  $this->assertCount(0, $toast->withoutLinks()->getLinks());
72  $this->assertInstanceOf(Icon::class, $toast->getIcon());
73  }
74 
78  public function testToastContainer(string $title, string $description): void
79  {
80  $container = $this->getToastFactory()->container()->withAdditionalToast(
81  $this->getToastFactory()->standard('', $this->getIconFactory()->standard('', ''))
82  );
83 
84  $this->assertNotNull($container);
85  $this->assertCount(1, $container->getToasts());
86  $this->assertInstanceOf(Toast::class, $container->getToasts()[0]);
87  $this->assertCount(0, $container->withoutToasts()->getToasts());
88  }
89 
90  public function getToastProvider(): array
91  {
92  return [
93  ['title', 'description', 'test.php'],
94  ['', '', ''],
95  ['"/><script>alert("hack")</script>', '"/><script>alert("hack")</script>', 'test.php']
96  ];
97  }
98 }
getToastProvider()
Definition: ToastTest.php:90
standard()
This is an example, of how the Notification Slate is generated by assigning Notification Items to it...
Definition: standard.php:16
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testImplementsFactoryInterface()
Definition: ToastTest.php:45
$container
Definition: wac.php:14
getLinkFactory()
Definition: ToastTest.php:40
testToast(string $title, string $description, string $action)
getToastProvider
Definition: ToastTest.php:58
Provides common functionality for UI tests.
Definition: Base.php:310
This is how the factory for UI elements looks.
Definition: Factory.php:37
testToastContainer(string $title, string $description)
getToastProvider
Definition: ToastTest.php:78
getIconFactory()
Definition: ToastTest.php:35
getToastFactory()
Definition: ToastTest.php:30