You are here

function UserRelationshipsBaseTestCase::createDefaultRelationshipTypes in User Relationships 7

Create a number of relationship types.

The created types are stored in $this->rtypes with the keys oneway, twoway, approval, approval_oneway, approval_reciprocal.

Parameters

$create_types: An array of type identifiers which should be created. Defaults to all.

5 calls to UserRelationshipsBaseTestCase::createDefaultRelationshipTypes()
UserRelationshipsTestCase::testNoOnewayRelationships in ./user_relationships.test
Test the load functions if there are no one way relationship types.
UserRelationshipsTestCase::testRelationshipAPI in ./user_relationships.test
Test various relationship APi functions and params.
UserRelationshipsTestCase::testTypeAPI in ./user_relationships.test
Test API functions for relationship types.
UserRelationshipsTestCase::testUserRelationshipsLoadDuplicates in ./user_relationships.test
UserRelationshipsTestCase::testUserRelationshipsReciprocalTypes in ./user_relationships.test

File

./user_relationships.test, line 39
User Relationships API tests @author Alex Karshakevich http://drupal.org/user/183217

Class

UserRelationshipsBaseTestCase
Base class for all UR test cases, provides various helper methods.

Code

function createDefaultRelationshipTypes($create_types = array()) {
  $this->rtypes = array();
  if (empty($create_types)) {
    $create_types = array(
      'oneway',
      'twoway',
      'approval',
      'approval_oneway',
      'approval_reciprocal',
    );
  }

  // Flush static cache.
  drupal_static_reset('user_relationships_types_load');
  if (in_array('oneway', $create_types)) {
    $rtype = new StdClass();
    $rtype->name = 'oneway';
    $rtype->machine_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;
  }
  if (in_array('twoway', $create_types)) {
    $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;
  }
  if (in_array('approval', $create_types)) {
    $rtype = new StdClass();
    $rtype->name = 'approval';
    $rtype->machine_name = 'approval';
    $rtype->plural_name = 'approvals';
    $rtype->is_oneway = FALSE;
    $rtype->requires_approval = TRUE;
    $rtype->expires_val = 0;
    user_relationships_type_save($rtype);
    $this->rtypes['approval'] = $rtype;
  }
  if (in_array('approval_oneway', $create_types)) {
    $rtype = new StdClass();
    $rtype->name = 'approval-oneway';
    $rtype->machine_name = 'approval_oneway';
    $rtype->plural_name = 'approvals-oneway';
    $rtype->is_oneway = TRUE;
    $rtype->requires_approval = TRUE;
    $rtype->expires_val = 0;
    user_relationships_type_save($rtype);
    $this->rtypes['approval_oneway'] = $rtype;
  }

  //#348025 reciprocal one-way relationships
  if (in_array('approval_reciprocal', $create_types)) {
    $rtype = new StdClass();
    $rtype->name = 'approval-reciprocal';
    $rtype->machine_name = 'approval_reciprocal';
    $rtype->plural_name = 'approvals-reciprocal';
    $rtype->is_oneway = TRUE;
    $rtype->is_reciprocal = TRUE;
    $rtype->requires_approval = TRUE;
    $rtype->expires_val = 0;
    user_relationships_type_save($rtype);
    $this->rtypes['approval_reciprocal'] = $rtype;
  }

  // Flush static cache.
  drupal_static_reset('user_relationships_types_load');

  // Flush permission cache.
  user_relationships_types_load();
  $this
    ->checkPermissions(array(), TRUE);
}