ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
GetFileInfoResponseTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\WOPI\Handler;
22
23use PHPUnit\Framework\TestCase;
26
30final class GetFileInfoResponseTest extends TestCase
31{
32 protected function setUp(): void
33 {
34 if (!defined('ILIAS_HTTP_PATH')) {
35 define('ILIAS_HTTP_PATH', 'https://ilias.example.org');
36 }
37
38 $GLOBALS['DIC'] ??= new \ILIAS\DI\Container();
39 if (!isset($GLOBALS['DIC']['ilDB'])) {
40 $db = $this->createStub(\ilDBInterface::class);
41 $db->method('queryF')->willReturn($this->createStub(\ilDBStatement::class));
42 $db->method('fetchAssoc')->willReturn(
43 ['firstname' => 'Ada', 'lastname' => 'Lovelace', 'title' => '', 'login' => 'ada']
44 );
45 $GLOBALS['DIC']['ilDB'] = static fn(): \ilDBInterface => $db;
46 }
47 }
48
49 private function responseFor(bool $editable, ?bool $user_can_write = null): array
50 {
51 $information = $this->createStub(Information::class);
52 $information->method('getSuffix')->willReturn('odt');
53 $information->method('getSize')->willReturn(1234);
54 $information->method('getCreationDate')->willReturn(new \DateTimeImmutable('2026-01-01 12:00:00'));
55
56 $revision = $this->createStub(Revision::class);
57 $revision->method('getTitle')->willReturn('minutes.odt');
58 $revision->method('getVersionNumber')->willReturn(3);
59 $revision->method('getOwnerId')->willReturn(6);
60 $revision->method('getInformation')->willReturn($information);
61
62 return (new GetFileInfoResponse($revision, 6, $editable, $user_can_write))->jsonSerialize();
63 }
64
71 {
72 $response = $this->responseFor(false);
73
74 $this->assertArrayNotHasKey('RestrictedWebViewOnly', $response);
75 $this->assertArrayNotHasKey('UserCanAttend', $response);
76 }
77
79 {
80 $response = $this->responseFor(true);
81
82 $this->assertArrayNotHasKey('RestrictedWebViewOnly', $response);
83 $this->assertArrayNotHasKey('UserCanAttend', $response);
84 }
85
86 public function testViewSessionStaysReadOnly(): void
87 {
88 $response = $this->responseFor(false);
89
90 $this->assertTrue($response['ReadOnly']);
91 $this->assertFalse($response['UserCanWrite']);
92 $this->assertFalse($response['SupportsUpdate']);
93 }
94
95 public function testEditSessionMayWrite(): void
96 {
97 $response = $this->responseFor(true);
98
99 $this->assertFalse($response['ReadOnly']);
100 $this->assertTrue($response['UserCanWrite']);
101 $this->assertTrue($response['SupportsUpdate']);
102 }
103
111 {
112 $response = $this->responseFor(false, true);
113
114 $this->assertTrue($response['ReadOnly']);
115 $this->assertFalse($response['SupportsUpdate']);
116 $this->assertTrue($response['UserCanWrite']);
117 }
118
120 {
121 $response = $this->responseFor(false, false);
122
123 $this->assertTrue($response['ReadOnly']);
124 $this->assertFalse($response['SupportsUpdate']);
125 $this->assertFalse($response['UserCanWrite']);
126 }
127
132 {
133 $this->assertFalse($this->responseFor(false, true)['EditModePostMessage']);
134 $this->assertFalse($this->responseFor(true)['EditModePostMessage']);
135 }
136
141 {
142 foreach ([false, true] as $editable) {
143 $response = $this->responseFor($editable);
144
145 $this->assertArrayNotHasKey('CloseUrl', $response);
146 $this->assertFalse($response['ClosePostMessage']);
147 }
148 }
149
150 public function testIdsAndVersionAreStrings(): void
151 {
152 $response = $this->responseFor(true);
153
154 $this->assertSame('6', $response['OwnerId']);
155 $this->assertSame('6', $response['UserId']);
156 $this->assertIsString($response['Version']);
157 }
158}
responseFor(bool $editable, ?bool $user_can_write=null)
testTheHostDoesNotOfferAWayIntoEditMode()
ILIAS never handles the UI_Edit message, so it must not announce that it does.
testViewSessionDoesNotClaimRestrictionsItDoesNotMean()
RestrictedWebViewOnly restricts what the user may do with the file and its effect is up to the client...
testViewSessionOfAUserWhoMayWriteStaysReadOnlyButDoesNotBlameTheirRights()
The content tab of a file object is a viewer, also for someone who holds the permission to edit the f...
testNoCloseButtonOfTheClientIsAnnounced()
ILIAS closes the WOPI client itself, a close button of the client would do nothing.
Interface ilDBInterface.
$GLOBALS["DIC"]
Definition: wac.php:66
$response
Definition: xapitoken.php:92