|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Frontend\MembershipContext\Tests\Integration\UseCases\CancelMembershipApplication; |
|
6
|
|
|
|
|
7
|
|
|
use WMDE\Fundraising\Frontend\MembershipContext\Authorization\ApplicationAuthorizer; |
|
8
|
|
|
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Model\Application; |
|
9
|
|
|
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Repositories\ApplicationRepository; |
|
10
|
|
|
use WMDE\Fundraising\Frontend\MembershipContext\Tests\Data\ValidMembershipApplication; |
|
11
|
|
|
use WMDE\Fundraising\Frontend\MembershipContext\Tests\Fixtures\FailingAuthorizer; |
|
12
|
|
|
use WMDE\Fundraising\Frontend\MembershipContext\Tests\Fixtures\InMemoryApplicationRepository; |
|
13
|
|
|
use WMDE\Fundraising\Frontend\MembershipContext\Tests\Fixtures\SucceedingAuthorizer; |
|
14
|
|
|
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\CancelMembershipApplication\CancellationRequest; |
|
15
|
|
|
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\CancelMembershipApplication\CancelMembershipApplicationUseCase; |
|
16
|
|
|
use WMDE\Fundraising\Frontend\Tests\Fixtures\TemplateBasedMailerSpy; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @covers WMDE\Fundraising\Frontend\MembershipContext\UseCases\CancelMembershipApplication\CancelMembershipApplicationUseCase |
|
20
|
|
|
* |
|
21
|
|
|
* @license GNU GPL v2+ |
|
22
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
23
|
|
|
*/ |
|
24
|
|
|
class CancelMembershipApplicationUseCaseTest extends \PHPUnit_Framework_TestCase { |
|
25
|
|
|
|
|
26
|
|
|
const ID_OF_NON_EXISTING_APPLICATION = 1337; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var ApplicationAuthorizer |
|
30
|
|
|
*/ |
|
31
|
|
|
private $authorizer; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var ApplicationRepository |
|
35
|
|
|
*/ |
|
36
|
|
|
private $repository; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var TemplateBasedMailerSpy |
|
40
|
|
|
*/ |
|
41
|
|
|
private $mailer; |
|
42
|
|
|
|
|
43
|
|
|
public function setUp() { |
|
44
|
|
|
$this->authorizer = new SucceedingAuthorizer(); |
|
45
|
|
|
$this->repository = new InMemoryApplicationRepository(); |
|
46
|
|
|
$this->mailer = new TemplateBasedMailerSpy( $this ); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testGivenIdOfUnknownDonation_cancellationIsNotSuccessful() { |
|
50
|
|
|
$useCase = $this->newUseCase(); |
|
51
|
|
|
|
|
52
|
|
|
$response = $useCase->cancelApplication( new CancellationRequest( self::ID_OF_NON_EXISTING_APPLICATION ) ); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertFalse( $response->cancellationWasSuccessful() ); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
private function newUseCase(): CancelMembershipApplicationUseCase { |
|
58
|
|
|
return new CancelMembershipApplicationUseCase( |
|
59
|
|
|
$this->authorizer, |
|
60
|
|
|
$this->repository, |
|
61
|
|
|
$this->mailer |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testFailureResponseContainsApplicationId() { |
|
66
|
|
|
$useCase = $this->newUseCase(); |
|
67
|
|
|
|
|
68
|
|
|
$response = $useCase->cancelApplication( new CancellationRequest( self::ID_OF_NON_EXISTING_APPLICATION ) ); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertEquals( self::ID_OF_NON_EXISTING_APPLICATION, $response->getMembershipApplicationId() ); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testGivenIdOfCancellableApplication_cancellationIsSuccessful() { |
|
74
|
|
|
$application = $this->newCancelableApplication(); |
|
75
|
|
|
$this->storeApplication( $application ); |
|
76
|
|
|
|
|
77
|
|
|
$response = $this->newUseCase()->cancelApplication( new CancellationRequest( $application->getId() ) ); |
|
78
|
|
|
|
|
79
|
|
|
$this->assertTrue( $response->cancellationWasSuccessful() ); |
|
80
|
|
|
$this->assertEquals( $application->getId(), $response->getMembershipApplicationId() ); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
private function newCancelableApplication(): Application { |
|
84
|
|
|
return ValidMembershipApplication::newDomainEntity(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
private function storeApplication( Application $application ) { |
|
88
|
|
|
$this->repository->storeApplication( $application ); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function testWhenApplicationGetsCancelled_cancellationConfirmationEmailIsSend() { |
|
92
|
|
|
$application = $this->newCancelableApplication(); |
|
93
|
|
|
$this->storeApplication( $application ); |
|
94
|
|
|
|
|
95
|
|
|
$this->newUseCase()->cancelApplication( new CancellationRequest( $application->getId() ) ); |
|
96
|
|
|
|
|
97
|
|
|
$this->mailer->assertCalledOnceWith( |
|
98
|
|
|
$application->getApplicant()->getEmailAddress(), |
|
99
|
|
|
[ |
|
100
|
|
|
'membershipApplicant' => [ |
|
101
|
|
|
'salutation' => $application->getApplicant()->getName()->getSalutation(), |
|
102
|
|
|
'title' => $application->getApplicant()->getName()->getTitle(), |
|
103
|
|
|
'lastName' => $application->getApplicant()->getName()->getLastName() |
|
104
|
|
|
], |
|
105
|
|
|
'applicationId' => 1 |
|
106
|
|
|
] |
|
107
|
|
|
); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function testNotAuthorized_cancellationFails() { |
|
111
|
|
|
$this->authorizer = new FailingAuthorizer(); |
|
112
|
|
|
|
|
113
|
|
|
$application = $this->newCancelableApplication(); |
|
114
|
|
|
$this->storeApplication( $application ); |
|
115
|
|
|
|
|
116
|
|
|
$response = $this->newUseCase()->cancelApplication( new CancellationRequest( $application->getId() ) ); |
|
117
|
|
|
|
|
118
|
|
|
$this->assertFalse( $response->cancellationWasSuccessful() ); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function testNotAuthorized_cancellationSucceeds() { |
|
122
|
|
|
$this->authorizer = new SucceedingAuthorizer(); |
|
123
|
|
|
|
|
124
|
|
|
$application = $this->newCancelableApplication(); |
|
125
|
|
|
$this->storeApplication( $application ); |
|
126
|
|
|
|
|
127
|
|
|
$response = $this->newUseCase()->cancelApplication( new CancellationRequest( $application->getId() ) ); |
|
128
|
|
|
|
|
129
|
|
|
$this->assertTrue( $response->cancellationWasSuccessful() ); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
} |
|
133
|
|
|
|