‪TYPO3CMS  11.5
OpenDocumentServiceTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Prophecy\PhpUnit\ProphecyTrait;
21 use Prophecy\Prophecy\ObjectProphecy;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪OpenDocumentServiceTest extends UnitTestCase
30 {
31  use ProphecyTrait;
32 
34 
36  protected ObjectProphecy ‪$backendUser;
37 
41  protected function ‪setUp(): void
42  {
43  parent::setUp();
44  $this->backendUser = $this->prophesize(BackendUserAuthentication::class);
45  $this->subject = new ‪OpenDocumentService($this->backendUser->reveal());
46  }
47 
51  public function ‪getsOpenDocumentsFromUserSession(): void
52  {
53  $this->backendUser->getModuleData('FormEngine', 'ses')->willReturn([
54  [
55  'identifier1' => [ 'data1' ],
56  'identifier2' => [ 'data2' ],
57  ],
58  'identifier2',
59  ]);
60 
61  $openDocuments = $this->subject->getOpenDocuments();
62  $expected = [
63  'identifier1' => [ 'data1' ],
64  'identifier2' => [ 'data2' ],
65  ];
66 
67  self::assertEquals($expected, $openDocuments);
68  }
69 
73  public function ‪handlesUserSessionWithoutOpenDocuments(): void
74  {
75  $this->backendUser->getModuleData('FormEngine', 'ses')->willReturn();
76 
77  $openDocuments = $this->subject->getOpenDocuments();
78 
79  self::assertEquals([], $openDocuments);
80  }
81 
85  public function ‪getsRecentDocumentsFromUserSession(): void
86  {
87  $this->backendUser->getModuleData('opendocs::recent')->willReturn([
88  'identifier1' => [ 'data1' ],
89  ]);
90 
91  $recentDocuments = $this->subject->getRecentDocuments();
92  $expected = [
93  'identifier1' => [ 'data1' ],
94  ];
95 
96  self::assertEquals($expected, $recentDocuments);
97  }
98 
102  public function ‪handlesUserSessionWithoutRecentDocuments(): void
103  {
104  $this->backendUser->getModuleData('opendocs::recent')->willReturn();
105 
106  $recentDocuments = $this->subject->getRecentDocuments();
107 
108  self::assertEquals([], $recentDocuments);
109  }
110 
114  public function ‪closesDocument(): void
115  {
116  $this->backendUser->getModuleData('FormEngine', 'ses')->willReturn([
117  [
118  'identifier8' => [ 'data8' ],
119  'identifier9' => [ 'data9' ],
120  ],
121  'identifier9',
122  ]);
123  $this->backendUser->getModuleData('opendocs::recent')->willReturn([
124  'identifier8' => [ 'data8' ],
125  'identifier7' => [ 'data7' ],
126  'identifier6' => [ 'data6' ],
127  'identifier5' => [ 'data5' ],
128  'identifier4' => [ 'data4' ],
129  'identifier3' => [ 'data3' ],
130  'identifier2' => [ 'data2' ],
131  'identifier1' => [ 'data1' ],
132  ]);
133 
134  $expectedOpenDocumentsData = [
135  [
136  'identifier8' => [ 'data8' ],
137  ],
138  'identifier9',
139  ];
140  $this->backendUser->pushModuleData('FormEngine', $expectedOpenDocumentsData)->shouldBeCalled();
141 
142  $expectedRecentDocumentsData = [
143  'identifier9' => [ 'data9' ],
144  'identifier8' => [ 'data8' ],
145  'identifier7' => [ 'data7' ],
146  'identifier6' => [ 'data6' ],
147  'identifier5' => [ 'data5' ],
148  'identifier4' => [ 'data4' ],
149  'identifier3' => [ 'data3' ],
150  'identifier2' => [ 'data2' ],
151  ];
152  $this->backendUser->pushModuleData('opendocs::recent', $expectedRecentDocumentsData)->shouldBeCalled();
153 
154  $this->subject->closeDocument('identifier9');
155  $this->subject->closeDocument('identifier9');
156  $this->subject->closeDocument('unknownIdentifier');
157  }
158 }
‪TYPO3\CMS\Opendocs\Tests\Unit\Service\OpenDocumentServiceTest\handlesUserSessionWithoutRecentDocuments
‪handlesUserSessionWithoutRecentDocuments()
Definition: OpenDocumentServiceTest.php:101
‪TYPO3\CMS\Opendocs\Tests\Unit\Service\OpenDocumentServiceTest\$backendUser
‪ObjectProphecy $backendUser
Definition: OpenDocumentServiceTest.php:35
‪TYPO3\CMS\Opendocs\Tests\Unit\Service\OpenDocumentServiceTest
Definition: OpenDocumentServiceTest.php:30
‪TYPO3\CMS\Opendocs\Tests\Unit\Service\OpenDocumentServiceTest\handlesUserSessionWithoutOpenDocuments
‪handlesUserSessionWithoutOpenDocuments()
Definition: OpenDocumentServiceTest.php:72
‪TYPO3\CMS\Opendocs\Tests\Unit\Service\OpenDocumentServiceTest\setUp
‪setUp()
Definition: OpenDocumentServiceTest.php:40
‪TYPO3\CMS\Opendocs\Tests\Unit\Service\OpenDocumentServiceTest\getsOpenDocumentsFromUserSession
‪getsOpenDocumentsFromUserSession()
Definition: OpenDocumentServiceTest.php:50
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService
Definition: OpenDocumentService.php:27
‪TYPO3\CMS\Opendocs\Tests\Unit\Service\OpenDocumentServiceTest\closesDocument
‪closesDocument()
Definition: OpenDocumentServiceTest.php:113
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Opendocs\Tests\Unit\Service\OpenDocumentServiceTest\getsRecentDocumentsFromUserSession
‪getsRecentDocumentsFromUserSession()
Definition: OpenDocumentServiceTest.php:84
‪TYPO3\CMS\Opendocs\Tests\Unit\Service
Definition: OpenDocumentServiceTest.php:18
‪TYPO3\CMS\Opendocs\Tests\Unit\Service\OpenDocumentServiceTest\$subject
‪OpenDocumentService $subject
Definition: OpenDocumentServiceTest.php:32