[~CONFIGURATION] Extbase: Set lockType to empty string instead of 'system'.
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / DomainObject / AbstractEntity_testcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Sebastian Kurf\9frst <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 // We can check here that _getDirtyProperties returns the correct values as well.
64 $this->assertSame(array('bar' => 'Now it is sunny.'), $domainObject->_getDirtyProperties());
65 }
66
67 /**
68 * @test
69 */
70 public function objectIsNotDirtyAfterCallingMemorizeCleanStateWithObjectProperties() {
71 $domainObjectName = uniqid('DomainObject_');
72 eval('class ' . $domainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {
73 public $foo;
74 public $bar;
75 }');
76 $domainObject = new $domainObjectName();
77 $domainObject->foo = new DateTime();
78 $domainObject->bar = 'It is raining outside';
79
80 $domainObject->_memorizePropertyCleanState('foo');
81 $domainObject->_memorizePropertyCleanState('bar');
82 $this->assertFalse($domainObject->_isDirty());
83 }
84
85 /**
86 * @test
87 */
88 public function getDirtyPropertiesReturnsNoPropertiesIfObjectWithObjectPropertiesIsClean() {
89 $domainObjectName = uniqid('DomainObject_');
90 eval('class ' . $domainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {
91 public $foo;
92 public $bar;
93 }');
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());
100 }
101
102 /**
103 * @test
104 */
105 public function objectIsNotDirtyAfterCallingMemorizeCleanStateWithOtherDomainObjectsAsProperties() {
106 $domainObjectName = uniqid('DomainObject_');
107 eval('class ' . $domainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {
108 public $foo;
109 public $bar;
110 }');
111
112 $secondDomainObjectName = uniqid('DomainObject_');
113 eval('class ' . $secondDomainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {
114 public $foo;
115 public $bar;
116 }');
117
118 $domainObject = new $domainObjectName();
119 $domainObject->foo = new $secondDomainObjectName;
120 $domainObject->bar = 'It is raining outside';
121
122 $domainObject->_memorizePropertyCleanState('foo');
123 $domainObject->_memorizePropertyCleanState('bar');
124 $this->assertFalse($domainObject->_isDirty());
125 }
126 }
127 ?>