TYPO3  7.6
DatabaseEditRowTest.php
Go to the documentation of this file.
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 Prophecy\Argument;
18 use Prophecy\Prophecy\ObjectProphecy;
19 use TYPO3\CMS\Backend\Form\Exception\DatabaseRecordException;
22 use TYPO3\CMS\Core\Tests\UnitTestCase;
23 
27 class DatabaseEditRowTest extends UnitTestCase
28 {
32  protected $subject;
33 
37  protected $dbProphecy;
38 
39  protected function setUp()
40  {
41  $this->dbProphecy = $this->prophesize(DatabaseConnection::class);
42  $GLOBALS['TYPO3_DB'] = $this->dbProphecy->reveal();
43 
44  $this->subject = new DatabaseEditRow();
45  }
46 
51  {
52  $input = [
53  'tableName' => 'tt_content',
54  'command' => 'edit',
55  'vanillaUid' => 10,
56  ];
57  $resultRow = [
58  'uid' => 10,
59  'pid' => 123
60  ];
61  $this->dbProphecy->quoteStr($input['tableName'], $input['tableName'])->willReturn($input['tableName']);
62  $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=' . $input['vanillaUid'])->willReturn($resultRow);
63  $this->dbProphecy->exec_SELECTgetSingleRow(Argument::cetera())->willReturn([]);
64 
65  $result = $this->subject->addData($input);
66 
67  $this->assertSame($resultRow, $result['databaseRow']);
68  }
69 
74  {
75  $input = [
76  'tableName' => 'tt_content',
77  'command' => 'edit',
78  'vanillaUid' => 10,
79  ];
80  $resultRow = [
81  'uid' => 10,
82  ];
83  $this->dbProphecy->quoteStr($input['tableName'], $input['tableName'])->willReturn($input['tableName']);
84  $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=' . $input['vanillaUid'])->willReturn($resultRow);
85 
86  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1437663061);
87 
88  $this->subject->addData($input);
89  }
90 
95  {
96  $input = [
97  'tableName' => 'tt_content',
98  'command' => 'edit',
99  'vanillaUid' => -10,
100  ];
101 
102  $this->setExpectedException(\InvalidArgumentException::class, $this->anything(), 1437656456);
103 
104  $this->subject->addData($input);
105  }
106 
111  {
112  $input = [
113  'tableName' => 'tt_content',
114  'command' => 'edit',
115  'vanillaUid' => 10,
116  ];
117 
118  $this->setExpectedException(\RuntimeException::class, $this->anything(), 1437655862);
119 
120  $this->subject->addData($input);
121  }
122 
127  {
128  $input = [
129  'tableName' => 'tt_content',
130  'command' => 'edit',
131  'vanillaUid' => 10,
132  ];
133  $this->dbProphecy->quoteStr(Argument::cetera())->willReturn($input['tableName']);
134  $this->dbProphecy->exec_SELECTgetSingleRow(Argument::cetera())->willReturn(false);
135 
136  $this->setExpectedException(DatabaseRecordException::class, $this->anything(), 1437656081);
137 
138  $this->subject->addData($input);
139  }
140 
145  {
146  $input = [
147  'tableName' => 'tt_content',
148  'command' => 'edit',
149  'vanillaUid' => 10,
150  ];
151  $this->dbProphecy->quoteStr(Argument::cetera())->willReturn($input['tableName']);
152  $this->dbProphecy->exec_SELECTgetSingleRow(Argument::cetera())->willReturn('invalid result data');
153 
154  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1437656323);
155 
156  $this->subject->addData($input);
157  }
158 }