1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverLeague\Console\Tests\Command\Member; |
4
|
|
|
|
5
|
|
|
use SilverLeague\Console\Tests\Command\AbstractCommandTest; |
6
|
|
|
use SilverStripe\Security\Member; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Test the unlock member command |
10
|
|
|
* |
11
|
|
|
* @package silverstripe-console |
12
|
|
|
* @author Robbie Averill <[email protected]> |
13
|
|
|
*/ |
14
|
|
View Code Duplication |
class UnlockCommandTest extends AbstractCommandTest |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Delete fixtured members after tests have run |
18
|
|
|
*/ |
19
|
|
|
protected function tearDown() |
20
|
|
|
{ |
21
|
|
|
parent::tearDown(); |
22
|
|
|
|
23
|
|
|
$testMember = Member::get()->filter(['Email' => '[email protected]'])->first(); |
24
|
|
|
if ($testMember && $testMember->exists()) { |
25
|
|
|
$testMember->delete(); |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
protected function getTestCommand() |
30
|
|
|
{ |
31
|
|
|
return 'member:unlock'; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testExecute() |
35
|
|
|
{ |
36
|
|
|
$member = $this->createMember(); |
37
|
|
|
$this->assertTrue($member->isLockedOut()); |
38
|
|
|
|
39
|
|
|
$tester = $this->executeTest(['email' => '[email protected]']); |
40
|
|
|
/** @var Member $member */ |
41
|
|
|
$member = Member::get()->byID($member->ID); |
42
|
|
|
$this->assertContains('Member [email protected] unlocked', $tester->getDisplay()); |
43
|
|
|
$this->assertFalse($member->isLockedOut()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testMemberNotFound() |
47
|
|
|
{ |
48
|
|
|
$result = $this->executeTest(['email' => '[email protected]']); |
49
|
|
|
$this->assertContains('Member with email "[email protected]" was not found.', $result->getDisplay()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Creates a dummy user for testing with |
54
|
|
|
* |
55
|
|
|
* @return Member |
56
|
|
|
*/ |
57
|
|
|
protected function createMember() |
58
|
|
|
{ |
59
|
|
|
$member = Member::create(); |
60
|
|
|
$member->Email = '[email protected]'; |
61
|
|
|
$member->Password = 'Opensesame1'; |
62
|
|
|
$member->LockedOutUntil = '2099-01-01 01:02:03'; |
63
|
|
|
$member->write(); |
64
|
|
|
return $member; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|