‪TYPO3CMS  11.5
DatabaseParentPageRowTest.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 PHPUnit\Framework\MockObject\MockObject;
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪DatabaseParentPageRowTest extends UnitTestCase
28 {
32  protected MockObject ‪$subject;
33 
34  protected function ‪setUp(): void
35  {
36  parent::setUp();
37  $this->subject = $this->getMockBuilder(DatabaseParentPageRow::class)
38  ->onlyMethods(['getDatabaseRow'])
39  ->getMock();
40  }
41 
46  {
47  $input = [
48  'tableName' => 'tt_content',
49  'command' => 'new',
50  'vanillaUid' => -10,
51  ];
52  $parentPageRow = [
53  'uid' => 123,
54  'pid' => 321,
55  ];
56 
57  $this->subject->expects(self::exactly(2))
58  ->method('getDatabaseRow')
59  ->withConsecutive([$input['tableName'], 10], ['pages', 123])
60  ->willReturnOnConsecutiveCalls(['pid' => 123], $parentPageRow);
61 
62  $result = $this->subject->addData($input);
63 
64  self::assertSame($parentPageRow, $result['parentPageRow']);
65  }
66 
71  {
72  $input = [
73  'tableName' => 'tt_content',
74  'command' => 'new',
75  'vanillaUid' => -10,
76  ];
77  $neighborRow = [
78  'uid' => 10,
79  'pid' => 321,
80  ];
81  $parentPageRow = [
82  'uid' => 123,
83  'pid' => 321,
84  ];
85  $this->subject->expects(self::exactly(2))
86  ->method('getDatabaseRow')
87  ->withConsecutive([$input['tableName'], 10], ['pages', 321])
88  ->willReturnOnConsecutiveCalls($neighborRow, $parentPageRow);
89 
90  $result = $this->subject->addData($input);
91 
92  self::assertSame($neighborRow, $result['neighborRow']);
93  }
94 
99  {
100  $input = [
101  'tableName' => 'tt_content',
102  'command' => 'new',
103  'vanillaUid' => -10,
104  ];
105 
106  $this->subject->expects(self::once())
107  ->method('getDatabaseRow')
108  ->with($input['tableName'], 10)
109  ->willReturn(['pid' => 0]);
110 
111  $result = $this->subject->addData($input);
112 
113  self::assertNull($result['parentPageRow']);
114  }
115 
120  {
121  $input = [
122  'tableName' => 'tt_content',
123  'command' => 'new',
124  'vanillaUid' => 123,
125  ];
126  $parentPageRow = [
127  'uid' => 123,
128  'pid' => 321,
129  ];
130 
131  $this->subject->expects(self::once())
132  ->method('getDatabaseRow')
133  ->with('pages', 123)
134  ->willReturn($parentPageRow);
135 
136  $result = $this->subject->addData($input);
137 
138  self::assertSame($parentPageRow, $result['parentPageRow']);
139  }
140 
145  {
146  $input = [
147  'tableName' => 'tt_content',
148  'command' => 'edit',
149  'vanillaUid' => 123,
150  'databaseRow' => [
151  'uid' => 123,
152  'pid' => 321,
153  ],
154  ];
155  $parentPageRow = [
156  'uid' => 321,
157  'pid' => 456,
158  ];
159  $this->subject->expects(self::once())
160  ->method('getDatabaseRow')
161  ->with('pages', 321)
162  ->willReturn($parentPageRow);
163 
164  $result = $this->subject->addData($input);
165 
166  self::assertSame($parentPageRow, $result['parentPageRow']);
167  }
168 
173  {
174  $input = [
175  'tableName' => 'tt_content',
176  'command' => 'new',
177  'vanillaUid' => 'NEW123',
178  'databaseRow' => [],
179  ];
180 
181  $this->subject->expects(self::never())->method('getDatabaseRow');
182 
183  $result = $this->subject->addData($input);
184 
185  self::assertNull($result['parentPageRow']);
186  }
187 
192  {
193  $input = [
194  'tableName' => 'tt_content',
195  'command' => 'new',
196  'vanillaUid' => 0,
197  'databaseRow' => [],
198  ];
199 
200  $this->subject->expects(self::never())->method('getDatabaseRow');
201 
202  $result = $this->subject->addData($input);
203 
204  self::assertNull($result['parentPageRow']);
205  }
206 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseParentPageRowTest\addDataSetsParentPageRowOnParentIfCommandIsEdit
‪addDataSetsParentPageRowOnParentIfCommandIsEdit()
Definition: DatabaseParentPageRowTest.php:144
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseParentPageRowTest\addDataSetsParentPageToGivenPageIdIfCommandIsNew
‪addDataSetsParentPageToGivenPageIdIfCommandIsNew()
Definition: DatabaseParentPageRowTest.php:119
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseParentPageRowTest\addDataFetchesParentPageRowOfRecordIfNeighbourGiven
‪addDataFetchesParentPageRowOfRecordIfNeighbourGiven()
Definition: DatabaseParentPageRowTest.php:45
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseParentPageRowTest\addDataSetsNeighborRowIfNegativeUidGiven
‪addDataSetsNeighborRowIfNegativeUidGiven()
Definition: DatabaseParentPageRowTest.php:70
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseParentPageRowTest\addDataSetsParentPageRowOnNullWithZero
‪addDataSetsParentPageRowOnNullWithZero()
Definition: DatabaseParentPageRowTest.php:191
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseParentPageRowTest\addDataSetsParentPageRowToNullIfParentIsRoot
‪addDataSetsParentPageRowToNullIfParentIsRoot()
Definition: DatabaseParentPageRowTest.php:98
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseParentPageRowTest\setUp
‪setUp()
Definition: DatabaseParentPageRowTest.php:34
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseParentPageRowTest
Definition: DatabaseParentPageRowTest.php:28
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseParentPageRowTest\addDataSetsParentPageRowOnNullWithNew
‪addDataSetsParentPageRowOnNullWithNew()
Definition: DatabaseParentPageRowTest.php:172
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseParentPageRow
Definition: DatabaseParentPageRow.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseParentPageRowTest\$subject
‪MockObject $subject
Definition: DatabaseParentPageRowTest.php:32
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18