1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class UserInvitationTest extends SapphireTest |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
public static $fixture_file = 'UserInvitationTest.yml'; |
6
|
|
|
|
7
|
|
|
public function setUp() |
8
|
|
|
{ |
9
|
|
|
parent::setUp(); |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Tests that an invitation email was sent. |
14
|
|
|
*/ |
15
|
|
|
public function testSendInvitation() |
16
|
|
|
{ |
17
|
|
|
Injector::inst()->registerService(new EmailTest_Mailer(), 'Mailer'); |
|
|
|
|
18
|
|
|
/** @var UserInvitation $joe */ |
19
|
|
|
$joe = $this->objFromFixture('UserInvitation', 'joe'); |
20
|
|
|
|
21
|
|
|
$sent = $joe->sendInvitation(); |
22
|
|
|
$this->assertEquals($joe->Email, $sent['to']); |
23
|
|
|
$this->assertEquals("Invitation from {$joe->InvitedBy()->FirstName}", $sent['subject']); |
24
|
|
|
$this->assertContains('Click here to accept this invitation', $sent['content']); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Tests for expired invitations |
29
|
|
|
*/ |
30
|
|
|
public function testIsExpired() |
31
|
|
|
{ |
32
|
|
|
/** @var UserInvitation $expired */ |
33
|
|
|
$expired = $this->objFromFixture('UserInvitation', 'expired'); |
34
|
|
|
$this->assertTrue($expired->isExpired()); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Tests that the TempHash field has been removed |
39
|
|
|
*/ |
40
|
|
|
public function testGetCMSFields() |
41
|
|
|
{ |
42
|
|
|
/** @var UserInvitation $joe */ |
43
|
|
|
$joe = $this->objFromFixture('UserInvitation', 'joe'); |
44
|
|
|
$fields = $joe->getCMSFields(); |
45
|
|
|
$this->assertNull($fields->dataFieldByName('TempHash')); |
46
|
|
|
$this->assertNotNull($fields->dataFieldByName('FirstName')); |
47
|
|
|
$this->assertNotNull($fields->dataFieldByName('Email')); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Tests that invitations can't be re-sent. |
52
|
|
|
*/ |
53
|
|
View Code Duplication |
public function testInvitationAlreadySent() |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
$invite = UserInvitation::create(array( |
56
|
|
|
'FirstName' => 'Joe', |
57
|
|
|
'Email' => '[email protected]' |
58
|
|
|
)); |
59
|
|
|
$result = $invite->validate(); |
60
|
|
|
$this->assertFalse($result->valid()); |
61
|
|
|
$this->assertEquals('This user was already sent an invite.', $result->message()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Tests that duplicate members can't be created |
66
|
|
|
*/ |
67
|
|
View Code Duplication |
public function testMemberAlreadyExists() |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
$invite = UserInvitation::create(array( |
70
|
|
|
'FirstName' => 'Jane', |
71
|
|
|
'Email' => '[email protected]' |
72
|
|
|
)); |
73
|
|
|
$result = $invite->validate(); |
74
|
|
|
$this->assertFalse($result->valid()); |
75
|
|
|
$this->assertEquals('This person is already a member of this system.', $result->message()); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Tests that a random hash and the logged in users id was added |
80
|
|
|
*/ |
81
|
|
|
public function testOnBeforeWrite() |
82
|
|
|
{ |
83
|
|
|
$this->logInWithPermission('ADMIN'); |
84
|
|
|
$invite = UserInvitation::create(array( |
85
|
|
|
'FirstName' => 'Dane', |
86
|
|
|
'Email' => '[email protected]' |
87
|
|
|
)); |
88
|
|
|
$invite->write(); |
89
|
|
|
$this->assertNotNull($invite->TempHash); |
90
|
|
|
$this->assertNotNull($invite->InvitedByID); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths