You are here

private function PatternsUserTestCase::testPermissionModifyUserCreate in Patterns 7.2

Creates an user, a role and a set of permissions. This case proves the fact that patterns whose semantic dependencies are manually solved can be run.

File

tests/user/user.test, line 48
SimpleTests for the User component of Patterns. TODO: permissions.

Class

PatternsUserTestCase
@file SimpleTests for the User component of Patterns. TODO: permissions.

Code

private function testPermissionModifyUserCreate() {
  $username = 'test_uid_sem_dependencies';
  $rolename = 'manager_sem_dep';
  $permissions = array(
    'administer blocks',
    'administer image styles',
  );

  //Delete user if exists already
  if (user_load_by_name($username)) {
    user_delete(user_load_by_name($username)->uid);
  }

  //Delete role if exists already
  if (user_role_load_by_name($rolename)) {
    user_role_delete($rolename);
  }

  //Raise error if user exists already
  $this
    ->assertFalse(user_load_by_name($username), format_string('Username %username does not exist in the system yet.', array(
    '%username' => $username,
  )));

  //Raise error if role exists already
  $this
    ->assertFalse(user_role_load_by_name($rolename), format_string('role %role does not exist in the system yet.', array(
    '%role' => $rolename,
  )));

  //Run pattern that creates user assign him a role and set the permissions for that role
  parent::runFile('user_permission_modify_user_create.yaml', 'User, role and permissions', $this->user_tests_dir);

  //parent::quickRun('user_permission_modify_user_create.yaml', 'User, role and permissions', $this->user_tests_dir, 'yaml', TRUE, 'php');

  //Raise error if user does not exist now
  $this
    ->assertTrue(user_load_by_name($username), format_string('Username %username now exists in the system.', array(
    '%username' => $username,
  )));

  //Raise error if role does not exist now
  $this
    ->assertTrue(user_role_load_by_name($rolename), format_string('role %role does not exist in the system yet.', array(
    '%role' => $rolename,
  )));

  //Check also that the new user holds the expected permissions
  $user = user_load_by_name($username);
  $debugrole = user_role_load_by_name($rolename);
  foreach ($permissions as $permission) {
    $this
      ->assertTrue(user_access($permission, $user), format_string('Permission %p successfully added to the role after running the pattern.', array(
      '%p' => $permission,
    )));
  }
}