[TASK] Make TYPO3 Core PSR-2 standard compliant
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / DatabaseEffectivePidTest.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\Core\Tests\UnitTestCase;
18 use TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseEffectivePid;
19
20 /**
21 * Test case
22 */
23 class DatabaseEffectivePidTest extends UnitTestCase
24 {
25 /**
26 * @var DatabaseEffectivePid
27 */
28 protected $subject;
29
30 protected function setUp()
31 {
32 $this->subject = new DatabaseEffectivePid();
33 }
34
35 /**
36 * @test
37 */
38 public function addDataSetsUidOfRecordIsPageIsEdited()
39 {
40 $input = [
41 'command' => 'edit',
42 'tableName' => 'pages',
43 'databaseRow' => [
44 'uid' => 123,
45 ],
46 ];
47 $expected = $input;
48 $expected['effectivePid'] = 123;
49 $this->assertSame($expected, $this->subject->addData($input));
50 }
51
52 /**
53 * @test
54 */
55 public function addDataSetsPidOfRecordIfNoPageIsEdited()
56 {
57 $input = [
58 'command' => 'edit',
59 'tableName' => 'tt_content',
60 'databaseRow' => [
61 'pid' => 123,
62 ],
63 ];
64 $expected = $input;
65 $expected['effectivePid'] = 123;
66 $this->assertSame($expected, $this->subject->addData($input));
67 }
68
69 /**
70 * @test
71 */
72 public function addDataSetsUidOfParentPageRowIfParentPageRowExistsAndCommandIsNew()
73 {
74 $input = [
75 'command' => 'new',
76 'tableName' => 'tt_content',
77 'parentPageRow' => [
78 'uid' => 123
79 ],
80 ];
81 $expected = $input;
82 $expected['effectivePid'] = 123;
83 $this->assertSame($expected, $this->subject->addData($input));
84 }
85
86 /**
87 * @test
88 */
89 public function addDataSetsZeroWithMissingParentPageRowAndCommandIsNew()
90 {
91 $input = [
92 'command' => 'new',
93 'tableName' => 'pages',
94 'parentPageRow' => null,
95 ];
96 $expected = $input;
97 $expected['effectivePid'] = 0;
98 $this->assertSame($expected, $this->subject->addData($input));
99 }
100 }