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