|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package framework |
|
4
|
|
|
* @subpackage tests |
|
5
|
|
|
*/ |
|
6
|
|
|
class BulkLoaderResultTest extends SapphireTest |
|
7
|
|
|
{ |
|
8
|
|
|
protected $extraDataObjects = array('BulkLoaderTestPlayer'); |
|
9
|
|
|
|
|
10
|
|
|
public function setUp() |
|
11
|
|
|
{ |
|
12
|
|
|
parent::setUp(); |
|
13
|
|
|
BulkLoaderTestPlayer::create(array('Name' => 'Vincent', 'Status' => 'Available'))->write(); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
public function testBulkLoaderResultCreated() |
|
17
|
|
|
{ |
|
18
|
|
|
$results = BulkLoader_Result::create(); |
|
19
|
|
|
$player = BulkLoaderTestPlayer::create(array('Name' => 'Rangi', 'Status' => 'Possible')); |
|
20
|
|
|
$player->write(); |
|
21
|
|
|
$results->addCreated($player, 'Speedster'); |
|
22
|
|
|
|
|
23
|
|
|
$this->assertEquals($results->CreatedCount(), 1); |
|
24
|
|
|
$this->assertSame( |
|
25
|
|
|
'Rangi', |
|
26
|
|
|
$results->Created()->find('Name', 'Rangi')->Name, |
|
27
|
|
|
'The player Rangi should be recorded as created in $results' |
|
28
|
|
|
); |
|
29
|
|
|
$this->assertSame( |
|
30
|
|
|
'Possible', |
|
31
|
|
|
$results->Created()->find('Name', 'Rangi')->Status, |
|
32
|
|
|
'The player Rangi should have Status of "Possible" in $results' |
|
33
|
|
|
); |
|
34
|
|
|
$this->assertSame( |
|
35
|
|
|
'Speedster', |
|
36
|
|
|
$results->Created()->find('Name', 'Rangi')->_BulkLoaderMessage, |
|
37
|
|
|
'Rangi should have _BulkLoaderMessage of Speedster' |
|
38
|
|
|
); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testBulkLoaderResultDeleted() |
|
42
|
|
|
{ |
|
43
|
|
|
$results = BulkLoader_Result::create(); |
|
44
|
|
|
$player = BulkLoaderTestPlayer::get()->find('Name', 'Vincent'); |
|
45
|
|
|
$results->addDeleted($player, 'Retired'); |
|
46
|
|
|
$player->delete(); |
|
47
|
|
|
|
|
48
|
|
|
$this->assertEquals($results->DeletedCount(), 1); |
|
49
|
|
|
$this->assertSame( |
|
50
|
|
|
'Vincent', |
|
51
|
|
|
$results->Deleted()->find('Name', 'Vincent')->Name, |
|
52
|
|
|
'The player Vincent should be recorded as deleted' |
|
53
|
|
|
); |
|
54
|
|
|
$this->assertSame( |
|
55
|
|
|
'Retired', |
|
56
|
|
|
$results->Deleted()->find('Name', 'Vincent')->_BulkLoaderMessage, |
|
57
|
|
|
'Vincent should have a _BulkLoaderMessage of Retired' |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testBulkLoaderResultUpdated() |
|
62
|
|
|
{ |
|
63
|
|
|
$results = BulkLoader_Result::create(); |
|
64
|
|
|
$player = BulkLoaderTestPlayer::get()->find('Name', 'Vincent'); |
|
65
|
|
|
$player->Status = 'Unavailable'; |
|
|
|
|
|
|
66
|
|
|
$player->write(); |
|
67
|
|
|
$results->addUpdated($player, 'Injured'); |
|
68
|
|
|
|
|
69
|
|
|
$this->assertEquals($results->UpdatedCount(), 1); |
|
70
|
|
|
$this->assertSame( |
|
71
|
|
|
'Vincent', |
|
72
|
|
|
$results->Updated()->find('Name', 'Vincent')->Name, |
|
73
|
|
|
'The player Vincent should be recorded as updated' |
|
74
|
|
|
); |
|
75
|
|
|
$this->assertSame( |
|
76
|
|
|
'Unavailable', |
|
77
|
|
|
$results->Updated()->find('Name', 'Vincent')->Status, |
|
78
|
|
|
'The player Vincent should have a Status of Unavailable' |
|
79
|
|
|
); |
|
80
|
|
|
$this->assertSame( |
|
81
|
|
|
'Injured', |
|
82
|
|
|
$results->Updated()->find('Name', 'Vincent')->_BulkLoaderMessage, |
|
83
|
|
|
'Vincent is injured' |
|
84
|
|
|
); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
class BulkLoaderTestPlayer extends DataObject implements TestOnly |
|
89
|
|
|
{ |
|
90
|
|
|
private static $db = array( |
|
91
|
|
|
'Name' => 'Varchar', |
|
92
|
|
|
'Status' => 'Varchar', |
|
93
|
|
|
); |
|
94
|
|
|
} |
|
95
|
|
|
|
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@propertyannotation 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.