2 /***************************************************************
5 * (c) 2009 Sebastian Kurf\9frst <sebastian@typo3.org>
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
25 class Tx_Extbase_DomainObject_AbstractEntity_testcase
extends Tx_Extbase_BaseTestCase
{
30 public function objectIsNotDirtyAfterCallingMemorizeCleanStateWithSimpleProperties() {
31 $domainObjectName = uniqid('DomainObject_');
32 eval('class ' . $domainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {
36 $domainObject = new $domainObjectName();
37 $domainObject->foo
= 'Test';
38 $domainObject->bar
= 'It is raining outside';
40 $domainObject->_memorizePropertyCleanState('foo');
41 $domainObject->_memorizePropertyCleanState('bar');
42 $this->assertFalse($domainObject->_isDirty());
48 public function objectIsDirtyAfterCallingMemorizeCleanStateWithSimplePropertiesAndModifyingThePropertiesAfterwards() {
49 $domainObjectName = uniqid('DomainObject_');
50 eval('class ' . $domainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {
54 $domainObject = new $domainObjectName();
55 $domainObject->foo
= 'Test';
56 $domainObject->bar
= 'It is raining outside';
58 $domainObject->_memorizePropertyCleanState('foo');
59 $domainObject->_memorizePropertyCleanState('bar');
60 $domainObject->bar
= 'Now it is sunny.';
61 $this->assertTrue($domainObject->_isDirty());
63 // We can check here that _getDirtyProperties returns the correct values as well.
64 $this->assertSame(array('bar' => 'Now it is sunny.'), $domainObject->_getDirtyProperties());
70 public function objectIsNotDirtyAfterCallingMemorizeCleanStateWithObjectProperties() {
71 $domainObjectName = uniqid('DomainObject_');
72 eval('class ' . $domainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {
76 $domainObject = new $domainObjectName();
77 $domainObject->foo
= new DateTime();
78 $domainObject->bar
= 'It is raining outside';
80 $domainObject->_memorizePropertyCleanState('foo');
81 $domainObject->_memorizePropertyCleanState('bar');
82 $this->assertFalse($domainObject->_isDirty());
88 public function getDirtyPropertiesReturnsNoPropertiesIfObjectWithObjectPropertiesIsClean() {
89 $domainObjectName = uniqid('DomainObject_');
90 eval('class ' . $domainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {
94 $domainObject = new $domainObjectName();
95 $domainObject->foo
= new DateTime();
96 $domainObject->bar
= 'It is raining outside';
97 $domainObject->_memorizePropertyCleanState('foo');
98 $domainObject->_memorizePropertyCleanState('bar');
99 $this->assertEquals(array(), $domainObject->_getDirtyProperties());
105 public function objectIsNotDirtyAfterCallingMemorizeCleanStateWithOtherDomainObjectsAsProperties() {
106 $domainObjectName = uniqid('DomainObject_');
107 eval('class ' . $domainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {
112 $secondDomainObjectName = uniqid('DomainObject_');
113 eval('class ' . $secondDomainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {
118 $domainObject = new $domainObjectName();
119 $domainObject->foo
= new $secondDomainObjectName;
120 $domainObject->bar
= 'It is raining outside';
122 $domainObject->_memorizePropertyCleanState('foo');
123 $domainObject->_memorizePropertyCleanState('bar');
124 $this->assertFalse($domainObject->_isDirty());