TYPO3 CMS  TYPO3_8-7
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 
21 
25 class DatabaseEditRowTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
26 {
30  protected $subject;
31 
35  protected $dbProphecy;
36 
37  protected function setUp()
38  {
39  $this->subject = $this->getMockBuilder(DatabaseEditRow::class)
40  ->setMethods(['getDatabaseRow'])
41  ->getMock();
42  }
43 
48  {
49  $input = [
50  'tableName' => 'tt_content',
51  'command' => 'edit',
52  'vanillaUid' => 10,
53  ];
54  $resultRow = [
55  'uid' => 10,
56  'pid' => 123
57  ];
58  $this->subject->expects($this->once())->method('getDatabaseRow')->willReturn($resultRow);
59 
60  $result = $this->subject->addData($input);
61 
62  $this->assertSame($resultRow, $result['databaseRow']);
63  }
64 
69  {
70  $input = [
71  'tableName' => 'tt_content',
72  'command' => 'edit',
73  'vanillaUid' => 10,
74  ];
75  $resultRow = [
76  'uid' => 10,
77  ];
78  $this->subject->expects($this->once())->method('getDatabaseRow')->willReturn($resultRow);
79 
80  $this->expectException(\UnexpectedValueException::class);
81  $this->expectExceptionCode(1437663061);
82 
83  $this->subject->addData($input);
84  }
85 
90  {
91  $input = [
92  'tableName' => 'tt_content',
93  'command' => 'edit',
94  'vanillaUid' => -10,
95  ];
96 
97  $this->expectException(\InvalidArgumentException::class);
98  $this->expectExceptionCode(1437656456);
99 
100  $this->subject->addData($input);
101  }
102 
107  {
108  $input = [
109  'tableName' => 'tt_content',
110  'command' => 'edit',
111  'vanillaUid' => 10,
112  ];
113  $this->subject->expects($this->once())->method('getDatabaseRow')->willReturn([]);
114 
115  $this->expectException(DatabaseRecordException::class);
116  $this->expectExceptionCode(1437656081);
117 
118  $this->subject->addData($input);
119  }
120 
125  {
126  $input = [
127  'tableName' => 'tt_content',
128  'command' => 'edit',
129  'vanillaUid' => 10,
130  ];
131  $this->subject->expects($this->once())->method('getDatabaseRow')->willReturn([]);
132 
133  try {
134  $this->subject->addData($input);
135  } catch (DatabaseRecordException $e) {
136  $this->assertSame('tt_content', $e->getTableName());
137  $this->assertSame(10, $e->getUid());
138  }
139  }
140 
145  {
146  $virtualRow = [
147  'uid' => 10,
148  'pid' => 123,
149  'title' => 'Title of the virtual record'
150  ];
151  $input = [
152  'tableName' => 'virtual_table',
153  'command' => 'edit',
154  'vanillaUid' => 10,
155  'databaseRow' => $virtualRow
156  ];
157  $resultRow = $virtualRow;
158  $this->subject->expects($this->never())->method('getDatabaseRow');
159 
160  $result = $this->subject->addData($input);
161 
162  $this->assertSame($resultRow, $result['databaseRow']);
163  }
164 }