ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ToastTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once("vendor/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../Base.php");
23
27
29{
30 public function getToastFactory(): \ILIAS\UI\Implementation\Component\Toast\Factory
31 {
33 }
34
35 public function getIconFactory(): \ILIAS\UI\Implementation\Component\Symbol\Icon\Factory
36 {
38 }
39
40 public function getLinkFactory(): \ILIAS\UI\Implementation\Component\Link\Factory
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
55 #[\PHPUnit\Framework\Attributes\DataProvider('getToastProvider')]
56 public function testToast(string $title, string $description, string $action): void
57 {
58 $toast = $this->getToastFactory()->standard($title, $this->getIconFactory()->standard('', ''))
59 ->withDescription($description)
60 ->withAction($action)
61 ->withAdditionalLink($this->getLinkFactory()->standard('', ''));
62
63 $this->assertNotNull($toast);
64 $this->assertEquals($title, $toast->getTitle());
65 $this->assertEquals($description, $toast->getDescription());
66 $this->assertEquals($action, $toast->getAction());
67 $this->assertCount(1, $toast->getLinks());
68 $this->assertInstanceOf(Link::class, $toast->getLinks()[0]);
69 $this->assertCount(0, $toast->withoutLinks()->getLinks());
70 $this->assertInstanceOf(Icon::class, $toast->getIcon());
71 }
72
73 #[\PHPUnit\Framework\Attributes\DataProvider('getToastProvider')]
74 public function testToastContainer(string $title, string $description): void
75 {
76 $container = $this->getToastFactory()->container()->withAdditionalToast(
77 $this->getToastFactory()->standard('', $this->getIconFactory()->standard('', ''))
78 );
79
80 $this->assertNotNull($container);
81 $this->assertCount(1, $container->getToasts());
82 $this->assertInstanceOf(Toast::class, $container->getToasts()[0]);
83 $this->assertCount(0, $container->withoutToasts()->getToasts());
84 }
85
86 public static function getToastProvider(): array
87 {
88 return [
89 ['title', 'description', 'test.php'],
90 ['', '', ''],
91 ['"/><script>alert("hack")</script>', '"/><script>alert("hack")</script>', 'test.php']
92 ];
93 }
94}
Provides common functionality for UI tests.
Definition: Base.php:337
getLinkFactory()
Definition: ToastTest.php:40
getToastFactory()
Definition: ToastTest.php:30
testToastContainer(string $title, string $description)
Definition: ToastTest.php:74
testToast(string $title, string $description, string $action)
Definition: ToastTest.php:56
static getToastProvider()
Definition: ToastTest.php:86
testImplementsFactoryInterface()
Definition: ToastTest.php:45
getIconFactory()
Definition: ToastTest.php:35
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
$container
@noRector
Definition: wac.php:37