ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
BarTest.php
Go to the documentation of this file.
1 <?php
2 
18 declare(strict_types=1);
19 
20 namespace Component\Progress;
21 
22 require_once(__DIR__ . "/../../Base.php");
23 
25 use ILIAS\UI\Component as C;
26 
31 {
32  protected I\SignalGeneratorInterface $signal_generator;
33  protected I\Symbol\Glyph\Factory $glyph_factory;
34  protected C\Symbol\Glyph\Glyph $glyph_mock;
35  protected string $glyph_html;
36  protected \ILIAS\Data\URI $uri_mock;
37  protected string $uri;
38 
39  protected function setUp(): void
40  {
41  $this->glyph_html = sha1(C\Symbol\Glyph\Glyph::class);
42 
43  $this->glyph_mock = $this->createMock(C\Symbol\Glyph\Glyph::class);
44  $this->glyph_mock->method('getCanonicalName')->willReturn($this->glyph_html);
45 
46  $this->glyph_factory = $this->createMock(I\Symbol\Glyph\Factory::class);
47  $this->glyph_factory->method('apply')->willReturn($this->glyph_mock);
48  $this->glyph_factory->method('close')->willReturn($this->glyph_mock);
49 
50  $this->uri = sha1('https://example.com?foo=bar&bar=foobar');
51 
52  $this->uri_mock = $this->createMock(\ILIAS\Data\URI::class);
53  $this->uri_mock->method('__toString')->willReturn($this->uri);
54 
55  $this->signal_generator = new \IncrementalSignalGenerator();
56 
57  parent::setUp();
58  }
59 
60  public function testRender(): void
61  {
62  $label = sha1('progress_bar_label');
63 
64  $progress_bar = $this->getUIFactory()->progress()->bar($label);
65 
66  $renderer = $this->getDefaultRenderer(null, [$this->glyph_mock]);
67 
68  $actual_html = $renderer->render($progress_bar);
69 
70  $expected_html = <<<EOT
71 <div class="c-progress c-progress-bar">
72  <div class="c-progress-bar__label"><label for="id_1">$label</label>
73  <span data-status="success" class="c-progress-bar--success hidden">$this->glyph_html</span>
74  <span data-status="failure" class="c-progress-bar--failure hidden">$this->glyph_html</span>
75  </div>
76  <progress id="id_1" class="c-progress-bar__progress" value="0" max="100"></progress>
77  <div class="c-progress-bar__message text-left invisible" aria-live="polite"></div>
78 </div>
79 EOT;
80 
81  $this->assertEquals(
82  $this->brutallyTrimHTML($expected_html),
83  $this->brutallyTrimHTML($actual_html),
84  );
85  }
86 
87  public function testRenderWithAsyncUrl(): void
88  {
89  $label = sha1('progress_bar_label');
90 
91  $progress_bar = $this->getUIFactory()->progress()->bar($label, $this->uri_mock);
92 
93  $renderer = $this->getDefaultRenderer(null, [$this->glyph_mock]);
94 
95  $actual_html = $renderer->render($progress_bar);
96 
97  $expected_html = "data-url=\"$this->uri\"";
98 
99  $this->assertTrue(
100  str_contains($actual_html, $expected_html)
101  );
102  }
103 
104  public function getUIFactory(): \NoUIFactory
105  {
106  $symbol_factory = new I\Symbol\Factory(
107  $this->createMock(I\Symbol\Icon\Factory::class),
108  $this->glyph_factory,
109  $this->createMock(I\Symbol\Avatar\Factory::class),
110  );
111 
112  $progress_factory = new I\Progress\Factory(
113  $this->createMock(C\Progress\AsyncRefreshInterval::class),
114  $this->signal_generator,
115  $this->createMock(C\Progress\State\Factory::class),
116  );
117 
118  return new class ($progress_factory, $symbol_factory) extends \NoUIFactory {
119  public function __construct(
120  protected C\Progress\Factory $progress_factory,
121  protected C\Symbol\Factory $symbol_factory,
122  ) {
123  }
124  public function progress(): C\Progress\Factory
125  {
126  return $this->progress_factory;
127  }
128  public function symbol(): C\Symbol\Factory
129  {
130  return $this->symbol_factory;
131  }
132  };
133  }
134 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$renderer
Interface Observer Contains several chained tasks and infos about them.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS Data URI $uri_mock
Definition: BarTest.php:36
Provides common functionality for UI tests.
Definition: Base.php:330
C Symbol Glyph Glyph $glyph_mock
Definition: BarTest.php:34
I SignalGeneratorInterface $signal_generator
Definition: BarTest.php:32
__construct(Container $dic, ilPlugin $plugin)
I Symbol Glyph Factory $glyph_factory
Definition: BarTest.php:33