Add Extbase 1.0.1 to TYPO3core. Do NOT make changes inside! See misc/core_svn_rules...
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / DomainObject / AbstractEntity_testcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Sebastian Kurf├╝rst <sebastian@typo3.org>
6 * All rights reserved
7 *
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.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
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.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 class Tx_Extbase_DomainObject_AbstractEntity_testcase extends Tx_Extbase_BaseTestCase {
26
27 /**
28 * @test
29 */
30 public function objectIsNotDirtyAfterCallingMemorizeCleanStateWithSimpleProperties() {
31 $domainObjectName = uniqid('DomainObject_');
32 eval('class ' . $domainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {
33 public $foo;
34 public $bar;
35 }');
36 $domainObject = new $domainObjectName();
37 $domainObject->foo = 'Test';
38 $domainObject->bar = 'It is raining outside';
39
40 $domainObject->_memorizePropertyCleanState('foo');
41 $domainObject->_memorizePropertyCleanState('bar');
42 $this->assertFalse($domainObject->_isDirty());
43 }
44
45 /**
46 * @test
47 */
48 public function objectIsDirtyAfterCallingMemorizeCleanStateWithSimplePropertiesAndModifyingThePropertiesAfterwards() {
49 $domainObjectName = uniqid('DomainObject_');
50 eval('class ' . $domainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {
51 public $foo;
52 public $bar;
53 }');
54 $domainObject = new $domainObjectName();
55 $domainObject->foo = 'Test';
56 $domainObject->bar = 'It is raining outside';
57
58 $domainObject->_memorizePropertyCleanState('foo');
59 $domainObject->_memorizePropertyCleanState('bar');
60 $domainObject->bar = 'Now it is sunny.';
61 $this->assertTrue($domainObject->_isDirty());
62 }
63
64 /**
65 * @test
66 */
67 public function objectIsNotDirtyAfterCallingMemorizeCleanStateWithObjectProperties() {
68 $domainObjectName = uniqid('DomainObject_');
69 eval('class ' . $domainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {
70 public $foo;
71 public $bar;
72 }');
73 $domainObject = new $domainObjectName();
74 $domainObject->foo = new DateTime();
75 $domainObject->bar = 'It is raining outside';
76
77 $domainObject->_memorizePropertyCleanState('foo');
78 $domainObject->_memorizePropertyCleanState('bar');
79 $this->assertFalse($domainObject->_isDirty());
80 }
81
82 /**
83 * @test
84 */
85 public function objectIsNotDirtyAfterCallingMemorizeCleanStateWithOtherDomainObjectsAsProperties() {
86 $domainObjectName = uniqid('DomainObject_');
87 eval('class ' . $domainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {
88 public $foo;
89 public $bar;
90 }');
91
92 $secondDomainObjectName = uniqid('DomainObject_');
93 eval('class ' . $secondDomainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {
94 public $foo;
95 public $bar;
96 }');
97
98 $domainObject = new $domainObjectName();
99 $domainObject->foo = new $secondDomainObjectName;
100 $domainObject->bar = 'It is raining outside';
101
102 $domainObject->_memorizePropertyCleanState('foo');
103 $domainObject->_memorizePropertyCleanState('bar');
104 $this->assertFalse($domainObject->_isDirty());
105 }
106 }
107 ?>