|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace WMDE\Fundraising\Store\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use WMDE\Fundraising\Entities\DoctrineDonation; |
|
6
|
|
|
use WMDE\Fundraising\Store\DonationData; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @covers WMDE\Fundraising\Entities\DoctrineDonation |
|
10
|
|
|
* @covers WMDE\Fundraising\Store\DonationData |
|
11
|
|
|
* |
|
12
|
|
|
* @licence GNU GPL v2+ |
|
13
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
14
|
|
|
*/ |
|
15
|
|
|
class DoctrineDonationTest extends \PHPUnit_Framework_TestCase { |
|
16
|
|
|
|
|
17
|
|
|
public function testDataEncodingAndDecodingRoundtrips() { |
|
18
|
|
|
$donation = new DoctrineDonation(); |
|
19
|
|
|
|
|
20
|
|
|
$someData = [ |
|
21
|
|
|
'nyan' => 'cat', |
|
22
|
|
|
'foo' => null, |
|
23
|
|
|
'bar' => 9000.01, |
|
24
|
|
|
'baz' => [ true ] |
|
25
|
|
|
]; |
|
26
|
|
|
|
|
27
|
|
|
$donation->encodeAndSetData( $someData ); |
|
28
|
|
|
|
|
29
|
|
|
$this->assertSame( $someData, $donation->getDecodedData() ); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testGivenNoData_getDecodedDataReturnsEmptyArray() { |
|
33
|
|
|
$donation = new DoctrineDonation(); |
|
34
|
|
|
|
|
35
|
|
|
$this->assertSame( [], $donation->getDecodedData() ); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testWhenSettingIdToAnInteger_getIdReturnsIt() { |
|
39
|
|
|
$donation = new DoctrineDonation(); |
|
40
|
|
|
$donation->setId( 1337 ); |
|
41
|
|
|
|
|
42
|
|
|
$this->assertSame( 1337, $donation->getId() ); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testWhenSettingIdToNull_getIdReturnsNull() { |
|
46
|
|
|
$donation = new DoctrineDonation(); |
|
47
|
|
|
$donation->setId( 1337 ); |
|
48
|
|
|
$donation->setId( null ); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertNull( $donation->getId() ); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testWhenIdIsNotSet_getIdReturnsNull() { |
|
54
|
|
|
$donation = new DoctrineDonation(); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertNull( $donation->getId() ); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testGivenNoData_getDataObjectReturnsObjectWithNullValues() { |
|
60
|
|
|
$donation = new DoctrineDonation(); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertNull( $donation->getDataObject()->getAccessToken() ); |
|
63
|
|
|
$this->assertNull( $donation->getDataObject()->getUpdateToken() ); |
|
64
|
|
|
$this->assertNull( $donation->getDataObject()->getUpdateTokenExpiry() ); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function testGivenData_getDataObjectReturnsTheValues() { |
|
68
|
|
|
$donation = new DoctrineDonation(); |
|
69
|
|
|
$donation->encodeAndSetData( [ |
|
70
|
|
|
'token' => 'foo', |
|
71
|
|
|
'utoken' => 'bar', |
|
72
|
|
|
'uexpiry' => 'baz', |
|
73
|
|
|
] ); |
|
74
|
|
|
|
|
75
|
|
|
$this->assertSame( 'foo', $donation->getDataObject()->getAccessToken() ); |
|
76
|
|
|
$this->assertSame( 'bar', $donation->getDataObject()->getUpdateToken() ); |
|
77
|
|
|
$this->assertSame( 'baz', $donation->getDataObject()->getUpdateTokenExpiry() ); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function testWhenProvidingData_setDataObjectSetsData() { |
|
81
|
|
|
$data = new DonationData(); |
|
82
|
|
|
$data->setAccessToken( 'foo' ); |
|
83
|
|
|
$data->setUpdateToken( 'bar' ); |
|
84
|
|
|
$data->setUpdateTokenExpiry( 'baz' ); |
|
85
|
|
|
|
|
86
|
|
|
$donation = new DoctrineDonation(); |
|
87
|
|
|
$donation->setDataObject( $data ); |
|
88
|
|
|
|
|
89
|
|
|
$this->assertSame( |
|
90
|
|
|
[ |
|
91
|
|
|
'token' => 'foo', |
|
92
|
|
|
'utoken' => 'bar', |
|
93
|
|
|
'uexpiry' => 'baz', |
|
94
|
|
|
], |
|
95
|
|
|
$donation->getDecodedData() |
|
96
|
|
|
); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function testWhenProvidingNullData_setObjectDoesNotSetFields() { |
|
100
|
|
|
$donation = new DoctrineDonation(); |
|
101
|
|
|
$donation->setDataObject( new DonationData() ); |
|
102
|
|
|
|
|
103
|
|
|
$this->assertSame( |
|
104
|
|
|
[], |
|
105
|
|
|
$donation->getDecodedData() |
|
106
|
|
|
); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function testWhenDataAlreadyExists_setDataObjectRetainsAndUpdatesData() { |
|
110
|
|
|
$donation = new DoctrineDonation(); |
|
111
|
|
|
$donation->encodeAndSetData( [ |
|
112
|
|
|
'nyan' => 'cat', |
|
113
|
|
|
'token' => 'wee', |
|
114
|
|
|
'pink' => 'fluffy', |
|
115
|
|
|
] ); |
|
116
|
|
|
|
|
117
|
|
|
$data = new DonationData(); |
|
118
|
|
|
$data->setAccessToken( 'foo' ); |
|
119
|
|
|
$data->setUpdateToken( 'bar' ); |
|
120
|
|
|
|
|
121
|
|
|
$donation->setDataObject( $data ); |
|
122
|
|
|
|
|
123
|
|
|
$this->assertSame( |
|
124
|
|
|
[ |
|
125
|
|
|
'nyan' => 'cat', |
|
126
|
|
|
'token' => 'foo', |
|
127
|
|
|
'pink' => 'fluffy', |
|
128
|
|
|
'utoken' => 'bar', |
|
129
|
|
|
], |
|
130
|
|
|
$donation->getDecodedData() |
|
131
|
|
|
); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function testWhenModifyingTheDataObject_modificationsAreReflected() { |
|
135
|
|
|
$donation = new DoctrineDonation(); |
|
136
|
|
|
$donation->encodeAndSetData( [ |
|
137
|
|
|
'nyan' => 'cat', |
|
138
|
|
|
'token' => 'wee', |
|
139
|
|
|
'pink' => 'fluffy', |
|
140
|
|
|
] ); |
|
141
|
|
|
|
|
142
|
|
|
$donation->modifyDataObject( function( DonationData $data ) { |
|
143
|
|
|
$data->setAccessToken( 'foo' ); |
|
144
|
|
|
$data->setUpdateToken( 'bar' ); |
|
145
|
|
|
} ); |
|
146
|
|
|
|
|
147
|
|
|
$this->assertSame( |
|
148
|
|
|
[ |
|
149
|
|
|
'nyan' => 'cat', |
|
150
|
|
|
'token' => 'foo', |
|
151
|
|
|
'pink' => 'fluffy', |
|
152
|
|
|
'utoken' => 'bar', |
|
153
|
|
|
], |
|
154
|
|
|
$donation->getDecodedData() |
|
155
|
|
|
); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
public function testStatusConstantsExist() { |
|
159
|
|
|
$this->assertNotNull( DoctrineDonation::STATUS_NEW ); |
|
160
|
|
|
$this->assertNotNull( DoctrineDonation::STATUS_CANCELLED ); |
|
161
|
|
|
$this->assertNotNull( DoctrineDonation::STATUS_EXTERNAL_BOOKED ); |
|
162
|
|
|
$this->assertNotNull( DoctrineDonation::STATUS_EXTERNAL_INCOMPLETE ); |
|
163
|
|
|
$this->assertNotNull( DoctrineDonation::STATUS_MODERATION ); |
|
164
|
|
|
$this->assertNotNull( DoctrineDonation::STATUS_PROMISE ); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
} |
|
168
|
|
|
|