#!/usr/bin/env php array() ); $form_state['values']['name'] = 'test-group'; $form_state['values']['type'] = 'test_group'; $form_state['values']['og_content_type_usage'] = 'group'; drupal_execute('node_type_form',$form_state); $form_state = array( 'values'=>array() ); $form_state['values']['name'] = 'test-post-group'; $form_state['values']['type'] = 'test_post_group'; $form_state['values']['og_content_type_usage'] = 'group_post_standard'; drupal_execute('node_type_form',$form_state); // Create users with ID 3 to 7. $user_ids=array(); foreach (range(3, 7) as $i) { $user_values = array(); $user_values['name'] = 'og_test_user' . $i; $user_values['mail'] = 'og_test_user' . $i . '@example.com'; $user_values['pass'] = user_password(5); $user_values['status'] = 1; $user = user_save(NULL,$user_values); $user_ids[$i] = $user->uid; } /** * Organic groups content generation interface. */ interface ogContent { //Returns a list of groups configuration arrays. public function groupList($user_ids); // Returns a list of posts configuation arrays // Groups nids generated in groupList are provided in groups parameter. public function postList($user_ids, $groups); // Performs actions of the generated groups and posts. public function groupActions($user_ids, $groups, $posts); } /** * A group without posts. */ class ogGroupNoPosts implements ogContent { public function groupList($user_ids) { $list = array(); $list[] = array( 'title' => 'group-without-posts', 'uid' => $user_ids[3], 'body' => 'group without posts' ); return $list; } public function postList($user_ids, $groups) { return array(); } public function groupActions($user_ids, $groups, $posts) {} } /** * A group with three posts. */ class ogGroupThreePosts implements ogContent { public function groupList($user_ids) { $list = array(); $list[] = array( 'title' => 'group-with-3-posts', 'uid' => $user_ids[3], 'body' => 'group with 3 posts' ); return $list; } public function postList($user_ids, $groups) { $gid = $groups[0]; $list = array(); foreach ( array(1,2,3) as $itr){ $list[] = array( 'title' => 'group-posts-' . $itr, 'uid' => $user_ids[3], 'body' => 'group posts ' . $itr, 'og_groups' => array($gid) ); } return $list; } public function groupActions($user_ids, $groups, $posts){} } /** * A group post not associated to any other group. */ class ogGroupOrphanPost implements ogContent { public function groupList($user_ids) { return array(); } public function postList($user_ids, $groups) { $list = array(); $list[] = array( 'title' => 'group-posts-orphan', 'uid' => $user_ids[3], 'body' => 'group posts orphan', 'og_groups' => array() ); return $list; } public function groupActions($user_ids, $groups, $posts){} } /** * A group post associated with two groups. */ class ogGroupPostMultipleGroups implements ogContent { public function groupList($user_ids) { $list = array(); $list['alpha'] = array( 'title' => 'group-alpha', 'uid' => $user_ids[3], 'body' => 'group alpha' ); $list['beta'] =array( 'title' => 'group-beta', 'uid' => $user_ids[3], 'body' => 'group beta' ); return $list; } public function postList($user_ids, $groups) { $list = array(); $gid_b = $groups['beta']; $gid_a = $groups['alpha']; $list[] = array( 'title' => 'group-posts-ab', 'uid' => $user_ids[3], 'body' => 'group posts ab', 'og_groups' => array($gid_a,$gid_b) ); return $list; } public function groupActions($user_ids, $groups, $posts) {} } /** * A group with multiple members. */ class ogGroupUserAction implements ogContent { public function groupList($user_ids) { $list = array(); $list[] = array( 'title' => 'group-with-user-action', 'uid' => $user_ids[3], 'body' => 'group with user action' ); return $list; } public function postList($user_ids, $groups) { return array(); } public function groupActions($user_ids, $groups, $posts){ $gid = $groups[0]; // - user ID 4 as pending member. og_save_subscription( $gid , $user_ids[4] , array('is_active' => 0)); // - user ID 5 as active member. og_save_subscription( $gid , $user_ids[5] , array('is_active' => 1)); // - user ID 6 as pending admin member. og_save_subscription( $gid , $user_ids[6] , array('is_active' => 0 , 'is_admin' => 1)); // - user ID 7 as active admin member. og_save_subscription( $gid , $user_ids[7] , array('is_active' => 1 , 'is_admin' => 1)); } } // Start content generation. $og_content_config = array(); $og_content_config[] = new ogGroupNoPosts(); $og_content_config[] = new ogGroupThreePosts(); $og_content_config[] = new ogGroupOrphanPost(); $og_content_config[] = new ogGroupPostMultipleGroups(); $og_content_config[] = new ogGroupUserAction(); foreach ($og_content_config as $content_config){ $groups = array_map('og_group_node' , $content_config->groupList($user_ids) ); $posts = array_map('og_post_node', $content_config->postList($user_ids, $groups)); $content_config->groupActions($user_ids, $groups, $posts); } /** * Create a group node. */ function og_group_node($values = array()) { $node=(object)$values; $node->type = 'test_group'; node_save($node); return $node->nid; } /** * Create a group post. */ function og_post_node($values = array()){ $node=(object)$values; $node->type = 'test_post_group'; node_save($node); return $node->nid; }