You are here

function UserRelationshipsTestCase::testTypeAPI in User Relationships 7

Test API functions for relationship types.

File

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

Class

UserRelationshipsTestCase
Test cases für UR API.

Code

function testTypeAPI() {
  $this
    ->createDefaultRelationshipTypes();

  // Test loading by a different column than name or plural_name.
  $rtype = user_relationships_type_load(array(
    'is_reciprocal' => 1,
  ));
  $this
    ->assertEqual('approval-reciprocal', $rtype->name);

  // Enforce uniqueness of relationship type name.
  $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;
  $this
    ->assertFalse(user_relationships_type_save($rtype));

  // Verify default value of expires_val.
  $rtype = new StdClass();
  $rtype->name = 'expires_default_test';
  $rtype->machine_name = 'expires_default_test';
  $rtype->plural_name = 'expires_default_test_plural';
  $rtype->is_oneway = TRUE;
  $rtype->requires_approval = FALSE;
  user_relationships_type_save($rtype);
  $this
    ->assertEqual(0, $rtype->expires_val);

  // Delete a relationship type.
  user_relationships_type_delete($rtype->rtid);
  $this
    ->assertFalse(db_query('SELECT name FROM {user_relationship_types} WHERE rtid = :rtid', array(
    ':rtid' => $rtype->rtid,
  ))
    ->fetchField());
  $this
    ->assertFalse(user_relationships_type_load($rtype->rtid));
}