1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverLeague\Console\Tests\Command\Member; |
4
|
|
|
|
5
|
|
|
use SilverLeague\Console\Tests\Command\AbstractCommandTest; |
6
|
|
|
use SilverStripe\Security\Member; |
7
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @coversDefaultClass \SilverLeague\Console\Command\Member\ChangePasswordCommand |
11
|
|
|
* @package silverstripe-console |
12
|
|
|
* @author Robbie Averill <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class ChangePasswordCommandTest extends AbstractCommandTest |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Create a Member to play with |
18
|
|
|
*/ |
19
|
|
|
public function setUp() |
20
|
|
|
{ |
21
|
|
|
parent::setUp(); |
22
|
|
|
|
23
|
|
|
Member::get()->removeAll(); |
24
|
|
|
$member = Member::create(); |
25
|
|
|
$member->Email = '[email protected]'; |
26
|
|
|
$member->Password = 'notrelevant'; |
27
|
|
|
$member->write(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritDoc} |
32
|
|
|
*/ |
33
|
|
|
public function getTestCommand() |
34
|
|
|
{ |
35
|
|
|
return 'member:change-password'; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Test that our existing Member's password can be changed |
40
|
|
|
* |
41
|
|
|
* @covers ::execute |
42
|
|
|
*/ |
43
|
|
View Code Duplication |
public function testExecute() |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
$tester = new CommandTester($this->command); |
46
|
|
|
$tester->execute( |
47
|
|
|
[ |
48
|
|
|
'command' => $this->command->getName(), |
49
|
|
|
'email' => '[email protected]', |
50
|
|
|
'password' => 'newpassword' |
51
|
|
|
] |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$this->assertContains('Password updated', $tester->getDisplay()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Test that if an email does not match a Member, then an error is returned |
59
|
|
|
* |
60
|
|
|
* @covers ::execute |
61
|
|
|
*/ |
62
|
|
View Code Duplication |
public function testErrorWhenEmailNotFound() |
|
|
|
|
63
|
|
|
{ |
64
|
|
|
$tester = new CommandTester($this->command); |
65
|
|
|
$tester->execute( |
66
|
|
|
[ |
67
|
|
|
'command' => $this->command->getName(), |
68
|
|
|
'email' => '[email protected]', |
69
|
|
|
'password' => 'helloworld' |
70
|
|
|
] |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
$this->assertContains('Member with email "[email protected]" was not found', $tester->getDisplay()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Ensure that the InputArgument for at least one of the arguments has been added |
78
|
|
|
* |
79
|
|
|
* @covers ::configure |
80
|
|
|
*/ |
81
|
|
|
public function testConfigure() |
82
|
|
|
{ |
83
|
|
|
$this->assertTrue($this->command->getDefinition()->hasArgument('password')); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.