You are here

function UserRelationshipsNodeAccessTestCase::setUp in User Relationships 6

Enable modules.

Overrides DrupalWebTestCase::setUp

File

user_relationship_node_access/tests/user_relationship_node_access.test, line 27
User Relationships Node Access Tests

Class

UserRelationshipsNodeAccessTestCase
@file User Relationships Node Access Tests

Code

function setUp() {
  parent::setUp('user_relationships_api', 'user_relationship_node_access', 'user_relationships_ui');
  $this->users = array();
  $this->rtypes = array();
  $this->nodes = array();

  //clear cache
  user_relationships_types_load(TRUE);
  $rtype = new StdClass();
  $rtype->name = 'oneway';
  $rtype->plural_name = 'oneways';
  $rtype->is_oneway = TRUE;
  $rtype->requires_approval = FALSE;
  $rtype->expires_val = 0;
  user_relationships_type_save($rtype);
  $this->rtypes['oneway'] = $rtype;
  unset($rtype);
  $rtype = new StdClass();
  $rtype->name = 'twoway';
  $rtype->plural_name = 'twoways';
  $rtype->is_oneway = FALSE;
  $rtype->requires_approval = FALSE;
  $rtype->expires_val = 0;
  user_relationships_type_save($rtype);
  $this->rtypes['twoway'] = $rtype;
  unset($rtype);
  $rtype = new StdClass();
  $rtype->name = 'external';
  $rtype->plural_name = 'externals';
  $rtype->is_oneway = FALSE;
  $rtype->requires_approval = FALSE;
  $rtype->expires_val = 0;
  user_relationships_type_save($rtype);
  $this->rtypes['external'] = $rtype;

  //clear cache
  user_relationships_types_load(TRUE);

  // User with absolute minimal permissions.
  $u1 = $this
    ->drupalCreateUser(array(
    'access content',
    'can have relationships',
  ));
  $this->users['u1'] = $u1;

  // User can grant delete.
  $u2 = $this
    ->drupalCreateUser(array(
    'grant delete permission to related users',
    'access content',
    'create page content',
    'can have relationships',
  ));
  $this->users['u2'] = $u2;

  // User can grant update.
  $u3 = $this
    ->drupalCreateUser(array(
    'grant update permission to related users',
    'access content',
    'create page content',
    'can have relationships',
  ));
  $this->users['u3'] = $u3;

  // User can grant view.
  $u4 = $this
    ->drupalCreateUser(array(
    'grant view permission to related users',
    'access content',
    'create page content',
    'can have relationships',
  ));
  $this->users['u4'] = $u4;

  // Unrelated user.
  $u5 = $this
    ->drupalCreateUser(array(
    'grant view permission to related users',
    'access content',
    'create page content',
    'can have relationships',
  ));
  $this->users['u5'] = $u5;

  // Admin user.
  $admin = $this
    ->drupalCreateUser(array(
    'administer user relationships',
    'access administration pages',
    'administer nodes',
  ));
  $this->users['admin'] = $admin;

  // Basically user 1 has every kind of relationships with everybody.
  user_relationships_request_relationship($u1, $u2, $this->rtypes['oneway']->rtid, TRUE);
  user_relationships_request_relationship($u1, $u3, $this->rtypes['oneway']->rtid, TRUE);

  // Them to you.
  user_relationships_request_relationship($u4, $u1, $this->rtypes['oneway']->rtid, TRUE);
  user_relationships_request_relationship($u1, $u2, $this->rtypes['twoway']->rtid, TRUE);
  user_relationships_request_relationship($u1, $u3, $this->rtypes['twoway']->rtid, TRUE);

  // Them to you.
  user_relationships_request_relationship($u4, $u1, $this->rtypes['twoway']->rtid, TRUE);
  user_relationships_request_relationship($u5, $u1, $this->rtypes['external']->rtid, TRUE);

  // Manually apply the proper type settings.
  $this
    ->drupalLogin($this->users['admin']);
  $this
    ->drupalPost('admin/content/node-settings/rebuild', null, 'Rebuild permissions');
  $type_settings = array(
    'user_relationship_node_access_allowed_types[page]' => TRUE,
  );
  $this
    ->drupalPost('admin/content/user_relationship_node_access', $type_settings, 'Save configuration');
  $this
    ->drupalLogout();
}