‪TYPO3CMS  10.4
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 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪OpenDocumentServiceTest extends UnitTestCase
28 {
32  protected ‪$subject;
33 
37  protected ‪$backendUser;
38 
42  protected function ‪setUp(): void
43  {
44  parent::setUp();
45  $this->backendUser = $this->prophesize(BackendUserAuthentication::class);
46  $this->subject = new ‪OpenDocumentService($this->backendUser->reveal());
47  }
48 
52  public function ‪getsOpenDocumentsFromUserSession()
53  {
54  $this->backendUser->getModuleData('FormEngine', 'ses')->willReturn([
55  [
56  'identifier1' => [ 'data1' ],
57  'identifier2' => [ 'data2' ],
58  ],
59  'identifier2',
60  ]);
61 
62  $openDocuments = $this->subject->getOpenDocuments();
63  $expected = [
64  'identifier1' => [ 'data1' ],
65  'identifier2' => [ 'data2' ],
66  ];
67 
68  self::assertEquals($expected, $openDocuments);
69  }
70 
75  {
76  $this->backendUser->getModuleData('FormEngine', 'ses')->willReturn();
77 
78  $openDocuments = $this->subject->getOpenDocuments();
79 
80  self::assertEquals([], $openDocuments);
81  }
82 
87  {
88  $this->backendUser->getModuleData('opendocs::recent')->willReturn([
89  'identifier1' => [ 'data1' ],
90  ]);
91 
92  $recentDocuments = $this->subject->getRecentDocuments();
93  $expected = [
94  'identifier1' => [ 'data1' ],
95  ];
96 
97  self::assertEquals($expected, $recentDocuments);
98  }
99 
104  {
105  $this->backendUser->getModuleData('opendocs::recent')->willReturn();
106 
107  $recentDocuments = $this->subject->getRecentDocuments();
108 
109  self::assertEquals([], $recentDocuments);
110  }
111 
115  public function ‪closesDocument()
116  {
117  $this->backendUser->getModuleData('FormEngine', 'ses')->willReturn([
118  [
119  'identifier8' => [ 'data8' ],
120  'identifier9' => [ 'data9' ],
121  ],
122  'identifier9',
123  ]);
124  $this->backendUser->getModuleData('opendocs::recent')->willReturn([
125  'identifier8' => [ 'data8' ],
126  'identifier7' => [ 'data7' ],
127  'identifier6' => [ 'data6' ],
128  'identifier5' => [ 'data5' ],
129  'identifier4' => [ 'data4' ],
130  'identifier3' => [ 'data3' ],
131  'identifier2' => [ 'data2' ],
132  'identifier1' => [ 'data1' ],
133  ]);
134 
135  $expectedOpenDocumentsData = [
136  [
137  'identifier8' => [ 'data8' ],
138  ],
139  'identifier9',
140  ];
141  $this->backendUser->pushModuleData('FormEngine', $expectedOpenDocumentsData)->shouldBeCalled();
142 
143  $expectedRecentDocumentsData = [
144  'identifier9' => [ 'data9' ],
145  'identifier8' => [ 'data8' ],
146  'identifier7' => [ 'data7' ],
147  'identifier6' => [ 'data6' ],
148  'identifier5' => [ 'data5' ],
149  'identifier4' => [ 'data4' ],
150  'identifier3' => [ 'data3' ],
151  'identifier2' => [ 'data2' ],
152  ];
153  $this->backendUser->pushModuleData('opendocs::recent', $expectedRecentDocumentsData)->shouldBeCalled();
154 
155  $this->subject->closeDocument('identifier9');
156  $this->subject->closeDocument('identifier9');
157  $this->subject->closeDocument('unknownIdentifier');
158  }
159 }
‪TYPO3\CMS\Opendocs\Tests\Unit\Service\OpenDocumentServiceTest\handlesUserSessionWithoutRecentDocuments
‪handlesUserSessionWithoutRecentDocuments()
Definition: OpenDocumentServiceTest.php:101
‪TYPO3\CMS\Opendocs\Tests\Unit\Service\OpenDocumentServiceTest\$backendUser
‪BackendUserAuthentication Prophecy Prophecy ObjectProphecy $backendUser
Definition: OpenDocumentServiceTest.php:35
‪TYPO3\CMS\Opendocs\Tests\Unit\Service\OpenDocumentServiceTest
Definition: OpenDocumentServiceTest.php:28
‪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:31