mirror of
https://github.com/opensupports/opensupports.git
synced 2025-09-26 11:29:05 +02:00
64 lines
2.0 KiB
PHP
Executable File
64 lines
2.0 KiB
PHP
Executable File
<?php
|
|
// MOCKS
|
|
include_once 'tests/__lib__/Mock.php';
|
|
include_once 'tests/__mocks__/NullDataStoreMock.php';
|
|
include_once 'tests/__mocks__/ResponseMock.php';
|
|
include_once 'tests/__mocks__/ControllerMock.php';
|
|
include_once 'tests/__mocks__/SessionMock.php';
|
|
include_once 'tests/__mocks__/UserMock.php';
|
|
include_once 'tests/__mocks__/HashingMock.php';
|
|
include_once 'tests/__mocks__/SessionCookieMock.php';
|
|
include_once 'data/ERRORS.php';
|
|
|
|
include_once 'controllers/user/login.php';
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class LoginControllerTest extends TestCase {
|
|
private $loginController;
|
|
|
|
protected function setUp() {
|
|
Session::initStubs();
|
|
User::initStubs();
|
|
Response::initStubs();
|
|
$_SERVER['REMOTE_ADDR'] = 'MOCK_REMOTE';
|
|
|
|
$this->loginController = new LoginController();
|
|
}
|
|
|
|
public function testShouldRespondErrorIfAlreadyLoggedIn() {
|
|
Session::mockInstanceFunction('sessionExists', \Mock::stub()->returns(true));
|
|
|
|
$this->expectExceptionMessage(ERRORS::SESSION_EXISTS);
|
|
|
|
$this->loginController->handler();
|
|
}
|
|
|
|
public function testShouldCreateSessionAndRespondSuccessIfCredentialsAreValid() {
|
|
Session::mockInstanceFunction('sessionExists', \Mock::stub()->returns(false));
|
|
|
|
$this->loginController->handler();
|
|
|
|
$this->assertTrue(!!Session::getInstance()->createSession->hasBeenCalledWithArgs('MOCK_ID', false));
|
|
$this->assertTrue(Response::get('respondSuccess')->hasBeenCalledWithArgs(array(
|
|
'userId' => 'MOCK_ID',
|
|
'userEmail' => 'MOCK_EMAIL',
|
|
'staff' => false,
|
|
'token' => 'TEST_TOKEN',
|
|
'rememberToken' => null
|
|
)));
|
|
}
|
|
|
|
public function testShouldRespondErrorIfCredentialsAreInvalid() {
|
|
User::setStatics(array(
|
|
'authenticate' => \Mock::stub()->returns(new NullDataStore())
|
|
));
|
|
|
|
Controller::$requestReturnMock = '';
|
|
|
|
$this->expectExceptionMessage(ERRORS::INVALID_CREDENTIALS);
|
|
|
|
$this->loginController->handler();
|
|
}
|
|
}
|