You are here

function ServicesResourceUsertests::testCreateUser in Services 7.3

Same name and namespace in other branches
  1. 6.3 tests/functional/ServicesResourceUserTests.test \ServicesResourceUsertests::testCreateUser()

Test create method.

Create user, load user, try ti create user without email.

File

tests/functional/ServicesResourceUserTests.test, line 53
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 testCreateUser() {

  // Create user.
  $user = array();
  $user['name'] = $this
    ->randomName();
  $user['mail'] = $user['name'] . '@example.com';
  $user['pass'] = user_password();
  $user['status'] = 1;
  $response = $this
    ->servicesPost($this->endpoint->path . '/user', $user);
  $account = $response['body'];
  $this
    ->assertTrue(!empty($account['uid']), 'User has been create successfully.', 'UserResource: Create');

  // Load user.
  $user_load = user_load($account['uid']);
  $this
    ->assertTrue(!empty($user_load), 'Newly created user has been loaded successfully.', 'UserResource: Create');

  // Try to create user without email.
  $user = array();
  $user['name'] = $this
    ->randomName();
  $user['pass'] = user_password();
  $user['status'] = 1;
  $response = $this
    ->servicesPost($this->endpoint->path . '/user', $user);
  $this
    ->assertTrue(strpos($response['status'], 'E-mail address field is required') !== FALSE, 'It is not possible to create user without email.', 'UserResource: Create');
}