annotate og_statistics.test @ 3:13824d66b299 tip

Application du patch sur la 1.0-rc2
author Franck Deroche <franck@defr.org>
date Tue, 24 Nov 2009 14:30:14 +0100
parents 48f07e7acaca
children
rev   line source
franck@0 1 <?php
franck@2 2 // $Id: og_statistics.test,v 1.2.2.6 2009/09/07 19:22:31 dereine Exp $
franck@0 3
franck@0 4 /**
franck@0 5 * Test file for og_statitics.
franck@0 6 *
franck@0 7 * @TODO Use multiple groups for testing.
franck@0 8 * @TODO Abstract part of the tests.
franck@0 9 */
franck@0 10
franck@0 11 require_once drupal_get_path('module', 'og') .'/tests/og_testcase.php';
franck@0 12
franck@0 13 class OgStatisticsTestCase extends OgTestCase {
franck@2 14 public static function getInfo() {
franck@0 15 return array(
franck@0 16 'name' => t('Organic groups statistics'),
franck@0 17 'description' => t('tests statistics of og_statistics module'),
franck@0 18 'group' => t('Organic groups'),
franck@0 19 );
franck@0 20 }
franck@0 21
franck@0 22 function setUp() {
franck@2 23 parent::setUp('node', 'user', 'comment', 'views', 'og', 'og_views', 'og_statistics', 'og_access', 'devel');
franck@0 24
franck@0 25 // Create a user with admin permissions.
franck@0 26 $web_admin = $this->drupalCreateUser(array('administer nodes', 'administer content types', 'access administration pages', 'administer site configuration', 'administer organic groups'));
franck@0 27 $this->drupalLogin($web_admin);
franck@0 28 }
franck@0 29
franck@0 30 function TestOgStatisticsWritePureRecord() {
franck@0 31 // Create a group node content type.
franck@0 32 $og_group_type = $this->drupalCreateContentType();
franck@0 33 variable_set('og_content_type_usage_'. $og_group_type->name, 'group');
franck@0 34
franck@0 35 // Create a group post content type.
franck@0 36 $og_post_type = $this->drupalCreateContentType();
franck@0 37 variable_set('og_content_type_usage_'. $og_post_type->name, 'group_post_standard');
franck@0 38
franck@0 39 // Rebuild the menu so the new content types will appear in the menu.
franck@0 40 menu_rebuild();
franck@0 41
franck@0 42 // Create a group node.
franck@0 43 $gid = $this->addOgGroup($og_group_type->name);
franck@0 44
franck@0 45 // get the record of the group
franck@0 46 $stat = og_statistics_load($gid);
franck@0 47 unset($stat['nid']);
franck@0 48 $members =
franck@0 49
franck@0 50 $empty = FALSE;
franck@0 51 foreach ($stat as $key => $item) {
franck@0 52 $empty = $empty || $item == TRUE;
franck@0 53 }
franck@0 54 $this->assertFalse($empty, t('All stats should have 0 as item'));
franck@0 55 }
franck@0 56
franck@0 57 // Tests nodeapi statistics.
franck@0 58 function TestOgStatisticsNodeapi() {
franck@0 59 // Create a group node content type.
franck@0 60 $og_group_type = $this->drupalCreateContentType();
franck@0 61 variable_set('og_content_type_usage_'. $og_group_type->name, 'group');
franck@0 62
franck@0 63 // Create a group post content type.
franck@0 64 $og_post_type = $this->drupalCreateContentType();
franck@0 65 variable_set('og_content_type_usage_'. $og_post_type->name, 'group_post_standard');
franck@0 66
franck@0 67 // Rebuild the menu so the new content types will appear in the menu.
franck@0 68 menu_rebuild();
franck@0 69
franck@0 70 // create a test group
franck@0 71 $gid = $this->addOgGroup($og_group_type->name);
franck@0 72 $before = og_statistics_load($gid);
franck@0 73
franck@0 74 // add a test post
franck@0 75 $nids[] = $nid = $this->addOgPost($og_post_type->name, array($gid));
franck@0 76 $node = node_load($nid);
franck@0 77 // Rebuild the menu so the new content types will appear in the menu.
franck@0 78 menu_rebuild();
franck@0 79 $after = og_statistics_load($gid);
franck@0 80 $count_one_up = ($after['posts_count'] - $before['posts_count']) == 1;
franck@0 81
franck@0 82 $this->assertTrue($count_one_up, 'A node post in a group, counts the counter 1 up');
franck@0 83 $this->assertEqual($node->created, $after['last_node_timestamp'], 'A node post in a group, sets the last node timestamp');
franck@2 84 $this->assertEqual($node->nid, $after['last_node_nid'], 'A node post in a group sets the last node nid');
franck@2 85 $this->assertEqual($node->uid, $after['last_node_uid'], 'A node post in a group sets the last node uid');
franck@0 86
franck@0 87 // remove the post
franck@0 88 node_delete($nid);
franck@0 89 $before = $after;
franck@0 90 $after = og_statistics_load($gid);
franck@0 91 $count_down = ($after['posts_count'] - $before['posts_count']) == -1;
franck@0 92
franck@0 93 $this->assertTrue($count_down, 'A node poast in a group was deleted, counts the counter 1 down');
franck@0 94 }
franck@0 95
franck@2 96 function drupalCreateComment($edit) {
franck@2 97 if ($cid = comment_save($edit)) {
franck@2 98 return $cid;
franck@2 99 }
franck@2 100 }
franck@2 101
franck@0 102 // Tests comments hooks statistic
franck@0 103 function TestOgStatisticsComment() {
franck@2 104 global $user;
franck@0 105 // Create a group node content type.
franck@0 106 $og_group_type = $this->drupalCreateContentType();
franck@0 107 variable_set('og_content_type_usage_'. $og_group_type->name, 'group');
franck@0 108
franck@0 109 // Create a group post content type.
franck@0 110 $og_post_type = $this->drupalCreateContentType();
franck@0 111 variable_set('og_content_type_usage_'. $og_post_type->name, 'group_post_standard');
franck@0 112
franck@0 113 // Rebuild the menu so the new content types will appear in the menu.
franck@0 114 menu_rebuild();
franck@0 115
franck@0 116 // create a test group
franck@0 117 $gid = $this->addOgGroup($og_group_type->name);
franck@0 118 $before = og_statistics_load($gid);
franck@0 119
franck@0 120 // add a test post
franck@0 121 $nids[] = $nid = $this->addOgPost($og_post_type->name, array($gid));
franck@2 122 $node = node_load($nid);
franck@0 123
franck@0 124 // adds some comments
franck@0 125 $edit = array();
franck@0 126 $edit['subject'] = $this->randomName(10);
franck@0 127 $edit['comment'] = $this->randomName(50);
franck@0 128 $edit['nid'] = $nid;
franck@2 129 $edit['format'] = FILTER_FORMAT_DEFAULT;
franck@2 130 $edit['node'] = $node;
franck@2 131 $edit['uid'] = $user->uid;
franck@2 132 $edit['pid'] = NULL;
franck@2 133 $edit['cid'] = NULL;
franck@2 134 $cid = $this->drupalCreateComment($edit);
franck@0 135 $comment = _comment_load($cid);
franck@0 136
franck@0 137 $after = og_statistics_load($gid);
franck@0 138 $count_up = ($after['comments_count'] - $before['comments_count']) == 1;
franck@0 139 $this->assertTrue($count_up, 'new comment to one group post, counts up the comment counter');
franck@0 140 $this->assertEqual($comment->timestamp, $after['last_comment_timestamp'], 'new comment to one group post, counts up the comment counter');
franck@2 141 $this->assertEqual($comment->cid, $after['last_comment_cid'], 'New comment to one group post sets the last comment cid.');
franck@2 142 $this->assertEqual($comment->nid, $after['last_comment_nid'], 'New comment to one group post sets the last comment nid.');
franck@2 143 $this->assertEqual($comment->uid, $after['last_comment_uid'], 'New comment to one group post sets the last comment uid.');
franck@2 144
franck@2 145 // add another comment.
franck@2 146
franck@2 147 $edit = array();
franck@2 148 $edit['subject'] = $this->randomName(10);
franck@2 149 $edit['comment'] = $this->randomName(50);
franck@2 150 $edit['nid'] = $nid;
franck@2 151 $edit['format'] = FILTER_FORMAT_DEFAULT;
franck@2 152 $edit['node'] = $node;
franck@2 153 $edit['uid'] = $user->uid;
franck@2 154 $edit['pid'] = NULL;
franck@2 155 $edit['cid'] = NULL;
franck@2 156 $cid = $this->drupalCreateComment($edit);
franck@2 157
franck@2 158 // Remove the node and check whether comment count is updated
franck@2 159 // reload the node, to update the stats.
franck@2 160 $node = node_load($node, NULL, TRUE);
franck@2 161
franck@2 162 node_delete($nid);
franck@2 163 $stat = og_statistics_load($gid);
franck@2 164 $this->assertEqual($stat['comments_count'], 0, 'all comments were deleted');
franck@0 165 }
franck@0 166
franck@0 167 function TestOgStatisticsOg() {
franck@0 168 // Create a group node content type.
franck@0 169 $og_group_type = $this->drupalCreateContentType();
franck@0 170 variable_set('og_content_type_usage_'. $og_group_type->name, 'group');
franck@0 171
franck@0 172 // Create a group post content type.
franck@0 173 $og_post_type = $this->drupalCreateContentType();
franck@0 174 variable_set('og_content_type_usage_'. $og_post_type->name, 'group_post_standard');
franck@0 175
franck@0 176 // Rebuild the menu so the new content types will appear in the menu.
franck@0 177 menu_rebuild();
franck@0 178
franck@0 179 // create a test group
franck@0 180 $gid = $this->addOgGroup($og_group_type->name);
franck@0 181 $before = og_statistics_load($gid);
franck@0 182
franck@0 183 // let one member choine the group
franck@0 184 $account = $this->drupalCreateUser();
franck@0 185 $time = time();
franck@0 186 og_save_subscription($gid, $account->uid, array('created' => $time));
franck@0 187
franck@0 188 $after = og_statistics_load($gid);
franck@0 189
franck@0 190 $count_up = ($after['members_count'] - $before['members_count']) == 1;
franck@0 191
franck@0 192 $this->assertTrue($count_up, 'New subscription to a group adds the counter 1 up');
franck@0 193 $this->assertEqual($time, $after['last_member_timestamp'], 'New subscription to a group adds the counter 1 up');
franck@2 194 $this->assertEqual($account->uid, $after['last_member_uid'], 'New subscription to a group sets the last member uid.');
franck@2 195 }
franck@2 196
franck@2 197 function TestOgStatisticsDelete() {
franck@2 198 // Create a group node content type.
franck@2 199 $og_group_type = $this->drupalCreateContentType();
franck@2 200 variable_set('og_content_type_usage_'. $og_group_type->name, 'group');
franck@2 201
franck@2 202 // Create a group post content type.
franck@2 203 $og_post_type = $this->drupalCreateContentType();
franck@2 204 variable_set('og_content_type_usage_'. $og_post_type->name, 'group_post_standard');
franck@2 205
franck@2 206 // Rebuild the menu so the new content types will appear in the menu.
franck@2 207 menu_rebuild();
franck@2 208
franck@2 209 $gid = $this->addOgGroup($og_group_type->name);
franck@2 210 // create a test group
franck@2 211 $gid = $this->addOgGroup($og_group_type->name);
franck@2 212 $before = og_statistics_load($gid);
franck@2 213
franck@2 214 // Delete the node, the stat-record should be deleted too.
franck@2 215 $node = node_load($gid);
franck@2 216 node_delete($node->nid);
franck@2 217 $after = og_statistics_load($gid);
franck@2 218
franck@2 219 $this->assertTrue(empty($after), 'Og statistics record get deleted');
franck@0 220 }
franck@0 221 }
franck@0 222