You are here

public function ServicesEntityTestHelper::serviceLogin in Services Entity API 7.2

Log a user in via services.

Parameters

String $name: The name of the user to log in.

String $pass: The password of the user to log in.

Return value

Object The newly logged in user object.

2 calls to ServicesEntityTestHelper::serviceLogin()
ServicesEntityNodeResourceTest::testCRUD in tests/services_entity.test
Tests basic CRUD and index actions of a node via the entity_node service.
ServicesEntityNodeResourceTest::testIndex in tests/services_entity.test
Test index functionality.

File

tests/services_entity.test, line 144
Services Entity Tests

Class

ServicesEntityTestHelper
Services Entity Test Helper class.

Code

public function serviceLogin($name, $pass) {
  $response = $this
    ->servicesPost($this->endpoint->path . '/user/login', array(
    'username' => $name,
    'password' => $pass,
  ));
  $response_data = $response['body'];
  $proper_answer = isset($response_data->sessid) && isset($response_data->user) && $response_data->user->name == $name;
  $this
    ->assertTrue($proper_answer, 'User successfully logged in.');

  // Save session details.
  $this->session_id = $response_data->sessid;
  $this->session_name = $response_data->session_name;
  $this->loggedInUser = $response_data->user;
  return $this->loggedInUser;
}