1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
4
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\AddressChangeContext\Tests\Unit\Domain\Model; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressChange; |
9
|
|
|
use WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressChangeId; |
10
|
|
|
use WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressType; |
11
|
|
|
use WMDE\Fundraising\AddressChangeContext\Tests\Data\ValidAddress; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @covers \WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressChange |
15
|
|
|
*/ |
16
|
|
|
class AddressChangeTest extends TestCase { |
17
|
|
|
|
18
|
|
|
private const DUMMY_DONATION_ID = 0; |
19
|
|
|
|
20
|
|
|
private AddressChangeId $identifier; |
21
|
|
|
private AddressChangeId $newIdentifier; |
22
|
|
|
|
23
|
|
|
public function setUp(): void { |
24
|
|
|
$this->identifier = AddressChangeId::fromString( 'c956688a-89e8-41b7-b93e-7e4cf3d6c826' ); |
25
|
|
|
$this->newIdentifier = AddressChangeId::fromString( 'e0c4db0b-9049-462c-8c76-c4f6a3a75091' ); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testWhenNewAddressChangeIsCreated_itIsNotModified(): void { |
29
|
|
|
$addressChange = new AddressChange( AddressType::Person, AddressChange::EXTERNAL_ID_TYPE_DONATION, self::DUMMY_DONATION_ID, $this->identifier ); |
30
|
|
|
$this->assertFalse( $addressChange->isModified() ); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testWhenAddressIsUpdated_dataIsProperlyAssigned(): void { |
34
|
|
|
$addressChange = $this->newPersonAddressChange(); |
35
|
|
|
$address = ValidAddress::newValidPersonalAddress(); |
36
|
|
|
|
37
|
|
|
$addressChange->performAddressChange( $address, $this->newIdentifier ); |
38
|
|
|
|
39
|
|
|
$this->assertSame( $address, $addressChange->getAddress() ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
private function newPersonAddressChange(): AddressChange { |
43
|
|
|
return new AddressChange( |
44
|
|
|
AddressType::Person, |
45
|
|
|
AddressChange::EXTERNAL_ID_TYPE_DONATION, |
46
|
|
|
self::DUMMY_DONATION_ID, |
47
|
|
|
$this->identifier, |
48
|
|
|
null, |
49
|
|
|
new \DateTime( '1970-01-01' ), |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testUpdatingAddressMarksAddressChangeAsModified(): void { |
54
|
|
|
$addressChange = $this->newPersonAddressChange(); |
55
|
|
|
$initialIdentifier = $addressChange->getCurrentIdentifier(); |
56
|
|
|
|
57
|
|
|
$addressChange->performAddressChange( ValidAddress::newValidPersonalAddress(), $this->newIdentifier ); |
58
|
|
|
|
59
|
|
|
$this->assertNotSame( $initialIdentifier, $addressChange->getCurrentIdentifier() ); |
60
|
|
|
$this->assertSame( $initialIdentifier, $addressChange->getPreviousIdentifier() ); |
61
|
|
|
$this->assertTrue( $addressChange->isModified() ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testOptingOutOfReceiptMarksAddressChangeAsModified(): void { |
65
|
|
|
$addressChange = $this->newPersonAddressChange(); |
66
|
|
|
$initialIdentifier = $addressChange->getCurrentIdentifier(); |
67
|
|
|
|
68
|
|
|
$addressChange->optOutOfDonationReceipt( $this->newIdentifier ); |
69
|
|
|
|
70
|
|
|
$this->assertNotSame( $initialIdentifier, $addressChange->getCurrentIdentifier() ); |
71
|
|
|
$this->assertSame( $initialIdentifier, $addressChange->getPreviousIdentifier() ); |
72
|
|
|
$this->assertTrue( $addressChange->isModified() ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testNewAddressChangeIsNotExported(): void { |
76
|
|
|
$addressChange = new AddressChange( AddressType::Person, AddressChange::EXTERNAL_ID_TYPE_DONATION, self::DUMMY_DONATION_ID, $this->identifier ); |
77
|
|
|
$this->assertFalse( $addressChange->isExported() ); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testAddressChangeCanBeMarkedAsExported(): void { |
81
|
|
|
$addressChange = new AddressChange( AddressType::Person, AddressChange::EXTERNAL_ID_TYPE_DONATION, self::DUMMY_DONATION_ID, $this->identifier ); |
82
|
|
|
$addressChange->markAsExported(); |
83
|
|
|
$this->assertTrue( $addressChange->isExported() ); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testAddressChangeCannotBeExportedTwice(): void { |
87
|
|
|
$addressChange = new AddressChange( AddressType::Person, AddressChange::EXTERNAL_ID_TYPE_DONATION, self::DUMMY_DONATION_ID, $this->identifier ); |
88
|
|
|
$addressChange->markAsExported(); |
89
|
|
|
|
90
|
|
|
$this->expectException( \LogicException::class ); |
91
|
|
|
|
92
|
|
|
$addressChange->markAsExported(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function testMarkingAsExportedDoesNotChangeModificationDate(): void { |
96
|
|
|
$addressChange = new AddressChange( AddressType::Person, AddressChange::EXTERNAL_ID_TYPE_DONATION, self::DUMMY_DONATION_ID, $this->identifier ); |
97
|
|
|
$addressChange->markAsExported(); |
98
|
|
|
$this->assertFalse( $addressChange->isModified() ); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function testWhenAddressChangeIsPerformed_exportStateIsReset(): void { |
102
|
|
|
$addressChange = new AddressChange( AddressType::Person, AddressChange::EXTERNAL_ID_TYPE_DONATION, self::DUMMY_DONATION_ID, $this->identifier ); |
103
|
|
|
$addressChange->markAsExported(); |
104
|
|
|
$addressChange->performAddressChange( ValidAddress::newValidCompanyAddress(), $this->newIdentifier ); |
105
|
|
|
|
106
|
|
|
$this->assertFalse( $addressChange->isExported() ); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function testReferenceTypeIsValidated(): void { |
110
|
|
|
$this->expectException( \InvalidArgumentException::class ); |
111
|
|
|
|
112
|
|
|
new AddressChange( AddressType::Person, 'dogs!', self::DUMMY_DONATION_ID, $this->identifier ); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function testUnusedAddressReturnsCorrectExportState(): void { |
116
|
|
|
$addressChange = new AddressChange( AddressType::Person, AddressChange::EXTERNAL_ID_TYPE_DONATION, self::DUMMY_DONATION_ID, $this->identifier ); |
117
|
|
|
|
118
|
|
|
$this->assertEquals( AddressChange::EXPORT_STATE_NO_DATA, $addressChange->getExportState() ); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function testUsedAddressReturnsCorrectExportState(): void { |
122
|
|
|
$addressChange = new AddressChange( AddressType::Person, AddressChange::EXTERNAL_ID_TYPE_DONATION, self::DUMMY_DONATION_ID, $this->identifier ); |
123
|
|
|
$addressChange->performAddressChange( ValidAddress::newValidPersonalAddress(), $this->newIdentifier ); |
124
|
|
|
|
125
|
|
|
$this->assertEquals( AddressChange::EXPORT_STATE_USED_NOT_EXPORTED, $addressChange->getExportState() ); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function testUsedAndExportedAddressReturnsCorrectExportState(): void { |
129
|
|
|
$addressChange = new AddressChange( AddressType::Person, AddressChange::EXTERNAL_ID_TYPE_DONATION, self::DUMMY_DONATION_ID, $this->identifier ); |
130
|
|
|
$addressChange->performAddressChange( ValidAddress::newValidPersonalAddress(), $this->newIdentifier ); |
131
|
|
|
$addressChange->markAsExported(); |
132
|
|
|
|
133
|
|
|
$this->assertEquals( AddressChange::EXPORT_STATE_USED_EXPORTED, $addressChange->getExportState() ); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|