mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-23 06:04:53 +00:00
CLI tests for password changing and clearing
This commit is contained in:
parent
a7fe879174
commit
54be5997d1
1 changed files with 40 additions and 9 deletions
|
@ -221,16 +221,20 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
|
|
||||||
/** @dataProvider provideUserPasswordChanges */
|
/** @dataProvider provideUserPasswordChanges */
|
||||||
public function testChangeAUserPassword(string $cmd, int $exitStatus, string $output) {
|
public function testChangeAUserPassword(string $cmd, int $exitStatus, string $output) {
|
||||||
// FIXME: Phake is somehow unable to mock the User class correctly, so we use PHPUnit's mocks instead
|
$passwordChange = function($user, $pass = null) {
|
||||||
Arsse::$user = $this->createMock(User::class);
|
|
||||||
Arsse::$user->method("passwordSet")->will($this->returnCallback(function($user, $pass = null) {
|
|
||||||
switch ($user) {
|
switch ($user) {
|
||||||
case "jane.doe@example.com":
|
case "jane.doe@example.com":
|
||||||
throw new \JKingWeb\Arsse\User\Exception("doesNotExist");
|
throw new \JKingWeb\Arsse\User\Exception("doesNotExist");
|
||||||
case "john.doe@example.com":
|
case "john.doe@example.com":
|
||||||
return is_null($pass) ? "random password" : $pass;
|
return is_null($pass) ? "random password" : $pass;
|
||||||
}
|
}
|
||||||
}));
|
};
|
||||||
|
// FIXME: Phake is somehow unable to mock the User class correctly, so we use PHPUnit's mocks instead
|
||||||
|
Arsse::$user = $this->createMock(User::class);
|
||||||
|
Arsse::$user->method("passwordSet")->will($this->returnCallback($passwordChange));
|
||||||
|
$fever = \Phake::mock(FeverUser::class);
|
||||||
|
\Phake::when($fever)->register->thenReturnCallback($passwordChange);
|
||||||
|
\Phake::when($this->cli)->getFever->thenReturn($fever);
|
||||||
$this->assertConsole($this->cli, $cmd, $exitStatus, $output);
|
$this->assertConsole($this->cli, $cmd, $exitStatus, $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,10 +243,37 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
["arsse.php user set-pass john.doe@example.com", 0, "random password"],
|
["arsse.php user set-pass john.doe@example.com", 0, "random password"],
|
||||||
["arsse.php user set-pass john.doe@example.com superman", 0, ""],
|
["arsse.php user set-pass john.doe@example.com superman", 0, ""],
|
||||||
["arsse.php user set-pass jane.doe@example.com", 10402, ""],
|
["arsse.php user set-pass jane.doe@example.com", 10402, ""],
|
||||||
|
["arsse.php user set-pass john.doe@example.com --fever", 0, "random password"],
|
||||||
|
["arsse.php user set-pass --fever john.doe@example.com superman", 0, ""],
|
||||||
|
["arsse.php user set-pass jane.doe@example.com --fever", 10402, ""],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testChangeAFeverPassword() {
|
/** @dataProvider provideUserPasswordClearings */
|
||||||
$this->markTestIncomplete();
|
public function testClearAUserPassword(string $cmd, int $exitStatus, string $output) {
|
||||||
|
$passwordClear = function($user) {
|
||||||
|
switch ($user) {
|
||||||
|
case "jane.doe@example.com":
|
||||||
|
throw new \JKingWeb\Arsse\User\Exception("doesNotExist");
|
||||||
|
case "john.doe@example.com":
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// FIXME: Phake is somehow unable to mock the User class correctly, so we use PHPUnit's mocks instead
|
||||||
|
Arsse::$user = $this->createMock(User::class);
|
||||||
|
Arsse::$user->method("passwordUnet")->will($this->returnCallback($passwordChange));
|
||||||
|
$fever = \Phake::mock(FeverUser::class);
|
||||||
|
\Phake::when($fever)->unregister->thenReturnCallback($passwordChange);
|
||||||
|
\Phake::when($this->cli)->getFever->thenReturn($fever);
|
||||||
|
$this->assertConsole($this->cli, $cmd, $exitStatus, $output);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideUserPasswordClearings() {
|
||||||
|
return [
|
||||||
|
["arsse.php user unset-pass john.doe@example.com", 0, ""],
|
||||||
|
["arsse.php user unset-pass jane.doe@example.com", 10402, ""],
|
||||||
|
["arsse.php user unset-pass john.doe@example.com --fever", 0, ""],
|
||||||
|
["arsse.php user unset-pass jane.doe@example.com --fever", 10402, ""],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue