From 686569b4a133fb25f426de68a225819c27f265ce Mon Sep 17 00:00:00 2001
From: mrded <mrded@556088.no-reply.drupal.org>
Date: Fri, 26 Apr 2013 16:51:25 +0100
Subject: [PATCH] Add machine name to user_relationships

---
 .../user_relationship_privatemsg.test              | 14 ++--
 user_relationships.admin.inc                       |  9 +++
 user_relationships.install                         | 21 ++++++
 user_relationships.module                          | 24 ++++--
 user_relationships.test                            | 86 ++++++++++++----------
 user_relationships_ui/user_relationships_ui.module |  4 +-
 user_relationships_ui/user_relationships_ui.test   | 40 +++++-----
 7 files changed, 128 insertions(+), 70 deletions(-)

diff --git a/user_relationship_privatemsg/user_relationship_privatemsg.test b/user_relationship_privatemsg/user_relationship_privatemsg.test
index 5a2b30b..72bf84f 100644
--- a/user_relationship_privatemsg/user_relationship_privatemsg.test
+++ b/user_relationship_privatemsg/user_relationship_privatemsg.test
@@ -36,6 +36,7 @@ class UserRelationshipsPrivatemsgRecipientTestCase extends DrupalWebTestCase {
     // Create relationship.
     $relationship = array(
       'name' => $this->randomName(),
+      'machine_name' => strtolower($this->randomName()),
       'plural_name' => $this->randomName(),
       'requires_approval' => FALSE,
       'expires_val' => 0,
@@ -46,9 +47,9 @@ class UserRelationshipsPrivatemsgRecipientTestCase extends DrupalWebTestCase {
     drupal_static_reset('user_relationships_types_load');
     $this->checkPermissions(array(), TRUE);
 
-    $have_permission = 'can have ' . $relationship['name'] . ' relationships';
-    $request_permission = 'can request ' . $relationship['name'] . ' relationships';
-    $maintain_permission = 'maintain ' . $relationship['name'] . ' relationships';
+    $have_permission = 'can have ' . $relationship['machine_name'] . ' relationships';
+    $request_permission = 'can request ' . $relationship['machine_name'] . ' relationships';
+    $maintain_permission = 'maintain ' . $relationship['machine_name'] . ' relationships';
 
     $admin = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg', $have_permission, $request_permission, 'view relationship recipients', 'administer user relationships', $maintain_permission, 'write privatemsg to relationships', 'access user profiles'));
     $userA = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg', $have_permission, $request_permission, 'view relationship recipients', 'write privatemsg to relationships'));
@@ -220,6 +221,7 @@ class UserRelationshipsPrivatemsgRecipientTestCase extends DrupalWebTestCase {
     // Create relationship.
     $relationship = array(
       'name' => $this->randomName(),
+      'machine_name' => strtolower($this->randomName()),
       'plural_name' => $this->randomName(),
       'requires_approval' => FALSE,
       'expires_val' => 0,
@@ -230,9 +232,9 @@ class UserRelationshipsPrivatemsgRecipientTestCase extends DrupalWebTestCase {
     drupal_static_reset('user_relationships_types_load');
     $this->checkPermissions(array(), TRUE);
 
-    $have_permission = 'can have ' . $relationship['name'] . ' relationships';
-    $request_permission = 'can request ' . $relationship['name'] . ' relationships';
-    $maintain_permission = 'maintain ' . $relationship['name'] . ' relationships';
+    $have_permission = 'can have ' . $relationship['machine_name'] . ' relationships';
+    $request_permission = 'can request ' . $relationship['machine_name'] . ' relationships';
+    $maintain_permission = 'maintain ' . $relationship['machine_name'] . ' relationships';
     $admin = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg', $have_permission, $request_permission, 'view relationship recipients', 'administer user relationships', $maintain_permission, 'write privatemsg to relationships', 'access user profiles'));
 
     $this->drupalLogin($admin);
diff --git a/user_relationships.admin.inc b/user_relationships.admin.inc
index 2f7bb77..f4d2d8d 100644
--- a/user_relationships.admin.inc
+++ b/user_relationships.admin.inc
@@ -173,6 +173,15 @@ function user_relationships_admin_type_edit($form, &$form_state, $relationship_t
     '#required'       => TRUE,
     '#weight'         => -10,
   );
+  $form['machine_name'] = array(
+    '#type' => 'machine_name',
+    '#default_value' => isset($relationship_type) ? $relationship_type->machine_name : NULL,
+    '#maxlength' => 255,
+    '#machine_name' => array(
+      'exists' => 'user_relationships_type_machine_name_load',
+    ),
+    '#weight' => -9,
+  );
   $form['requires_approval'] = array(
     '#type'           => 'checkbox',
     '#title'          => t('Requires Approval'),
diff --git a/user_relationships.install b/user_relationships.install
index 952bd84..1df32ec 100644
--- a/user_relationships.install
+++ b/user_relationships.install
@@ -31,6 +31,7 @@ function user_relationships_schema() {
   $schema['user_relationship_types'] = array(
     'fields' => array(
       'rtid'              => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
+      'machine_name'      => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
       'name'              => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
       'plural_name'       => array('type' => 'varchar', 'length' => 255, 'default' => ''),
       'is_oneway'         => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'),
@@ -69,6 +70,7 @@ function user_relationships_schema() {
       ),
     ),
     'unique keys' => array(
+      'machine_name'  => array('machine_name'),
       'name'  => array('name'),
     ),
     'primary key' => array('rtid')
@@ -200,3 +202,22 @@ function user_relationships_update_7005() {
     db_add_field('user_relationship_types', $field, $definition);
   }
 }
+
+/**
+ * Add machine name field.
+ */
+function user_relationships_update_7006() {
+  if (!db_field_exists('user_relationship_types', 'machine_name')) {
+    $field = array(
+      'type' => 'varchar',
+      'length' => 255,
+      'default' => '',
+    );
+
+    db_add_field('user_relationship_types', 'machine_name', $field);
+
+    db_update('user_relationship_types')
+      ->expression('machine_name', 'name')
+      ->execute();
+  }
+}
diff --git a/user_relationships.module b/user_relationships.module
index 292fa85..bac289c 100644
--- a/user_relationships.module
+++ b/user_relationships.module
@@ -292,19 +292,19 @@ function user_relationships_permission() {
   ));
 
   foreach (user_relationships_types_load() as $type) {
-    $permissions['can have ' . $type->name . ' relationships'] = array(
+    $permissions['can have ' . $type->machine_name . ' relationships'] = array(
       'title' => t('Have %name relationships', array('%name' => $type->name)),
       'description' => t('The user may have relationships of this type.'),
     );
-    $permissions['maintain ' . $type->name . ' relationships'] = array(
+    $permissions['maintain ' . $type->machine_name . ' relationships'] = array(
       'title' => t('Maintain %name relationships', array('%name' => $type->name)),
       'description' => t('The user may approve or decline relationship requests of this type.'),
     );
-    $permissions['can request ' . $type->name . ' relationships'] = array(
+    $permissions['can request ' . $type->machine_name . ' relationships'] = array(
       'title' => t('Request %name relationships', array('%name' => $type->name)),
       'description' => t('The user may request relationships of this type.'),
     );
-    $permissions['delete ' . $type->name . ' relationships'] = array(
+    $permissions['delete ' . $type->machine_name . ' relationships'] = array(
       'title' => t('Delete %name relationships', array('%name' => $type->name)),
       'description' => t('The user may delete current relationships of this type.'),
     );
@@ -377,6 +377,20 @@ function user_relationships_activity_info() {
 }
 
 /**
+ * Public API for retrieving a specific relationship by machine name.
+ *
+ * @param $machine_name
+ *    The machine name identifying the relationship.
+ * @return
+ *    object of the requested relationship type
+ *
+ */
+function user_relationships_type_machine_name_load($machine_name) {
+  return user_relationships_type_load(array('machine_name' => $machine_name));
+}
+
+
+/**
  * Public API for retrieving a specific relationship
  *
  * @param $param
@@ -907,7 +921,7 @@ function user_relationships_user_access($permission, $relationship = NULL, $acco
   }
 
   foreach ($relationships as $r) {
-    $relationship_permission = str_replace('@relationship', $r->name, $permission);
+    $relationship_permission = str_replace('@relationship', $r->machine_name, $permission);
     if (user_access($relationship_permission, $account)) {
       return TRUE;
     }
diff --git a/user_relationships.test b/user_relationships.test
index 3ebffa3..3355b72 100644
--- a/user_relationships.test
+++ b/user_relationships.test
@@ -31,7 +31,7 @@ class UserRelationshipsBaseTestCase extends DrupalWebTestCase {
    * Create a number of relationship types.
    *
    * The created types are stored in $this->rtypes with the keys oneway, twoway,
-   * approval, approval-oneway, approval-reciprocal.
+   * approval, approval_oneway, approval_reciprocal.
    *
    * @param $create_types
    *   An array of type identifiers which should be created. Defaults to all.
@@ -40,7 +40,7 @@ class UserRelationshipsBaseTestCase extends DrupalWebTestCase {
     $this->rtypes = array();
 
     if (empty($create_types)) {
-      $create_types = array('oneway', 'twoway', 'approval', 'approval-oneway', 'approval-reciprocal');
+      $create_types = array('oneway', 'twoway', 'approval', 'approval_oneway', 'approval_reciprocal');
     }
 
     // Flush static cache.
@@ -49,6 +49,7 @@ class UserRelationshipsBaseTestCase extends DrupalWebTestCase {
     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;
@@ -71,6 +72,7 @@ class UserRelationshipsBaseTestCase extends DrupalWebTestCase {
     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;
@@ -79,28 +81,30 @@ class UserRelationshipsBaseTestCase extends DrupalWebTestCase {
       $this->rtypes['approval'] = $rtype;
     }
 
-    if (in_array('approval-oneway', $create_types)) {
+    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;
+      $this->rtypes['approval_oneway'] = $rtype;
     }
 
     //#348025 reciprocal one-way relationships
-    if (in_array('approval-reciprocal', $create_types)) {
+    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;
+      $this->rtypes['approval_reciprocal'] = $rtype;
     }
 
     // Flush static cache.
@@ -148,6 +152,7 @@ class UserRelationshipsTestCase extends UserRelationshipsBaseTestCase {
     // 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;
@@ -157,6 +162,7 @@ class UserRelationshipsTestCase extends UserRelationshipsBaseTestCase {
     // 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;
@@ -179,16 +185,16 @@ class UserRelationshipsTestCase extends UserRelationshipsBaseTestCase {
     $this->createDefaultRelationshipTypes();
 
     $permissions = array(
-      'can have ' . $this->rtypes['oneway']->name . ' relationships',
-      'can request ' . $this->rtypes['oneway']->name . ' relationships',
-      'can have ' . $this->rtypes['twoway']->name . ' relationships',
-      'can request ' . $this->rtypes['twoway']->name . ' relationships',
-      'can have ' . $this->rtypes['approval-oneway']->name . ' relationships',
-      'can request ' . $this->rtypes['approval-oneway']->name . ' relationships',
-      'can have ' . $this->rtypes['approval']->name . ' relationships',
-      'can request ' . $this->rtypes['approval']->name . ' relationships',
-      'can have ' . $this->rtypes['approval-reciprocal']->name . ' relationships',
-      'can request ' . $this->rtypes['approval-reciprocal']->name . ' relationships',
+      'can have ' . $this->rtypes['oneway']->machine_name . ' relationships',
+      'can request ' . $this->rtypes['oneway']->machine_name . ' relationships',
+      'can have ' . $this->rtypes['twoway']->machine_name . ' relationships',
+      'can request ' . $this->rtypes['twoway']->machine_name . ' relationships',
+      'can have ' . $this->rtypes['approval_oneway']->machine_name . ' relationships',
+      'can request ' . $this->rtypes['approval_oneway']->machine_name . ' relationships',
+      'can have ' . $this->rtypes['approval']->machine_name . ' relationships',
+      'can request ' . $this->rtypes['approval']->machine_name . ' relationships',
+      'can have ' . $this->rtypes['approval_reciprocal']->machine_name . ' relationships',
+      'can request ' . $this->rtypes['approval_reciprocal']->machine_name . ' relationships',
     );
     $u1 = $this->drupalCreateUser($permissions);
     $u2 = $this->drupalCreateUser($permissions);
@@ -257,8 +263,8 @@ class UserRelationshipsTestCase extends UserRelationshipsBaseTestCase {
   function testNoOnewayRelationships() {
     $this->createDefaultRelationshipTypes(array('twoway'));
     $permissions = array(
-      'can have ' . $this->rtypes['twoway']->name . ' relationships',
-      'can request ' . $this->rtypes['twoway']->name . ' relationships',
+      'can have ' . $this->rtypes['twoway']->machine_name . ' relationships',
+      'can request ' . $this->rtypes['twoway']->machine_name . ' relationships',
     );
     $u1 = $this->drupalCreateUser($permissions);
     $u2 = $this->drupalCreateUser($permissions);
@@ -277,14 +283,14 @@ class UserRelationshipsTestCase extends UserRelationshipsBaseTestCase {
   function testUserRelationshipsLoadDuplicates() {
     $this->createDefaultRelationshipTypes();
     $permissions = array(
-      'can have ' . $this->rtypes['oneway']->name . ' relationships',
-      'can request ' . $this->rtypes['oneway']->name . ' relationships',
-      'can have ' . $this->rtypes['twoway']->name . ' relationships',
-      'can request ' . $this->rtypes['twoway']->name . ' relationships',
-      'can have ' . $this->rtypes['approval-oneway']->name . ' relationships',
-      'can request ' . $this->rtypes['approval-oneway']->name . ' relationships',
-      'can have ' . $this->rtypes['approval']->name . ' relationships',
-      'can request ' . $this->rtypes['approval']->name . ' relationships',
+      'can have ' . $this->rtypes['oneway']->machine_name . ' relationships',
+      'can request ' . $this->rtypes['oneway']->machine_name . ' relationships',
+      'can have ' . $this->rtypes['twoway']->machine_name . ' relationships',
+      'can request ' . $this->rtypes['twoway']->machine_name . ' relationships',
+      'can have ' . $this->rtypes['approval_oneway']->machine_name . ' relationships',
+      'can request ' . $this->rtypes['approval_oneway']->machine_name . ' relationships',
+      'can have ' . $this->rtypes['approval']->machine_name . ' relationships',
+      'can request ' . $this->rtypes['approval']->machine_name . ' relationships',
     );
     $u1 = $this->drupalCreateUser($permissions);
     $u2 = $this->drupalCreateUser($permissions);
@@ -337,10 +343,10 @@ class UserRelationshipsTestCase extends UserRelationshipsBaseTestCase {
 
     //test approved
     //load pending records
-    $this->assertTrue(user_relationships_can_request($u1, $this->rtypes['approval-oneway']));
-    user_relationships_request_relationship($u1, $u2, $this->rtypes['approval-oneway']->rtid, FALSE);
-    $this->assertTrue(user_relationships_can_request($u3, $this->rtypes['approval-oneway']));
-    user_relationships_request_relationship($u3, $u1, $this->rtypes['approval-oneway']->rtid, FALSE);
+    $this->assertTrue(user_relationships_can_request($u1, $this->rtypes['approval_oneway']));
+    user_relationships_request_relationship($u1, $u2, $this->rtypes['approval_oneway']->rtid, FALSE);
+    $this->assertTrue(user_relationships_can_request($u3, $this->rtypes['approval_oneway']));
+    user_relationships_request_relationship($u3, $u1, $this->rtypes['approval_oneway']->rtid, FALSE);
 
     $result = user_relationships_load(array('approved' => 1));
     $this->assertEqual(count($result), 5);
@@ -349,11 +355,11 @@ class UserRelationshipsTestCase extends UserRelationshipsBaseTestCase {
     $result = user_relationships_load(array('approved' => 1), array('sort' => 'rtid'));
     $this->assertEqual(count($result[$this->rtypes['oneway']->rtid]), 2);
     $this->assertEqual(count($result[$this->rtypes['twoway']->rtid]), 3);
-    $this->assertFalse(isset($result[$this->rtypes['approval-oneway']->rtid]));
+    $this->assertFalse(isset($result[$this->rtypes['approval_oneway']->rtid]));
     $result = user_relationships_load(array('approved' => 1), array('sort' => 'rtid', 'include_twoway_reverse' => 1));
     $this->assertEqual(count($result[$this->rtypes['oneway']->rtid]), 2);
     $this->assertEqual(count($result[$this->rtypes['twoway']->rtid]), 6);
-    $this->assertFalse(isset($result[$this->rtypes['approval-oneway']->rtid]));
+    $this->assertFalse(isset($result[$this->rtypes['approval_oneway']->rtid]));
     //test pending
     $result = user_relationships_load(array('approved' => 0));
     $this->assertEqual(count($result), 2);
@@ -361,10 +367,10 @@ class UserRelationshipsTestCase extends UserRelationshipsBaseTestCase {
     $this->assertEqual(count($result), 2);
     $result = user_relationships_load(array('approved' => 0), array('sort' => 'rtid'));
     $this->assertEqual(count($result), 1);
-    $this->assertEqual(count($result[$this->rtypes['approval-oneway']->rtid]), 2);
+    $this->assertEqual(count($result[$this->rtypes['approval_oneway']->rtid]), 2);
     $result = user_relationships_load(array('approved' => 0), array('sort' => 'rtid', 'include_twoway_reverse' => 1));
     $this->assertEqual(count($result), 1);
-    $this->assertEqual(count($result[$this->rtypes['approval-oneway']->rtid]), 2);
+    $this->assertEqual(count($result[$this->rtypes['approval_oneway']->rtid]), 2);
     //test user and pending
     $result = user_relationships_load(array('user' => $u1->uid, 'approved' => 0));
     $this->assertEqual(count($result), 2);
@@ -392,9 +398,9 @@ class UserRelationshipsTestCase extends UserRelationshipsBaseTestCase {
     $this->assertTrue(user_relationships_can_request($u1, $this->rtypes['approval']));
     $this->assertTrue(user_relationships_can_request($u3, $this->rtypes['approval']));
     $this->assertTrue(user_relationships_can_request($u4, $this->rtypes['approval']));
-    $this->assertTrue(user_relationships_can_request($u4, $this->rtypes['approval-oneway']));
-    user_relationships_request_relationship($u4, $u2, $this->rtypes['approval-oneway']->rtid, FALSE);
-    user_relationships_request_relationship($u3, $u4, $this->rtypes['approval-oneway']->rtid, FALSE);
+    $this->assertTrue(user_relationships_can_request($u4, $this->rtypes['approval_oneway']));
+    user_relationships_request_relationship($u4, $u2, $this->rtypes['approval_oneway']->rtid, FALSE);
+    user_relationships_request_relationship($u3, $u4, $this->rtypes['approval_oneway']->rtid, FALSE);
     user_relationships_request_relationship($u1, $u2, $this->rtypes['approval']->rtid, FALSE);
     user_relationships_request_relationship($u4, $u2, $this->rtypes['approval']->rtid, FALSE);
     user_relationships_request_relationship($u3, $u4, $this->rtypes['approval']->rtid, FALSE);
@@ -475,9 +481,9 @@ class UserRelationshipsTestCase extends UserRelationshipsBaseTestCase {
   function testUserRelationshipsReciprocalTypes() {
     $this->createDefaultRelationshipTypes();
     $rtypes = user_relationships_types_load();
-    $rtype = $rtypes[$this->rtypes['approval-reciprocal']->rtid];
+    $rtype = $rtypes[$this->rtypes['approval_reciprocal']->rtid];
     $this->assertTrue($rtype->is_reciprocal);
-    $rtype = $rtypes[$this->rtypes['approval-oneway']->rtid];
+    $rtype = $rtypes[$this->rtypes['approval_oneway']->rtid];
     $this->assertFalse($rtype->is_reciprocal);
     $rtype = $rtypes[$this->rtypes['approval']->rtid];
     $this->assertFalse($rtype->is_reciprocal);
@@ -511,6 +517,7 @@ class UserRelationshipsTypesTestCase extends DrupalWebTestCase {
     // Create relationship type.
     $relationship_type = (object) array(
       'name' => $this->randomName(),
+      'machine_name' => strtolower($this->randomName()),
       'plural_name' => $this->randomName(),
       'reverse_name' => $this->randomName(),
       'reverse_plural_name' => $this->randomName(),
@@ -601,6 +608,7 @@ class UserRelationshipsI18nTestCase extends DrupalWebTestCase {
     // Create relationship type.
     $edit = array(
       'name' => $this->randomName(),
+      'machine_name' => strtolower($this->randomName()),
       'plural_name' => $this->randomName(),
       'reverse_name' => $this->randomName(),
       'reverse_plural_name' => $this->randomName(),
diff --git a/user_relationships_ui/user_relationships_ui.module b/user_relationships_ui/user_relationships_ui.module
index 919b515..a29d3b2 100644
--- a/user_relationships_ui/user_relationships_ui.module
+++ b/user_relationships_ui/user_relationships_ui.module
@@ -228,11 +228,11 @@ function user_relationships_ui_init() {
 function user_relationships_ui_permission() {
   $permissions = array();
   foreach (user_relationships_types_load() as $type) {
-    $permissions['view own ' . $type->name . ' relationships'] = array(
+    $permissions['view own ' . $type->machine_name . ' relationships'] = array(
       'title' => t('View own %name relationships', array('%name' => $type->name)),
       'description' => t('The user is allowed to see his own relationships of this type.'),
     );
-    $permissions['view all ' . $type->name . ' relationships'] = array(
+    $permissions['view all ' . $type->machine_name . ' relationships'] = array(
       'title' => t('View all %name relationships', array('%name' => $type->name)),
       'description' => t('The user is allowed to see all relationships of this type.'),
     );
diff --git a/user_relationships_ui/user_relationships_ui.test b/user_relationships_ui/user_relationships_ui.test
index 3dd7b27..e8b0b73 100644
--- a/user_relationships_ui/user_relationships_ui.test
+++ b/user_relationships_ui/user_relationships_ui.test
@@ -29,6 +29,7 @@ class UserRelationshipUserSettings extends DrupalWebTestCase {
     // Create relationship types.
     $rtype = new StdClass;
     $rtype->name = 'oneway';
+    $rtype->machine_name = 'oneway';
     $rtype->plural_name = 'oneways';
     $rtype->is_oneway = TRUE;
     $rtype->requires_approval = FALSE;
@@ -38,6 +39,7 @@ class UserRelationshipUserSettings extends DrupalWebTestCase {
 
     $rtype = new StdClass;
     $rtype->name = 'twoway';
+    $rtype->machine_name = 'twoway';
     $rtype->plural_name = 'twoways';
     $rtype->is_oneway = FALSE;
     $rtype->requires_approval = FALSE;
@@ -48,6 +50,7 @@ class UserRelationshipUserSettings extends DrupalWebTestCase {
     unset($rtype);
     $rtype = new StdClass;
     $rtype->name = 'approval';
+    $rtype->machine_name = 'approval';
     $rtype->plural_name = 'approvals';
     $rtype->is_oneway = FALSE;
     $rtype->requires_approval = TRUE;
@@ -58,12 +61,13 @@ class UserRelationshipUserSettings extends DrupalWebTestCase {
     unset($rtype);
     $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;
+    $this->rtypes['approval_oneway'] = $rtype;
 
     drupal_static_reset('user_relationships_types_load');
 
@@ -83,10 +87,10 @@ class UserRelationshipUserSettings extends DrupalWebTestCase {
    */
   function testAutoApprovalSettings() {
     $permissions = array(
-      'can have ' . $this->rtypes['oneway']->name . ' relationships',
-      'can request ' . $this->rtypes['oneway']->name . ' relationships',
-      'can have ' . $this->rtypes['twoway']->name . ' relationships',
-      'can request ' . $this->rtypes['twoway']->name . ' relationships',
+      'can have ' . $this->rtypes['oneway']->machine_name . ' relationships',
+      'can request ' . $this->rtypes['oneway']->machine_name . ' relationships',
+      'can have ' . $this->rtypes['twoway']->machine_name . ' relationships',
+      'can request ' . $this->rtypes['twoway']->machine_name . ' relationships',
       'view own twoway relationships',
       'view own oneway relationships',
     );
@@ -99,14 +103,14 @@ class UserRelationshipUserSettings extends DrupalWebTestCase {
     $u2 = $this->drupalCreateUser($permissions);
 
     // Two users with all required permissions.
-    $permissions[] = 'can have ' . $this->rtypes['approval-oneway']->name . ' relationships';
-    $permissions[] =  'can request ' . $this->rtypes['approval-oneway']->name . ' relationships';
-    $permissions[] =  'can have ' . $this->rtypes['approval']->name . ' relationships';
-    $permissions[] =  'can request ' . $this->rtypes['approval']->name . ' relationships';
+    $permissions[] = 'can have ' . $this->rtypes['approval_oneway']->machine_name . ' relationships';
+    $permissions[] = 'can request ' . $this->rtypes['approval_oneway']->machine_name . ' relationships';
+    $permissions[] = 'can have ' . $this->rtypes['approval']->machine_name . ' relationships';
+    $permissions[] = 'can request ' . $this->rtypes['approval']->machine_name . ' relationships';
     $permissions[] = 'maintain approval relationships';
-    $permissions[] = 'maintain approval-oneway relationships';
+    $permissions[] = 'maintain approval_oneway relationships';
     $permissions[] = 'view own approval relationships';
-    $permissions[] = 'view own approval-oneway relationships';
+    $permissions[] = 'view own approval_oneway relationships';
 
     $u3 = $this->drupalCreateUser($permissions);
     $u4 = $this->drupalCreateUser($permissions);
@@ -145,18 +149,18 @@ class UserRelationshipUserSettings extends DrupalWebTestCase {
     $this->assertText(t('Automatically approve relationship requests from other users'));
     $this->assertText(t('Receive e-mail notification of relationship activity'));
     $this->assertFieldByName('user_relationships_ui_auto_approve[' . $this->rtypes['approval']->rtid . ']');
-    $this->assertFieldByName('user_relationships_ui_auto_approve[' . $this->rtypes['approval-oneway']->rtid . ']');
+    $this->assertFieldByName('user_relationships_ui_auto_approve[' . $this->rtypes['approval_oneway']->rtid . ']');
     $this->assertNoFieldByName('user_relationships_ui_auto_approve[' . $this->rtypes['oneway']->rtid . ']');
     $this->assertNoFieldByName('user_relationships_ui_auto_approve[' . $this->rtypes['twoway']->rtid . ']');
 
-    // Enable auto approval for the approval-oneway type.
+    // Enable auto approval for the approval_oneway type.
     $edit = array(
-      'user_relationships_ui_auto_approve[' . $this->rtypes['approval-oneway']->rtid . ']' => TRUE,
+      'user_relationships_ui_auto_approve[' . $this->rtypes['approval_oneway']->rtid . ']' => TRUE,
     );
     $this->drupalPost(NULL, $edit, t('Save'));
 
     // Verify that the defaults are set correctly.
-    $this->assertFieldChecked('edit-user-relationships-ui-auto-approve-' . $this->rtypes['approval-oneway']->rtid);
+    $this->assertFieldChecked('edit-user-relationships-ui-auto-approve-' . $this->rtypes['approval_oneway']->rtid);
     $this->assertNoFieldChecked('edit-user-relationships-ui-auto-approve-' . $this->rtypes['approval']->rtid);
 
     // Finally, actually verify that the settings work.
@@ -166,15 +170,15 @@ class UserRelationshipUserSettings extends DrupalWebTestCase {
     $this->drupalPost('relationship/' . $u3->uid . '/request/' . $this->rtypes['approval']->rtid, array(), t('Send'));
     $this->assertText(t('Your approval request has been sent to @user.', array('@user' => $u3->name)));
 
-    // Request approval-oneway relationships, should approve automatically.
-    $this->drupalPost('relationship/' . $u3->uid . '/request/' . $this->rtypes['approval-oneway']->rtid, array(), t('Send'));
+    // Request approval_oneway relationships, should approve automatically.
+    $this->drupalPost('relationship/' . $u3->uid . '/request/' . $this->rtypes['approval_oneway']->rtid, array(), t('Send'));
     $this->assertText(t("You are @user's newest approval-oneway.", array('@user' => $u3->name)));
 
     // Load relationships between these two users.
     $relationships = user_relationships_load(array('between' => array($u3->uid, $u4->uid)));
     $this->assertEqual(count($relationships), 2);
     foreach ($relationships as $relationship) {
-      if ($relationship->rtid == $this->rtypes['approval-oneway']->rtid) {
+      if ($relationship->rtid == $this->rtypes['approval_oneway']->rtid) {
         $this->assertTrue((bool) $relationship->approved);
       }
       elseif ($relationship->rtid == $this->rtypes['approval']->rtid) {
-- 
1.7.12.4 (Apple Git-37)

