‪TYPO3CMS  ‪main
DatabaseUniqueUidNewRowTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
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 
19 
20 use PHPUnit\Framework\Attributes\Test;
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
24 final class ‪DatabaseUniqueUidNewRowTest extends UnitTestCase
25 {
27 
28  protected function ‪setUp(): void
29  {
30  parent::setUp();
31  $this->subject = new ‪DatabaseUniqueUidNewRow();
32  }
33 
34  #[Test]
36  {
37  $input = [
38  'command' => 'edit',
39  'databaseRow' => [
40  'uid' => 42,
41  ],
42  ];
43  self::assertSame($input, $this->subject->addData($input));
44  }
45 
46  #[Test]
47  public function ‪addDataKeepsGivenUidIfAlreadySet(): void
48  {
49  $input = [
50  'command' => 'new',
51  'databaseRow' => [
52  'uid' => 'NEW1234',
53  ],
54  ];
55  $expected = $input;
56  self::assertEquals($expected, $this->subject->addData($input));
57  }
58 
59  #[Test]
61  {
62  $input = [
63  'command' => 'new',
64  'databaseRow' => [
65  'uid' => 'FOO',
66  ],
67  ];
68  $this->expectException(\InvalidArgumentException::class);
69  $this->expectExceptionCode(1437991120);
70  $this->subject->addData($input);
71  }
72 
73  #[Test]
74  public function ‪addDataSetsUniqueId(): void
75  {
76  $input = [
77  'command' => 'new',
78  'databaseRow' => [],
79  ];
80  $result = $this->subject->addData($input);
81  $result = substr($result['databaseRow']['uid'], 0, 3);
82  self::assertSame('NEW', $result);
83  }
84 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseUniqueUidNewRowTest\setUp
‪setUp()
Definition: DatabaseUniqueUidNewRowTest.php:28
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseUniqueUidNewRowTest\$subject
‪DatabaseUniqueUidNewRow $subject
Definition: DatabaseUniqueUidNewRowTest.php:26
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseUniqueUidNewRowTest\addDataKeepsGivenUidIfAlreadySet
‪addDataKeepsGivenUidIfAlreadySet()
Definition: DatabaseUniqueUidNewRowTest.php:47
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseUniqueUidNewRowTest\addDataThrowsExceptionIfUidIsAlreadySetButDoesNotStartWithNewKeyword
‪addDataThrowsExceptionIfUidIsAlreadySetButDoesNotStartWithNewKeyword()
Definition: DatabaseUniqueUidNewRowTest.php:60
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseUniqueUidNewRowTest
Definition: DatabaseUniqueUidNewRowTest.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseUniqueUidNewRowTest\addDataReturnSameDataIfCommandIsEdit
‪addDataReturnSameDataIfCommandIsEdit()
Definition: DatabaseUniqueUidNewRowTest.php:35
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseUniqueUidNewRow
Definition: DatabaseUniqueUidNewRow.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseUniqueUidNewRowTest\addDataSetsUniqueId
‪addDataSetsUniqueId()
Definition: DatabaseUniqueUidNewRowTest.php:74
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18