ILIAS  release_8 Revision v8.24
ToastTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21require_once("libs/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../Base.php");
23
27
29{
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 test_implements_factory_interface(): 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 test_toast(string $title, string $description, int $vanish_time, int $delay_time, string $action): void
59 {
60 $toast = $this->getToastFactory()->standard($title, $this->getIconFactory()->standard('', ''))
61 ->withDescription($description)
62 ->withVanishTime($vanish_time)
63 ->withDelayTime($delay_time)
64 ->withAction($action)
65 ->withAdditionalLink($this->getLinkFactory()->standard('', ''));
66
67 $this->assertNotNull($toast);
68 $this->assertEquals($title, $toast->getTitle());
69 $this->assertEquals($description, $toast->getDescription());
70 $this->assertEquals($vanish_time, $toast->getVanishTime());
71 $this->assertEquals($delay_time, $toast->getDelayTime());
72 $this->assertEquals($action, $toast->getAction());
73 $this->assertCount(1, $toast->getLinks());
74 $this->assertInstanceOf(Link::class, $toast->getLinks()[0]);
75 $this->assertCount(0, $toast->withoutLinks()->getLinks());
76 $this->assertInstanceOf(Icon::class, $toast->getIcon());
77 }
78
82 public function test_toast_container(string $title, string $description, int $vanish_time): void
83 {
84 $container = $this->getToastFactory()->container()->withAdditionalToast(
85 $this->getToastFactory()->standard('', $this->getIconFactory()->standard('', ''))
86 );
87
88 $this->assertNotNull($container);
89 $this->assertCount(1, $container->getToasts());
90 $this->assertInstanceOf(Toast::class, $container->getToasts()[0]);
91 $this->assertCount(0, $container->withoutToasts()->getToasts());
92 }
93
94 public function toast_provider(): array
95 {
96 return [
97 ['title', 'description', 5000, 500, 'test.php'],
98 ['', '', -5000, -500, ''],
99 ['"/><script>alert("hack")</script>', '"/><script>alert("hack")</script>', PHP_INT_MAX, PHP_INT_MIN, 'test.php']
100 ];
101 }
102}
Provides common functionality for UI tests.
Definition: Base.php:299
getLinkFactory()
Definition: ToastTest.php:40
test_implements_factory_interface()
Definition: ToastTest.php:45
getToastFactory()
Definition: ToastTest.php:30
test_toast_container(string $title, string $description, int $vanish_time)
@dataProvider toast_provider
Definition: ToastTest.php:82
toast_provider()
Definition: ToastTest.php:94
getIconFactory()
Definition: ToastTest.php:35
test_toast(string $title, string $description, int $vanish_time, int $delay_time, string $action)
@dataProvider toast_provider
Definition: ToastTest.php:58
This is how the factory for UI elements looks.
Definition: Factory.php:38
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
standard()
This is an example, of how the Notification Slate is generated by assigning Notification Items to it.
Definition: standard.php:16
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$container
@noRector
Definition: wac.php:14