Mercurial > defr > drupal > og_statistics
diff og_statistics.test @ 2:48f07e7acaca
OG Stats 1.0-rc2
author | Franck Deroche <franck@defr.org> |
---|---|
date | Tue, 24 Nov 2009 14:27:37 +0100 |
parents | 9ce879ecbce6 |
children |
line wrap: on
line diff
--- a/og_statistics.test Tue Nov 24 14:25:13 2009 +0100 +++ b/og_statistics.test Tue Nov 24 14:27:37 2009 +0100 @@ -1,5 +1,5 @@ <?php -// $Id: og_statistics.test,v 1.2.2.2 2009/06/05 22:38:12 dereine Exp $ +// $Id: og_statistics.test,v 1.2.2.6 2009/09/07 19:22:31 dereine Exp $ /** * Test file for og_statitics. @@ -11,7 +11,7 @@ require_once drupal_get_path('module', 'og') .'/tests/og_testcase.php'; class OgStatisticsTestCase extends OgTestCase { - function getInfo() { + public static function getInfo() { return array( 'name' => t('Organic groups statistics'), 'description' => t('tests statistics of og_statistics module'), @@ -20,7 +20,7 @@ } function setUp() { - parent::setUp('node', 'user', 'comment', 'views', 'og', 'og_views', 'og_statistics', 'og_access'); + parent::setUp('node', 'user', 'comment', 'views', 'og', 'og_views', 'og_statistics', 'og_access', 'devel'); // Create a user with admin permissions. $web_admin = $this->drupalCreateUser(array('administer nodes', 'administer content types', 'access administration pages', 'administer site configuration', 'administer organic groups')); @@ -48,7 +48,6 @@ $members = $empty = FALSE; - $this->assertFalse($empty, print_r($stat, TRUE)); foreach ($stat as $key => $item) { $empty = $empty || $item == TRUE; } @@ -82,6 +81,8 @@ $this->assertTrue($count_one_up, 'A node post in a group, counts the counter 1 up'); $this->assertEqual($node->created, $after['last_node_timestamp'], 'A node post in a group, sets the last node timestamp'); + $this->assertEqual($node->nid, $after['last_node_nid'], 'A node post in a group sets the last node nid'); + $this->assertEqual($node->uid, $after['last_node_uid'], 'A node post in a group sets the last node uid'); // remove the post node_delete($nid); @@ -92,8 +93,15 @@ $this->assertTrue($count_down, 'A node poast in a group was deleted, counts the counter 1 down'); } + function drupalCreateComment($edit) { + if ($cid = comment_save($edit)) { + return $cid; + } + } + // Tests comments hooks statistic function TestOgStatisticsComment() { + global $user; // Create a group node content type. $og_group_type = $this->drupalCreateContentType(); variable_set('og_content_type_usage_'. $og_group_type->name, 'group'); @@ -111,19 +119,49 @@ // add a test post $nids[] = $nid = $this->addOgPost($og_post_type->name, array($gid)); + $node = node_load($nid); // adds some comments $edit = array(); $edit['subject'] = $this->randomName(10); $edit['comment'] = $this->randomName(50); $edit['nid'] = $nid; - $cid = comment_save($edit); + $edit['format'] = FILTER_FORMAT_DEFAULT; + $edit['node'] = $node; + $edit['uid'] = $user->uid; + $edit['pid'] = NULL; + $edit['cid'] = NULL; + $cid = $this->drupalCreateComment($edit); $comment = _comment_load($cid); $after = og_statistics_load($gid); $count_up = ($after['comments_count'] - $before['comments_count']) == 1; $this->assertTrue($count_up, 'new comment to one group post, counts up the comment counter'); $this->assertEqual($comment->timestamp, $after['last_comment_timestamp'], 'new comment to one group post, counts up the comment counter'); + $this->assertEqual($comment->cid, $after['last_comment_cid'], 'New comment to one group post sets the last comment cid.'); + $this->assertEqual($comment->nid, $after['last_comment_nid'], 'New comment to one group post sets the last comment nid.'); + $this->assertEqual($comment->uid, $after['last_comment_uid'], 'New comment to one group post sets the last comment uid.'); + + // add another comment. + + $edit = array(); + $edit['subject'] = $this->randomName(10); + $edit['comment'] = $this->randomName(50); + $edit['nid'] = $nid; + $edit['format'] = FILTER_FORMAT_DEFAULT; + $edit['node'] = $node; + $edit['uid'] = $user->uid; + $edit['pid'] = NULL; + $edit['cid'] = NULL; + $cid = $this->drupalCreateComment($edit); + + // Remove the node and check whether comment count is updated + // reload the node, to update the stats. + $node = node_load($node, NULL, TRUE); + + node_delete($nid); + $stat = og_statistics_load($gid); + $this->assertEqual($stat['comments_count'], 0, 'all comments were deleted'); } function TestOgStatisticsOg() { @@ -153,6 +191,32 @@ $this->assertTrue($count_up, 'New subscription to a group adds the counter 1 up'); $this->assertEqual($time, $after['last_member_timestamp'], 'New subscription to a group adds the counter 1 up'); + $this->assertEqual($account->uid, $after['last_member_uid'], 'New subscription to a group sets the last member uid.'); + } + + function TestOgStatisticsDelete() { + // Create a group node content type. + $og_group_type = $this->drupalCreateContentType(); + variable_set('og_content_type_usage_'. $og_group_type->name, 'group'); + + // Create a group post content type. + $og_post_type = $this->drupalCreateContentType(); + variable_set('og_content_type_usage_'. $og_post_type->name, 'group_post_standard'); + + // Rebuild the menu so the new content types will appear in the menu. + menu_rebuild(); + + $gid = $this->addOgGroup($og_group_type->name); + // create a test group + $gid = $this->addOgGroup($og_group_type->name); + $before = og_statistics_load($gid); + + // Delete the node, the stat-record should be deleted too. + $node = node_load($gid); + node_delete($node->nid); + $after = og_statistics_load($gid); + + $this->assertTrue(empty($after), 'Og statistics record get deleted'); } }