franck@0: t('Organic groups statistics'), franck@0: 'description' => t('tests statistics of og_statistics module'), franck@0: 'group' => t('Organic groups'), franck@0: ); franck@0: } franck@0: franck@0: function setUp() { franck@2: parent::setUp('node', 'user', 'comment', 'views', 'og', 'og_views', 'og_statistics', 'og_access', 'devel'); franck@0: franck@0: // Create a user with admin permissions. franck@0: $web_admin = $this->drupalCreateUser(array('administer nodes', 'administer content types', 'access administration pages', 'administer site configuration', 'administer organic groups')); franck@0: $this->drupalLogin($web_admin); franck@0: } franck@0: franck@0: function TestOgStatisticsWritePureRecord() { franck@0: // Create a group node content type. franck@0: $og_group_type = $this->drupalCreateContentType(); franck@0: variable_set('og_content_type_usage_'. $og_group_type->name, 'group'); franck@0: franck@0: // Create a group post content type. franck@0: $og_post_type = $this->drupalCreateContentType(); franck@0: variable_set('og_content_type_usage_'. $og_post_type->name, 'group_post_standard'); franck@0: franck@0: // Rebuild the menu so the new content types will appear in the menu. franck@0: menu_rebuild(); franck@0: franck@0: // Create a group node. franck@0: $gid = $this->addOgGroup($og_group_type->name); franck@0: franck@0: // get the record of the group franck@0: $stat = og_statistics_load($gid); franck@0: unset($stat['nid']); franck@0: $members = franck@0: franck@0: $empty = FALSE; franck@0: foreach ($stat as $key => $item) { franck@0: $empty = $empty || $item == TRUE; franck@0: } franck@0: $this->assertFalse($empty, t('All stats should have 0 as item')); franck@0: } franck@0: franck@0: // Tests nodeapi statistics. franck@0: function TestOgStatisticsNodeapi() { franck@0: // Create a group node content type. franck@0: $og_group_type = $this->drupalCreateContentType(); franck@0: variable_set('og_content_type_usage_'. $og_group_type->name, 'group'); franck@0: franck@0: // Create a group post content type. franck@0: $og_post_type = $this->drupalCreateContentType(); franck@0: variable_set('og_content_type_usage_'. $og_post_type->name, 'group_post_standard'); franck@0: franck@0: // Rebuild the menu so the new content types will appear in the menu. franck@0: menu_rebuild(); franck@0: franck@0: // create a test group franck@0: $gid = $this->addOgGroup($og_group_type->name); franck@0: $before = og_statistics_load($gid); franck@0: franck@0: // add a test post franck@0: $nids[] = $nid = $this->addOgPost($og_post_type->name, array($gid)); franck@0: $node = node_load($nid); franck@0: // Rebuild the menu so the new content types will appear in the menu. franck@0: menu_rebuild(); franck@0: $after = og_statistics_load($gid); franck@0: $count_one_up = ($after['posts_count'] - $before['posts_count']) == 1; franck@0: franck@0: $this->assertTrue($count_one_up, 'A node post in a group, counts the counter 1 up'); franck@0: $this->assertEqual($node->created, $after['last_node_timestamp'], 'A node post in a group, sets the last node timestamp'); franck@2: $this->assertEqual($node->nid, $after['last_node_nid'], 'A node post in a group sets the last node nid'); franck@2: $this->assertEqual($node->uid, $after['last_node_uid'], 'A node post in a group sets the last node uid'); franck@0: franck@0: // remove the post franck@0: node_delete($nid); franck@0: $before = $after; franck@0: $after = og_statistics_load($gid); franck@0: $count_down = ($after['posts_count'] - $before['posts_count']) == -1; franck@0: franck@0: $this->assertTrue($count_down, 'A node poast in a group was deleted, counts the counter 1 down'); franck@0: } franck@0: franck@2: function drupalCreateComment($edit) { franck@2: if ($cid = comment_save($edit)) { franck@2: return $cid; franck@2: } franck@2: } franck@2: franck@0: // Tests comments hooks statistic franck@0: function TestOgStatisticsComment() { franck@2: global $user; franck@0: // Create a group node content type. franck@0: $og_group_type = $this->drupalCreateContentType(); franck@0: variable_set('og_content_type_usage_'. $og_group_type->name, 'group'); franck@0: franck@0: // Create a group post content type. franck@0: $og_post_type = $this->drupalCreateContentType(); franck@0: variable_set('og_content_type_usage_'. $og_post_type->name, 'group_post_standard'); franck@0: franck@0: // Rebuild the menu so the new content types will appear in the menu. franck@0: menu_rebuild(); franck@0: franck@0: // create a test group franck@0: $gid = $this->addOgGroup($og_group_type->name); franck@0: $before = og_statistics_load($gid); franck@0: franck@0: // add a test post franck@0: $nids[] = $nid = $this->addOgPost($og_post_type->name, array($gid)); franck@2: $node = node_load($nid); franck@0: franck@0: // adds some comments franck@0: $edit = array(); franck@0: $edit['subject'] = $this->randomName(10); franck@0: $edit['comment'] = $this->randomName(50); franck@0: $edit['nid'] = $nid; franck@2: $edit['format'] = FILTER_FORMAT_DEFAULT; franck@2: $edit['node'] = $node; franck@2: $edit['uid'] = $user->uid; franck@2: $edit['pid'] = NULL; franck@2: $edit['cid'] = NULL; franck@2: $cid = $this->drupalCreateComment($edit); franck@0: $comment = _comment_load($cid); franck@0: franck@0: $after = og_statistics_load($gid); franck@0: $count_up = ($after['comments_count'] - $before['comments_count']) == 1; franck@0: $this->assertTrue($count_up, 'new comment to one group post, counts up the comment counter'); franck@0: $this->assertEqual($comment->timestamp, $after['last_comment_timestamp'], 'new comment to one group post, counts up the comment counter'); franck@2: $this->assertEqual($comment->cid, $after['last_comment_cid'], 'New comment to one group post sets the last comment cid.'); franck@2: $this->assertEqual($comment->nid, $after['last_comment_nid'], 'New comment to one group post sets the last comment nid.'); franck@2: $this->assertEqual($comment->uid, $after['last_comment_uid'], 'New comment to one group post sets the last comment uid.'); franck@2: franck@2: // add another comment. franck@2: franck@2: $edit = array(); franck@2: $edit['subject'] = $this->randomName(10); franck@2: $edit['comment'] = $this->randomName(50); franck@2: $edit['nid'] = $nid; franck@2: $edit['format'] = FILTER_FORMAT_DEFAULT; franck@2: $edit['node'] = $node; franck@2: $edit['uid'] = $user->uid; franck@2: $edit['pid'] = NULL; franck@2: $edit['cid'] = NULL; franck@2: $cid = $this->drupalCreateComment($edit); franck@2: franck@2: // Remove the node and check whether comment count is updated franck@2: // reload the node, to update the stats. franck@2: $node = node_load($node, NULL, TRUE); franck@2: franck@2: node_delete($nid); franck@2: $stat = og_statistics_load($gid); franck@2: $this->assertEqual($stat['comments_count'], 0, 'all comments were deleted'); franck@0: } franck@0: franck@0: function TestOgStatisticsOg() { franck@0: // Create a group node content type. franck@0: $og_group_type = $this->drupalCreateContentType(); franck@0: variable_set('og_content_type_usage_'. $og_group_type->name, 'group'); franck@0: franck@0: // Create a group post content type. franck@0: $og_post_type = $this->drupalCreateContentType(); franck@0: variable_set('og_content_type_usage_'. $og_post_type->name, 'group_post_standard'); franck@0: franck@0: // Rebuild the menu so the new content types will appear in the menu. franck@0: menu_rebuild(); franck@0: franck@0: // create a test group franck@0: $gid = $this->addOgGroup($og_group_type->name); franck@0: $before = og_statistics_load($gid); franck@0: franck@0: // let one member choine the group franck@0: $account = $this->drupalCreateUser(); franck@0: $time = time(); franck@0: og_save_subscription($gid, $account->uid, array('created' => $time)); franck@0: franck@0: $after = og_statistics_load($gid); franck@0: franck@0: $count_up = ($after['members_count'] - $before['members_count']) == 1; franck@0: franck@0: $this->assertTrue($count_up, 'New subscription to a group adds the counter 1 up'); franck@0: $this->assertEqual($time, $after['last_member_timestamp'], 'New subscription to a group adds the counter 1 up'); franck@2: $this->assertEqual($account->uid, $after['last_member_uid'], 'New subscription to a group sets the last member uid.'); franck@2: } franck@2: franck@2: function TestOgStatisticsDelete() { franck@2: // Create a group node content type. franck@2: $og_group_type = $this->drupalCreateContentType(); franck@2: variable_set('og_content_type_usage_'. $og_group_type->name, 'group'); franck@2: franck@2: // Create a group post content type. franck@2: $og_post_type = $this->drupalCreateContentType(); franck@2: variable_set('og_content_type_usage_'. $og_post_type->name, 'group_post_standard'); franck@2: franck@2: // Rebuild the menu so the new content types will appear in the menu. franck@2: menu_rebuild(); franck@2: franck@2: $gid = $this->addOgGroup($og_group_type->name); franck@2: // create a test group franck@2: $gid = $this->addOgGroup($og_group_type->name); franck@2: $before = og_statistics_load($gid); franck@2: franck@2: // Delete the node, the stat-record should be deleted too. franck@2: $node = node_load($gid); franck@2: node_delete($node->nid); franck@2: $after = og_statistics_load($gid); franck@2: franck@2: $this->assertTrue(empty($after), 'Og statistics record get deleted'); franck@0: } franck@0: } franck@0: