5e9f94902e53a997563376aa5df35f1d0ee71a11
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / DomainObject / AbstractEntityTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\DomainObject;
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 /**
18 * Test case
19 */
20 class AbstractEntityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
21
22 /**
23 * @test
24 */
25 public function objectIsNotDirtyAfterCallingMemorizeCleanStateWithSimpleProperties() {
26 $domainObjectName = uniqid('DomainObject_');
27 $domainObjectNameWithNS = __NAMESPACE__ . '\\' . $domainObjectName;
28 eval('namespace ' . __NAMESPACE__ . '; class ' . $domainObjectName . ' extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity {
29 public $foo;
30 public $bar;
31 }');
32 $domainObject = new $domainObjectNameWithNS();
33 $domainObject->foo = 'Test';
34 $domainObject->bar = 'It is raining outside';
35 $domainObject->_memorizeCleanState();
36 $this->assertFalse($domainObject->_isDirty());
37 }
38
39 /**
40 * @test
41 */
42 public function objectIsDirtyAfterCallingMemorizeCleanStateWithSimplePropertiesAndModifyingThePropertiesAfterwards() {
43 $domainObjectName = uniqid('DomainObject_');
44 $domainObjectNameWithNS = __NAMESPACE__ . '\\' . $domainObjectName;
45 eval('namespace ' . __NAMESPACE__ . '; class ' . $domainObjectName . ' extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity {
46 public $foo;
47 public $bar;
48 }');
49 $domainObject = new $domainObjectNameWithNS();
50 $domainObject->foo = 'Test';
51 $domainObject->bar = 'It is raining outside';
52 $domainObject->_memorizeCleanState();
53 $domainObject->bar = 'Now it is sunny.';
54 $this->assertTrue($domainObject->_isDirty());
55 }
56
57 /**
58 * @test
59 */
60 public function objectIsNotDirtyAfterCallingMemorizeCleanStateWithObjectProperties() {
61 $domainObjectName = uniqid('DomainObject_');
62 $domainObjectNameWithNS = __NAMESPACE__ . '\\' . $domainObjectName;
63 eval('namespace ' . __NAMESPACE__ . '; class ' . $domainObjectName . ' extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity {
64 public $foo;
65 public $bar;
66 }');
67 $domainObject = new $domainObjectNameWithNS();
68 $domainObject->foo = new \DateTime();
69 $domainObject->bar = 'It is raining outside';
70 $domainObject->_memorizeCleanState();
71 $this->assertFalse($domainObject->_isDirty());
72 }
73
74 /**
75 * @test
76 */
77 public function objectIsNotDirtyAfterCallingMemorizeCleanStateWithOtherDomainObjectsAsProperties() {
78 $domainObjectName = uniqid('DomainObject_');
79 $domainObjectNameWithNS = __NAMESPACE__ . '\\' . $domainObjectName;
80 eval('namespace ' . __NAMESPACE__ . '; class ' . $domainObjectName . ' extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity {
81 public $foo;
82 public $bar;
83 }');
84 $secondDomainObjectName = uniqid('DomainObject_');
85 $secondDomainObjectNameWithNS = __NAMESPACE__ . '\\' . $secondDomainObjectName;
86 eval('namespace ' . __NAMESPACE__ . '; class ' . $secondDomainObjectName . ' extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity {
87 public $foo;
88 public $bar;
89 }');
90 $secondDomainObject = new $secondDomainObjectNameWithNS();
91 $secondDomainObject->_memorizeCleanState();
92 $domainObject = new $domainObjectNameWithNS();
93 $domainObject->foo = $secondDomainObject;
94 $domainObject->bar = 'It is raining outside';
95 $domainObject->_memorizeCleanState();
96 $this->assertFalse($domainObject->_isDirty());
97 }
98 }