[!!!][TASK] Move TYPO3_DB to extension
[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
19 /**
20 * Test case
21 */
22 class DatabaseParentPageRowTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
23 {
24 /**
25 * @var DatabaseParentPageRow|\PHPUnit_Framework_MockObject_MockObject
26 */
27 protected $subject;
28
29 protected function setUp()
30 {
31 $this->subject = $this->getMockBuilder(DatabaseParentPageRow::class)
32 ->setMethods(['getDatabaseRow'])
33 ->getMock();
34 }
35
36 /**
37 * @test
38 */
39 public function addDataFetchesParentPageRowOfRecordIfNeighbourGiven()
40 {
41 $input = [
42 'tableName' => 'tt_content',
43 'command' => 'new',
44 'vanillaUid' => -10,
45 ];
46 $parentPageRow = [
47 'uid' => 123,
48 'pid' => 321
49 ];
50
51 $this->subject->expects($this->at(0))
52 ->method('getDatabaseRow')
53 ->with($input['tableName'], 10)
54 ->willReturn(['pid' => 123]);
55
56 $this->subject->expects($this->at(1))
57 ->method('getDatabaseRow')
58 ->with('pages', 123)
59 ->willReturn($parentPageRow);
60
61 $result = $this->subject->addData($input);
62
63 $this->assertSame($parentPageRow, $result['parentPageRow']);
64 }
65
66 /**
67 * @test
68 */
69 public function addDataSetsNeigborRowIfNegativeUidGiven()
70 {
71 $input = [
72 'tableName' => 'tt_content',
73 'command' => 'new',
74 'vanillaUid' => -10,
75 ];
76 $neigborRow = [
77 'uid' => 10,
78 'pid' => 321
79 ];
80 $parentPageRow = [
81 'uid' => 123,
82 'pid' => 321
83 ];
84 $this->subject->expects($this->at(0))
85 ->method('getDatabaseRow')
86 ->with($input['tableName'], 10)
87 ->willReturn($neigborRow);
88
89 $this->subject->expects($this->at(1))
90 ->method('getDatabaseRow')
91 ->with('pages', 321)
92 ->willReturn($parentPageRow);
93
94 $result = $this->subject->addData($input);
95
96 $this->assertSame($neigborRow, $result['neighborRow']);
97 }
98
99 /**
100 * @test
101 */
102 public function addDataSetsParentPageRowToNullIfParentIsRoot()
103 {
104 $input = [
105 'tableName' => 'tt_content',
106 'command' => 'new',
107 'vanillaUid' => -10,
108 ];
109
110 $this->subject->expects($this->once())
111 ->method('getDatabaseRow')
112 ->with($input['tableName'], 10)
113 ->willReturn(['pid' => 0]);
114
115 $result = $this->subject->addData($input);
116
117 $this->assertNull($result['parentPageRow']);
118 }
119
120 /**
121 * @test
122 */
123 public function addDataSetsParentPageToGivenPageIdIfCommandIsNew()
124 {
125 $input = [
126 'tableName' => 'tt_content',
127 'command' => 'new',
128 'vanillaUid' => 123,
129 ];
130 $parentPageRow = [
131 'uid' => 123,
132 'pid' => 321
133 ];
134
135 $this->subject->expects($this->once())
136 ->method('getDatabaseRow')
137 ->with('pages', 123)
138 ->willReturn($parentPageRow);
139
140 $result = $this->subject->addData($input);
141
142 $this->assertSame($parentPageRow, $result['parentPageRow']);
143 }
144
145 /**
146 * @test
147 */
148 public function addDataSetsParentPageRowOnParentIfCommandIsEdit()
149 {
150 $input = [
151 'tableName' => 'tt_content',
152 'command' => 'edit',
153 'vanillaUid' => 123,
154 'databaseRow' => [
155 'uid' => 123,
156 'pid' => 321
157 ],
158 ];
159 $parentPageRow = [
160 'uid' => 321,
161 'pid' => 456
162 ];
163 $this->subject->expects($this->once())
164 ->method('getDatabaseRow')
165 ->with('pages', 321)
166 ->willReturn($parentPageRow);
167
168 $result = $this->subject->addData($input);
169
170 $this->assertSame($parentPageRow, $result['parentPageRow']);
171 }
172 }