comparison og_statistics.test @ 0:9ce879ecbce6

OG Stats beta 3
author Franck Deroche <franck@defr.org>
date Tue, 24 Nov 2009 14:25:13 +0100
parents
children 48f07e7acaca
comparison
equal deleted inserted replaced
-1:000000000000 0:9ce879ecbce6
1 <?php
2 // $Id: og_statistics.test,v 1.2.2.2 2009/06/05 22:38:12 dereine Exp $
3
4 /**
5 * Test file for og_statitics.
6 *
7 * @TODO Use multiple groups for testing.
8 * @TODO Abstract part of the tests.
9 */
10
11 require_once drupal_get_path('module', 'og') .'/tests/og_testcase.php';
12
13 class OgStatisticsTestCase extends OgTestCase {
14 function getInfo() {
15 return array(
16 'name' => t('Organic groups statistics'),
17 'description' => t('tests statistics of og_statistics module'),
18 'group' => t('Organic groups'),
19 );
20 }
21
22 function setUp() {
23 parent::setUp('node', 'user', 'comment', 'views', 'og', 'og_views', 'og_statistics', 'og_access');
24
25 // Create a user with admin permissions.
26 $web_admin = $this->drupalCreateUser(array('administer nodes', 'administer content types', 'access administration pages', 'administer site configuration', 'administer organic groups'));
27 $this->drupalLogin($web_admin);
28 }
29
30 function TestOgStatisticsWritePureRecord() {
31 // Create a group node content type.
32 $og_group_type = $this->drupalCreateContentType();
33 variable_set('og_content_type_usage_'. $og_group_type->name, 'group');
34
35 // Create a group post content type.
36 $og_post_type = $this->drupalCreateContentType();
37 variable_set('og_content_type_usage_'. $og_post_type->name, 'group_post_standard');
38
39 // Rebuild the menu so the new content types will appear in the menu.
40 menu_rebuild();
41
42 // Create a group node.
43 $gid = $this->addOgGroup($og_group_type->name);
44
45 // get the record of the group
46 $stat = og_statistics_load($gid);
47 unset($stat['nid']);
48 $members =
49
50 $empty = FALSE;
51 $this->assertFalse($empty, print_r($stat, TRUE));
52 foreach ($stat as $key => $item) {
53 $empty = $empty || $item == TRUE;
54 }
55 $this->assertFalse($empty, t('All stats should have 0 as item'));
56 }
57
58 // Tests nodeapi statistics.
59 function TestOgStatisticsNodeapi() {
60 // Create a group node content type.
61 $og_group_type = $this->drupalCreateContentType();
62 variable_set('og_content_type_usage_'. $og_group_type->name, 'group');
63
64 // Create a group post content type.
65 $og_post_type = $this->drupalCreateContentType();
66 variable_set('og_content_type_usage_'. $og_post_type->name, 'group_post_standard');
67
68 // Rebuild the menu so the new content types will appear in the menu.
69 menu_rebuild();
70
71 // create a test group
72 $gid = $this->addOgGroup($og_group_type->name);
73 $before = og_statistics_load($gid);
74
75 // add a test post
76 $nids[] = $nid = $this->addOgPost($og_post_type->name, array($gid));
77 $node = node_load($nid);
78 // Rebuild the menu so the new content types will appear in the menu.
79 menu_rebuild();
80 $after = og_statistics_load($gid);
81 $count_one_up = ($after['posts_count'] - $before['posts_count']) == 1;
82
83 $this->assertTrue($count_one_up, 'A node post in a group, counts the counter 1 up');
84 $this->assertEqual($node->created, $after['last_node_timestamp'], 'A node post in a group, sets the last node timestamp');
85
86 // remove the post
87 node_delete($nid);
88 $before = $after;
89 $after = og_statistics_load($gid);
90 $count_down = ($after['posts_count'] - $before['posts_count']) == -1;
91
92 $this->assertTrue($count_down, 'A node poast in a group was deleted, counts the counter 1 down');
93 }
94
95 // Tests comments hooks statistic
96 function TestOgStatisticsComment() {
97 // Create a group node content type.
98 $og_group_type = $this->drupalCreateContentType();
99 variable_set('og_content_type_usage_'. $og_group_type->name, 'group');
100
101 // Create a group post content type.
102 $og_post_type = $this->drupalCreateContentType();
103 variable_set('og_content_type_usage_'. $og_post_type->name, 'group_post_standard');
104
105 // Rebuild the menu so the new content types will appear in the menu.
106 menu_rebuild();
107
108 // create a test group
109 $gid = $this->addOgGroup($og_group_type->name);
110 $before = og_statistics_load($gid);
111
112 // add a test post
113 $nids[] = $nid = $this->addOgPost($og_post_type->name, array($gid));
114
115 // adds some comments
116 $edit = array();
117 $edit['subject'] = $this->randomName(10);
118 $edit['comment'] = $this->randomName(50);
119 $edit['nid'] = $nid;
120 $cid = comment_save($edit);
121 $comment = _comment_load($cid);
122
123 $after = og_statistics_load($gid);
124 $count_up = ($after['comments_count'] - $before['comments_count']) == 1;
125 $this->assertTrue($count_up, 'new comment to one group post, counts up the comment counter');
126 $this->assertEqual($comment->timestamp, $after['last_comment_timestamp'], 'new comment to one group post, counts up the comment counter');
127 }
128
129 function TestOgStatisticsOg() {
130 // Create a group node content type.
131 $og_group_type = $this->drupalCreateContentType();
132 variable_set('og_content_type_usage_'. $og_group_type->name, 'group');
133
134 // Create a group post content type.
135 $og_post_type = $this->drupalCreateContentType();
136 variable_set('og_content_type_usage_'. $og_post_type->name, 'group_post_standard');
137
138 // Rebuild the menu so the new content types will appear in the menu.
139 menu_rebuild();
140
141 // create a test group
142 $gid = $this->addOgGroup($og_group_type->name);
143 $before = og_statistics_load($gid);
144
145 // let one member choine the group
146 $account = $this->drupalCreateUser();
147 $time = time();
148 og_save_subscription($gid, $account->uid, array('created' => $time));
149
150 $after = og_statistics_load($gid);
151
152 $count_up = ($after['members_count'] - $before['members_count']) == 1;
153
154 $this->assertTrue($count_up, 'New subscription to a group adds the counter 1 up');
155 $this->assertEqual($time, $after['last_member_timestamp'], 'New subscription to a group adds the counter 1 up');
156 }
157 }
158