ILIAS  trunk Revision v12.0_alpha-1338-g8f7e531aa3c
ResponseFactoryTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\StaticURL\Tests;
22
28
29require_once "Base.php";
30
34final class ResponseFactoryTest extends Base
35{
36 private function buildContext(bool $logged_in): Context
37 {
38 $user = $this->createMock(\ilObjUser::class);
39 $user->method('isAnonymous')->willReturn(!$logged_in);
40 $user->method('getId')->willReturn($logged_in ? 42 : 0);
41
42 $container = $this->createMock(Container::class);
43 $container->method('user')->willReturn($user);
44
45 return new Context($container);
46 }
47
48 public function testCannotReturnsCannotHandle(): void
49 {
50 $response = (new Factory($this->buildContext(true)))->cannot();
51
52 $this->assertFalse($response->targetCanBeReached());
53 $this->assertNull($response->getURIPath());
54 }
55
56 public function testCannotReachReturnsCannotReach(): void
57 {
58 $response = (new Factory($this->buildContext(true)))->cannotReach();
59
60 $this->assertTrue($response->targetCanBeReached());
61 $this->assertNull($response->getURIPath());
62 }
63
65 {
66 $response = (new Factory($this->buildContext(true)))->loginFirst();
67
68 $this->assertInstanceOf(CannotReach::class, $response);
69 }
70
72 {
73 $response = (new Factory($this->buildContext(false)))->loginFirst();
74
75 $this->assertInstanceOf(MaybeCanHandlerAfterLogin::class, $response);
76 }
77
79 {
80 $response = (new Factory($this->buildContext(true)))->can('/ilias.php?ref_id=5');
81
82 $this->assertSame('/ilias.php?ref_id=5', $response->getURIPath());
83 $this->assertSame(0, $response->shift());
84 $this->assertTrue($response->targetCanBeReached());
85 }
86
88 {
89 $response = (new Factory($this->buildContext(true)))->can('/ilias.php?ref_id=5', true);
90
91 $this->assertSame(1, $response->shift());
92 }
93}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
Returned by a Handler when the target exists but the CURRENT (logged-in) user has no permission to re...
Definition: CannotReach.php:35
Returned when the target is (or might be) reachable after the user logs in.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Base.php:19
$container
@noRector
Definition: wac.php:37
$response
Definition: xapitoken.php:90