Completed
Pull Request — master (#108)
by Jeroen De
03:37
created

testStatusConstantsExist()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace WMDE\Fundraising\Store\Tests;
4
5
use WMDE\Fundraising\Entities\DoctrineMembershipApplication;
6
use WMDE\Fundraising\Store\MembershipApplicationData;
7
8
/**
9
 * @covers WMDE\Fundraising\Entities\DoctrineMembershipApplication
10
 * @covers WMDE\Fundraising\Store\MembershipApplicationData
11
 *
12
 * @licence GNU GPL v2+
13
 * @author Jeroen De Dauw < [email protected] >
14
 */
15
class DoctrineMembershipApplicationTest extends \PHPUnit_Framework_TestCase {
16
17
	public function testWhenSettingIdToAnInteger_getIdReturnsIt() {
18
		$application = new DoctrineMembershipApplication();
19
		$application->setId( 1337 );
20
21
		$this->assertSame( 1337, $application->getId() );
22
	}
23
24
	public function testWhenSettingIdToNull_getIdReturnsNull() {
25
		$application = new DoctrineMembershipApplication();
26
		$application->setId( 1337 );
27
		$application->setId( null );
28
29
		$this->assertNull( $application->getId() );
30
	}
31
32
	public function testWhenIdIsNotSet_getIdReturnsNull() {
33
		$application = new DoctrineMembershipApplication();
34
35
		$this->assertNull( $application->getId() );
36
	}
37
38
	public function testGivenNoData_getDataObjectReturnsObjectWithNullValues() {
39
		$application = new DoctrineMembershipApplication();
40
41
		$this->assertNull( $application->getDataObject()->getAccessToken() );
42
		$this->assertNull( $application->getDataObject()->getUpdateToken() );
43
		$this->assertNull( $application->getDataObject()->getPreservedStatus() );
44
	}
45
46
	public function testWhenProvidingData_setDataObjectSetsData() {
47
		$data = new MembershipApplicationData();
48
		$data->setAccessToken( 'foo' );
49
		$data->setUpdateToken( 'bar' );
50
		$data->setPreservedStatus( 1337 );
51
52
		$application = new DoctrineMembershipApplication();
53
		$application->setDataObject( $data );
54
55
		$this->assertSame(
56
			[
57
				'token' => 'foo',
58
				'utoken' => 'bar',
59
				'old_status' => 1337,
60
			],
61
			$application->getDecodedData()
62
		);
63
	}
64
65
	public function testWhenProvidingNullData_setObjectDoesNotSetFields() {
66
		$application = new DoctrineMembershipApplication();
67
		$application->setDataObject( new MembershipApplicationData() );
68
69
		$this->assertSame(
70
			[],
71
			$application->getDecodedData()
72
		);
73
	}
74
75
	public function testWhenDataAlreadyExists_setDataObjectRetainsAndUpdatesData() {
76
		$application = new DoctrineMembershipApplication();
77
		$application->encodeAndSetData( [
78
			'nyan' => 'cat',
79
			'token' => 'wee',
80
			'pink' => 'fluffy',
81
		] );
82
83
		$data = new MembershipApplicationData();
84
		$data->setAccessToken( 'foo' );
85
		$data->setUpdateToken( 'bar' );
86
87
		$application->setDataObject( $data );
88
89
		$this->assertSame(
90
			[
91
				'nyan' => 'cat',
92
				'token' => 'foo',
93
				'pink' => 'fluffy',
94
				'utoken' => 'bar',
95
			],
96
			$application->getDecodedData()
97
		);
98
	}
99
100
	public function testWhenModifyingTheDataObject_modificationsAreReflected() {
101
		$application = new DoctrineMembershipApplication();
102
		$application->encodeAndSetData( [
103
			'nyan' => 'cat',
104
			'token' => 'wee',
105
			'pink' => 'fluffy',
106
		] );
107
108
		$application->modifyDataObject( function( MembershipApplicationData $data ) {
109
			$data->setAccessToken( 'foo' );
110
			$data->setUpdateToken( 'bar' );
111
		} );
112
113
		$this->assertSame(
114
			[
115
				'nyan' => 'cat',
116
				'token' => 'foo',
117
				'pink' => 'fluffy',
118
				'utoken' => 'bar',
119
			],
120
			$application->getDecodedData()
121
		);
122
	}
123
124
	public function testStatusConstantsExist() {
125
		$this->assertNotNull( DoctrineMembershipApplication::STATUS_MODERATION );
126
		$this->assertNotNull( DoctrineMembershipApplication::STATUS_ABORTED );
127
		$this->assertNotNull( DoctrineMembershipApplication::STATUS_CANCELED );
128
		$this->assertNotNull( DoctrineMembershipApplication::STATUS_CONFIRMED );
129
		$this->assertNotNull( DoctrineMembershipApplication::STATUS_DELETED );
130
		$this->assertNotNull( DoctrineMembershipApplication::STATUS_NEUTRAL );
131
	}
132
133
	public function testGivenModerationStatus_needsModerationReturnsTrue() {
134
		$application = new DoctrineMembershipApplication();
135
		$application->setStatus( DoctrineMembershipApplication::STATUS_MODERATION );
136
137
		$this->assertTrue( $application->needsModeration() );
138
	}
139
140
	public function testGivenDefaultStatus_needsModerationReturnsFalse() {
141
		$application = new DoctrineMembershipApplication();
142
143
		$this->assertFalse( $application->needsModeration() );
144
	}
145
146
	public function testGivenModerationAndCancelledStatus_needsModerationReturnsTrue() {
147
		$application = new DoctrineMembershipApplication();
148
		$application->setStatus(
149
			DoctrineMembershipApplication::STATUS_MODERATION + DoctrineMembershipApplication::STATUS_CANCELED
150
		);
151
152
		$this->assertTrue( $application->needsModeration() );
153
	}
154
155
	public function testGivenCancelledStatus_isCancelledReturnsTrue() {
156
		$application = new DoctrineMembershipApplication();
157
		$application->setStatus( DoctrineMembershipApplication::STATUS_CANCELED );
158
159
		$this->assertTrue( $application->isCancelled() );
160
	}
161
162
	public function testGivenDefaultStatus_isCancelledReturnsFalse() {
163
		$application = new DoctrineMembershipApplication();
164
165
		$this->assertFalse( $application->isCancelled() );
166
	}
167
168
	public function testGivenModerationAndCancelledStatus_isCancelledReturnsTrue() {
169
		$application = new DoctrineMembershipApplication();
170
		$application->setStatus(
171
			DoctrineMembershipApplication::STATUS_MODERATION + DoctrineMembershipApplication::STATUS_CANCELED
172
		);
173
174
		$this->assertTrue( $application->isCancelled() );
175
	}
176
177
}
178