ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
RoutingTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\LegalDocuments\test\ContainerMock;
26use PHPUnit\Framework\TestCase;
28use ilCtrl;
29
30require_once __DIR__ . '/../ContainerMock.php';
31
32class RoutingTest extends TestCase
33{
34 use ContainerMock;
35
36 public function testConstruct(): void
37 {
38 $this->assertInstanceOf(Routing::class, new Routing(
39 $this->mock(ilCtrl::class),
40 $this->mock(SelectSetting::class),
41 $this->fail(...),
42 $this->fail(...)
43 ));
44 }
45
46 public function testCtrl(): void
47 {
48 $ctrl = $this->mock(ilCtrl::class);
49 $this->assertSame($ctrl, (new Routing($ctrl, $this->mock(SelectSetting::class), $this->fail(...), $this->fail(...)))->ctrl());
50 }
51
52 public function testLogoutUrl(): void
53 {
54 $this->assertSame('dummy logout url', (new Routing(
55 $this->mock(ilCtrl::class),
56 $this->mock(SelectSetting::class),
57 $this->fail(...),
58 fn() => 'dummy logout url'
59 ))->logoutUrl());
60 }
61
62 public function testRedirectToStartingPage(): void
63 {
64 $called = false;
65
66 $session = $this->mock(SelectSetting::class);
67 $session->expects(self::once())->method('typed')->willReturnCallback(function (string $key, callable $proc) {
68 $this->assertSame('orig_request_target', $key);
69 return $this->mockTree(Setting::class, ['value' => null]);
70 });
71
72 (new Routing(
73 $this->mock(ilCtrl::class),
74 $session,
75 static function () use (&$called): void {
76 $called = true;
77 },
78 $this->fail(...)
79 ))->redirectToOriginalTarget();
80
81 $this->assertTrue($called);
82 }
83
84 public function testRedirectToOriginalTarget(): void
85 {
86 $setting = $this->mock(Setting::class);
87 $setting->method('value')->willReturn('some url');
88 $setting->expects(self::once())->method('update')->with(null);
89
90 $session = $this->mock(SelectSetting::class);
91 $session->method('typed')->willReturnCallback(function (string $key, callable $proc) use ($setting) {
92 $this->assertSame('orig_request_target', $key);
93
94 return $setting;
95 });
96
97 $ctrl = $this->mock(ilCtrl::class);
98 $ctrl->expects(self::once())->method('redirectToURL')->with('some url');
99
100 (new Routing(
101 $ctrl,
102 $session,
103 $this->fail(...),
104 $this->fail(...)
105 ))->redirectToOriginalTarget();
106 }
107}
ilSetting $setting
Definition: class.ilias.php:68
Class ilCtrl provides processing control methods.