[TASK] Update @typo3/icons to 1.10.0
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / DatabaseParentPageRowTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseParentPageRow;
18 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
19
20 /**
21 * Test case
22 */
23 class DatabaseParentPageRowTest extends UnitTestCase
24 {
25 /**
26 * @var DatabaseParentPageRow|\PHPUnit_Framework_MockObject_MockObject
27 */
28 protected $subject;
29
30 protected function setUp(): void
31 {
32 $this->subject = $this->getMockBuilder(DatabaseParentPageRow::class)
33 ->setMethods(['getDatabaseRow'])
34 ->getMock();
35 }
36
37 /**
38 * @test
39 */
40 public function addDataFetchesParentPageRowOfRecordIfNeighbourGiven()
41 {
42 $input = [
43 'tableName' => 'tt_content',
44 'command' => 'new',
45 'vanillaUid' => -10,
46 ];
47 $parentPageRow = [
48 'uid' => 123,
49 'pid' => 321
50 ];
51
52 $this->subject->expects($this->at(0))
53 ->method('getDatabaseRow')
54 ->with($input['tableName'], 10)
55 ->willReturn(['pid' => 123]);
56
57 $this->subject->expects($this->at(1))
58 ->method('getDatabaseRow')
59 ->with('pages', 123)
60 ->willReturn($parentPageRow);
61
62 $result = $this->subject->addData($input);
63
64 $this->assertSame($parentPageRow, $result['parentPageRow']);
65 }
66
67 /**
68 * @test
69 */
70 public function addDataSetsNeigborRowIfNegativeUidGiven()
71 {
72 $input = [
73 'tableName' => 'tt_content',
74 'command' => 'new',
75 'vanillaUid' => -10,
76 ];
77 $neigborRow = [
78 'uid' => 10,
79 'pid' => 321
80 ];
81 $parentPageRow = [
82 'uid' => 123,
83 'pid' => 321
84 ];
85 $this->subject->expects($this->at(0))
86 ->method('getDatabaseRow')
87 ->with($input['tableName'], 10)
88 ->willReturn($neigborRow);
89
90 $this->subject->expects($this->at(1))
91 ->method('getDatabaseRow')
92 ->with('pages', 321)
93 ->willReturn($parentPageRow);
94
95 $result = $this->subject->addData($input);
96
97 $this->assertSame($neigborRow, $result['neighborRow']);
98 }
99
100 /**
101 * @test
102 */
103 public function addDataSetsParentPageRowToNullIfParentIsRoot()
104 {
105 $input = [
106 'tableName' => 'tt_content',
107 'command' => 'new',
108 'vanillaUid' => -10,
109 ];
110
111 $this->subject->expects($this->once())
112 ->method('getDatabaseRow')
113 ->with($input['tableName'], 10)
114 ->willReturn(['pid' => 0]);
115
116 $result = $this->subject->addData($input);
117
118 $this->assertNull($result['parentPageRow']);
119 }
120
121 /**
122 * @test
123 */
124 public function addDataSetsParentPageToGivenPageIdIfCommandIsNew()
125 {
126 $input = [
127 'tableName' => 'tt_content',
128 'command' => 'new',
129 'vanillaUid' => 123,
130 ];
131 $parentPageRow = [
132 'uid' => 123,
133 'pid' => 321
134 ];
135
136 $this->subject->expects($this->once())
137 ->method('getDatabaseRow')
138 ->with('pages', 123)
139 ->willReturn($parentPageRow);
140
141 $result = $this->subject->addData($input);
142
143 $this->assertSame($parentPageRow, $result['parentPageRow']);
144 }
145
146 /**
147 * @test
148 */
149 public function addDataSetsParentPageRowOnParentIfCommandIsEdit()
150 {
151 $input = [
152 'tableName' => 'tt_content',
153 'command' => 'edit',
154 'vanillaUid' => 123,
155 'databaseRow' => [
156 'uid' => 123,
157 'pid' => 321
158 ],
159 ];
160 $parentPageRow = [
161 'uid' => 321,
162 'pid' => 456
163 ];
164 $this->subject->expects($this->once())
165 ->method('getDatabaseRow')
166 ->with('pages', 321)
167 ->willReturn($parentPageRow);
168
169 $result = $this->subject->addData($input);
170
171 $this->assertSame($parentPageRow, $result['parentPageRow']);
172 }
173 }