You are here

public function RestfulUserLoginCookieTestCase::testLogin in RESTful 7.2

Same name and namespace in other branches
  1. 7 tests/RestfulUserLoginCookieTestCase.test \RestfulUserLoginCookieTestCase::testLogin()

Test login using curl via /api/login.

File

tests/RestfulUserLoginCookieTestCase.test, line 60
Contains RestfulUserLoginCookieTestCase.

Class

RestfulUserLoginCookieTestCase
@file Contains RestfulUserLoginCookieTestCase.

Code

public function testLogin() {
  global $user;

  // We need to hijack the global user object in order to force it to be an
  // anonymous user.
  $user = drupal_anonymous_user();
  $user1 = $this
    ->drupalCreateUser();
  $this->httpauth_credentials = $user1->name . ':' . $user1->pass_raw;
  $result = $this
    ->httpRequest('api/login');
  $this
    ->assertEqual($result['code'], '200', '200 status code sent for an anonymous user logging in.');

  // Since we are already logged in, we should get a 403.
  $result = $this
    ->httpRequest('api/login');
  $this
    ->assertEqual($result['code'], '403', '403 status code sent for an already logged in user.');
}