[BUGFIX] Notice free FormEngine testing
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / DatabaseDefaultLanguagePageRowTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
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
18 use TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseDefaultLanguagePageRow;
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20
21 /**
22 * Test case
23 */
24 class DatabaseDefaultLanguagePageRowTest extends UnitTestCase
25 {
26 /**
27 * @var DatabaseDefaultLanguagePageRow|\PHPUnit_Framework_MockObject_MockObject
28 */
29 protected $subject;
30
31 protected function setUp()
32 {
33 $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'] = 'l10n_parent';
34 $this->subject = $this->getMockBuilder(DatabaseDefaultLanguagePageRow::class)
35 ->setMethods(['getDatabaseRow'])
36 ->getMock();
37 }
38
39 /**
40 * @test
41 */
42 public function addDataDoesNotApplyToAnyNonPagesTable()
43 {
44 $input = [
45 'tableName' => 'tx_doandroidsdreamofelectricsheep',
46 'databaseRow' => [
47 'uid' => 23,
48 'l10n_parent' => 13,
49 'sys_language_uid' => 23
50 ]
51 ];
52 $result = $this->subject->addData($input);
53
54 $this->assertArrayNotHasKey('defaultLanguagePageRow', $result);
55 }
56
57 /**
58 * @test
59 */
60 public function addDataDoesApplyToAPagesTableButNoChangeForDefaultLanguage()
61 {
62 $input = [
63 'tableName' => 'pages',
64 'databaseRow' => [
65 'uid' => 23,
66 'l10n_parent' => 0,
67 'sys_language_uid' => 0
68 ]
69 ];
70 $result = $this->subject->addData($input);
71 $this->assertSame($input, $result);
72 }
73
74 /**
75 * @test
76 */
77 public function addDataDoesApplyToATranslatedPagesTable()
78 {
79 $input = [
80 'tableName' => 'pages',
81 'databaseRow' => [
82 'uid' => 23,
83 'pid' => 1,
84 'l10n_parent' => 13,
85 'sys_language_uid' => 8
86 ]
87 ];
88
89 $defaultLanguagePageRow = [
90 'uid' => 13,
91 'pid' => 1,
92 'sys_language_uid' => 0,
93 'l10n_parent' => 0
94 ];
95
96 $this->subject->expects($this->once())
97 ->method('getDatabaseRow')
98 ->with($input['tableName'], 13)
99 ->willReturn($defaultLanguagePageRow);
100
101 $result = $this->subject->addData($input);
102 $this->assertEquals($defaultLanguagePageRow, $result['defaultLanguagePageRow']);
103 }
104 }