‪TYPO3CMS  9.5
DatabaseEditRowTest.php
Go to the documentation of this file.
1 <?php
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 
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20 
24 class ‪DatabaseEditRowTest extends UnitTestCase
25 {
29  protected ‪$subject;
30 
31  protected function ‪setUp()
32  {
33  $this->subject = $this->getMockBuilder(DatabaseEditRow::class)
34  ->setMethods(['getDatabaseRow'])
35  ->getMock();
36  }
37 
42  {
43  $input = [
44  'tableName' => 'tt_content',
45  'command' => 'edit',
46  'vanillaUid' => 10,
47  ];
48  $resultRow = [
49  'uid' => 10,
50  'pid' => 123
51  ];
52  $this->subject->expects($this->once())->method('getDatabaseRow')->willReturn($resultRow);
53 
54  $result = $this->subject->addData($input);
55 
56  $this->assertSame($resultRow, $result['databaseRow']);
57  }
58 
63  {
64  $input = [
65  'tableName' => 'tt_content',
66  'command' => 'edit',
67  'vanillaUid' => 10,
68  ];
69  $resultRow = [
70  'uid' => 10,
71  ];
72  $this->subject->expects($this->once())->method('getDatabaseRow')->willReturn($resultRow);
73 
74  $this->expectException(\UnexpectedValueException::class);
75  $this->expectExceptionCode(1437663061);
76 
77  $this->subject->addData($input);
78  }
79 
84  {
85  $input = [
86  'tableName' => 'tt_content',
87  'command' => 'edit',
88  'vanillaUid' => -10,
89  ];
90 
91  $this->expectException(\InvalidArgumentException::class);
92  $this->expectExceptionCode(1437656456);
93 
94  $this->subject->addData($input);
95  }
96 
101  {
102  $input = [
103  'tableName' => 'tt_content',
104  'command' => 'edit',
105  'vanillaUid' => 10,
106  ];
107  $this->subject->expects($this->once())->method('getDatabaseRow')->willReturn([]);
108 
109  $this->expectException(DatabaseRecordException::class);
110  $this->expectExceptionCode(1437656081);
111 
112  $this->subject->addData($input);
113  }
114 
119  {
120  $input = [
121  'tableName' => 'tt_content',
122  'command' => 'edit',
123  'vanillaUid' => 10,
124  ];
125  $this->subject->expects($this->once())->method('getDatabaseRow')->willReturn([]);
126 
127  try {
128  $this->subject->addData($input);
129  } catch (DatabaseRecordException $e) {
130  $this->assertSame('tt_content', $e->getTableName());
131  $this->assertSame(10, $e->getUid());
132  }
133  }
134 
139  {
140  $virtualRow = [
141  'uid' => 10,
142  'pid' => 123,
143  'title' => 'Title of the virtual record'
144  ];
145  $input = [
146  'tableName' => 'virtual_table',
147  'command' => 'edit',
148  'vanillaUid' => 10,
149  'databaseRow' => $virtualRow
150  ];
151  $resultRow = $virtualRow;
152  $this->subject->expects($this->never())->method('getDatabaseRow');
153 
154  $result = $this->subject->addData($input);
155 
156  $this->assertSame($resultRow, $result['databaseRow']);
157  }
158 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseEditRow
Definition: DatabaseEditRow.php:24
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\addDataThrowsExceptionIfRetrievedRowHasNoPid
‪addDataThrowsExceptionIfRetrievedRowHasNoPid()
Definition: DatabaseEditRowTest.php:61
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\addDataSkipsDatabaseLookupIfDatabaseRowIsPopulated
‪addDataSkipsDatabaseLookupIfDatabaseRowIsPopulated()
Definition: DatabaseEditRowTest.php:137
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\setUp
‪setUp()
Definition: DatabaseEditRowTest.php:30
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\addDataThrowsExceptionIfDatabaseFetchingReturnsNoRow
‪addDataThrowsExceptionIfDatabaseFetchingReturnsNoRow()
Definition: DatabaseEditRowTest.php:99
‪TYPO3\CMS\Backend\Form\Exception\DatabaseRecordException\getUid
‪int getUid()
Definition: DatabaseRecordException.php:63
‪TYPO3\CMS\Backend\Form\Exception\DatabaseRecordException\getTableName
‪string getTableName()
Definition: DatabaseRecordException.php:53
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\addDataThrowsExceptionIfGivenUidIsNotPositive
‪addDataThrowsExceptionIfGivenUidIsNotPositive()
Definition: DatabaseEditRowTest.php:82
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\addDataThrowsExceptionDatabaseRecordExceptionWithAdditionalInformationSet
‪addDataThrowsExceptionDatabaseRecordExceptionWithAdditionalInformationSet()
Definition: DatabaseEditRowTest.php:117
‪TYPO3\CMS\Backend\Form\Exception\DatabaseRecordException
Definition: DatabaseRecordException.php:23
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\addDataRetrievesRecordInformationFromDatabase
‪addDataRetrievesRecordInformationFromDatabase()
Definition: DatabaseEditRowTest.php:40
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest
Definition: DatabaseEditRowTest.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\$subject
‪DatabaseEditRow PHPUnit_Framework_MockObject_MockObject $subject
Definition: DatabaseEditRowTest.php:28
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:3