summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmitaibu2013-01-16 13:08:58 (GMT)
committer Amitaibu2013-01-16 13:08:58 (GMT)
commitf55bb8bac0c6ffc61f9d5ec68eeb49fcdcbb4440 (patch)
tree957508334b957ae4318dd21f3f0d06ee0d998e9f
parent908cd93b485ac5ec2f0ab6410b12859d3a8033fd (diff)
Add og-test stuff.
-rw-r--r--og.test28
-rw-r--r--tests/og_test.module24
2 files changed, 40 insertions, 12 deletions
diff --git a/og.test b/og.test
index 40127aa..9f78b23 100644
--- a/og.test
+++ b/og.test
@@ -1496,10 +1496,10 @@ class OgBehaviorHandlerTestCase extends DrupalWebTestCase {
// Add OG group field to the entity_test's "main" bundle.
og_create_field(OG_GROUP_FIELD, 'entity_test', 'main');
- $type = $this->drupalCreateContentType();
+ $type = $this->drupalCreateContentType(array('type' => 'behavior'));
$this->group_content = $type->type;
- // Add OG audience field to the node's "article" bundle.
+ // Add OG audience field to the new bundle.
$og_field = og_fields_info(OG_AUDIENCE_FIELD);
$og_field['field']['settings']['target_type'] = 'entity_test';
og_create_field(OG_AUDIENCE_FIELD, 'node', $type->type, $og_field);
@@ -1569,13 +1569,15 @@ class OgBehaviorHandlerTestCase extends DrupalWebTestCase {
}
/**
- * Test settings the OG memnership state via field values, when associating
+ * Test settings the OG membership state via field values, when associating
* a new group-content to a group.
*/
function testSetStateOnInsert() {
+ module_enable(array('og_test'));
$permissions = array(
'access content',
"create $this->group_content content",
+ 'administer group',
);
$user1 = $this->drupalCreateUser();
$user2 = $this->drupalCreateUser($permissions);
@@ -1593,25 +1595,27 @@ class OgBehaviorHandlerTestCase extends DrupalWebTestCase {
// Post a node, state should be active.
$type = str_replace('_', '-', $this->group_content);
$edit = array(
- 'title' => $this->randomName(),
+ 'title' => 'state-active',
+ 'og_group_ref[und][0][default][]' => array($entity1->pid),
);
$this->drupalLogin($user2);
-
- $this->drupalGet('node/add/' . $type);
$this->drupalPost('node/add/' . $type, $edit, t('Save'));
- $gids = og_get_entity_groups('user', $user2);
+ $gids = og_get_entity_groups('node', 1);
+ $id = key($gids['entity_test']);
+ $og_membership = og_membership_load($id);
+ $this->assertEqual($og_membership->state, OG_STATE_ACTIVE, 'Memebership status is Active');
// Post a node, state should be pending.
$this->drupalLogin($user3);
- $edit = array(
- 'title' => $this->randomName(),
- );
+ $edit['title'] = 'state-pending';
$this->drupalPost('node/add/' . $type, $edit, t('Save'));
- $gids = og_get_entity_groups('user', $user3, array(OG_STATE_PENDING));
-
+ $gids = og_get_entity_groups('node', 2, array(OG_STATE_PENDING));
+ $id = key($gids['entity_test']);
+ $og_membership = og_membership_load($id);
+ $this->assertEqual($og_membership->state, OG_STATE_PENDING, 'Memebership status is Active');
}
}
diff --git a/tests/og_test.module b/tests/og_test.module
index d6369e4..295c221 100644
--- a/tests/og_test.module
+++ b/tests/og_test.module
@@ -62,3 +62,27 @@ function og_test_entity_delete($entity, $type) {
),
);
}
+
+/**
+ * Implements hook_form_alter().
+ *
+ * @see OgBehaviorHandlerTestCase::testSetStateOnInsert()
+ */
+function og_test_form_alter(&$form, $form_state) {
+ if (empty($form['#edit_node']) || $form['#bundle'] != 'behavior') {
+ return;
+ }
+
+ $form[OG_AUDIENCE_FIELD]['#element_validate'][] = 'og_test_form_behavior_validate';
+}
+
+/**
+ * Validate handler; Add state to the field values, if title is "state-pending".
+. */
+function og_test_form_behavior_validate($element, &$form_state) {
+ if ($form_state['values']['title'] != 'state-pending') {
+ return;
+ }
+
+ $form_state['values'][OG_AUDIENCE_FIELD][LANGUAGE_NONE][0]['state'] = OG_STATE_PENDING;
+}