function ServicesResourceUsertests::testUserLoginMethodAPI_1_1 in Services 7.3
Test login method. API VERsion 1.1
Create user. Login. Try to login with another user (to get error). Login with wrong credentials (to get error).
File
- tests/
functional/ ServicesResourceUserTests.test, line 527 - Call the endpoint tests when no authentication is being used.
Class
- ServicesResourceUsertests
- Run test cases for the endpoint with no authentication turned on.
Code
function testUserLoginMethodAPI_1_1() {
$this->endpoint = $this
->saveNewVersionEndpoint('1.1');
$path = $this->endpoint->path;
$account = $this
->drupalCreateUser();
// Logout first.
$this
->drupalLogout();
$response = $this
->servicesPost($this->endpoint->path . '/user/login', array(
'username' => $account->name,
'password' => $account->pass_raw,
));
$response_data = $response['body'];
$this
->assertTrue(strpos($response['status'], 'Missing required argument name') !== FALSE, 'User Resource is rejecting old parameter names.', 'UserResource: Login');
$responseArray = $this
->servicesPost($this->endpoint->path . '/user/login', array(
'username' => $account->name,
'password' => $account->pass_raw,
), array(
'services_user_login_version: 1.0',
));
$this
->assertTrue($responseArray['code'] == '200', 'Arguments should be old arguments and we should be logged in.', 'Services Version System');
$response_data = $responseArray['body'];
$proper_answer = isset($response_data->sessid) && isset($response_data->user) && $response_data->user->name == $account->name;
$this
->assertTrue($proper_answer, 'User successfully logged in.', 'UserResource: Login');
$this
->drupalLogout();
$responseArray = $this
->servicesPost($this->endpoint->path . '/user/login', array(
'name' => $account->name,
'pass' => $account->pass_raw,
), array(
'services_user_login_version: 1.1',
));
$this
->assertTrue($responseArray['code'] == '200', 'Arguments should be old arguments and we should be logged in.', 'Services Version System');
$response_data = $responseArray['body'];
$proper_answer = isset($response_data->sessid) && isset($response_data->user) && $response_data->user->name == $account->name;
$this
->assertTrue($proper_answer, 'User successfully logged in.', 'UserResource: Login');
}