1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class ChangeSetItemTest_Versioned extends DataObject { |
4
|
|
|
private static $db = [ |
5
|
|
|
'Foo' => 'Int' |
6
|
|
|
]; |
7
|
|
|
|
8
|
|
|
private static $extensions = [ |
9
|
|
|
"Versioned" |
10
|
|
|
]; |
11
|
|
|
|
12
|
|
|
function canEdit($member = null) { return true; } |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @package framework |
17
|
|
|
* @subpackage tests |
18
|
|
|
*/ |
19
|
|
|
class ChangeSetItemTest extends SapphireTest { |
20
|
|
|
|
21
|
|
|
protected $extraDataObjects = [ |
22
|
|
|
'ChangeSetItemTest_Versioned' |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
function testChangeType() { |
26
|
|
|
$object = new ChangeSetItemTest_Versioned(['Foo' => 1]); |
27
|
|
|
$object->write(); |
28
|
|
|
|
29
|
|
|
$item = new ChangeSetItem([ |
30
|
|
|
'ObjectID' => $object->ID, |
31
|
|
|
'ObjectClass' => ClassInfo::baseDataClass($object->ClassName) |
32
|
|
|
]); |
33
|
|
|
|
34
|
|
|
$this->assertEquals( |
35
|
|
|
ChangeSetItem::CHANGE_CREATED, $item->ChangeType, |
36
|
|
|
'New objects that aren\'t yet published should return created' |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
$object->publishRecursive(); |
40
|
|
|
|
41
|
|
|
$this->assertEquals( |
42
|
|
|
ChangeSetItem::CHANGE_NONE, $item->ChangeType, |
43
|
|
|
'Objects that have just been published should return no change' |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
$object->Foo += 1; |
|
|
|
|
47
|
|
|
$object->write(); |
48
|
|
|
|
49
|
|
|
$this->assertEquals( |
50
|
|
|
ChangeSetItem::CHANGE_MODIFIED, $item->ChangeType, |
51
|
|
|
'Object that have unpublished changes written to draft should show as modified' |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$object->publishRecursive(); |
55
|
|
|
|
56
|
|
|
$this->assertEquals( |
57
|
|
|
ChangeSetItem::CHANGE_NONE, $item->ChangeType, |
58
|
|
|
'Objects that have just been published should return no change' |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
// We need to use a copy, because ID is set to 0 by delete, causing the following unpublish to fail |
62
|
|
|
$objectCopy = clone $object; $objectCopy->delete(); |
63
|
|
|
|
64
|
|
|
$this->assertEquals( |
65
|
|
|
ChangeSetItem::CHANGE_DELETED, $item->ChangeType, |
66
|
|
|
'Objects that have been deleted from draft (but not yet unpublished) should show as deleted' |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
$object->doUnpublish(); |
70
|
|
|
|
71
|
|
|
$this->assertEquals( |
72
|
|
|
ChangeSetItem::CHANGE_NONE, $item->ChangeType, |
73
|
|
|
'Objects that have been deleted and then unpublished should return no change' |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
function testGetForObject() { |
78
|
|
|
$object = new ChangeSetItemTest_Versioned(['Foo' => 1]); |
79
|
|
|
$object->write(); |
80
|
|
|
|
81
|
|
|
$item = new ChangeSetItem([ |
82
|
|
|
'ObjectID' => $object->ID, |
83
|
|
|
'ObjectClass' => ClassInfo::baseDataClass($object) |
84
|
|
|
]); |
85
|
|
|
$item->write(); |
86
|
|
|
|
87
|
|
|
$this->assertEquals( |
88
|
|
|
ChangeSetItemTest_Versioned::get()->byID($object->ID)->toMap(), |
89
|
|
|
ChangeSetItem::get_for_object($object)->first()->Object()->toMap() |
|
|
|
|
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
$this->assertEquals( |
93
|
|
|
ChangeSetItemTest_Versioned::get()->byID($object->ID)->toMap(), |
94
|
|
|
ChangeSetItem::get_for_object_by_id($object->ID, $object->ClassName)->first()->Object()->toMap() |
|
|
|
|
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.