franck@0
|
1 <?php |
franck@0
|
2 // $Id: og_statistics.test,v 1.2.2.2 2009/06/05 22:38:12 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@0
|
14 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@0
|
23 parent::setUp('node', 'user', 'comment', 'views', 'og', 'og_views', 'og_statistics', 'og_access'); |
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 $this->assertFalse($empty, print_r($stat, TRUE)); |
franck@0
|
52 foreach ($stat as $key => $item) { |
franck@0
|
53 $empty = $empty || $item == TRUE; |
franck@0
|
54 } |
franck@0
|
55 $this->assertFalse($empty, t('All stats should have 0 as item')); |
franck@0
|
56 } |
franck@0
|
57 |
franck@0
|
58 // Tests nodeapi statistics. |
franck@0
|
59 function TestOgStatisticsNodeapi() { |
franck@0
|
60 // Create a group node content type. |
franck@0
|
61 $og_group_type = $this->drupalCreateContentType(); |
franck@0
|
62 variable_set('og_content_type_usage_'. $og_group_type->name, 'group'); |
franck@0
|
63 |
franck@0
|
64 // Create a group post content type. |
franck@0
|
65 $og_post_type = $this->drupalCreateContentType(); |
franck@0
|
66 variable_set('og_content_type_usage_'. $og_post_type->name, 'group_post_standard'); |
franck@0
|
67 |
franck@0
|
68 // Rebuild the menu so the new content types will appear in the menu. |
franck@0
|
69 menu_rebuild(); |
franck@0
|
70 |
franck@0
|
71 // create a test group |
franck@0
|
72 $gid = $this->addOgGroup($og_group_type->name); |
franck@0
|
73 $before = og_statistics_load($gid); |
franck@0
|
74 |
franck@0
|
75 // add a test post |
franck@0
|
76 $nids[] = $nid = $this->addOgPost($og_post_type->name, array($gid)); |
franck@0
|
77 $node = node_load($nid); |
franck@0
|
78 // Rebuild the menu so the new content types will appear in the menu. |
franck@0
|
79 menu_rebuild(); |
franck@0
|
80 $after = og_statistics_load($gid); |
franck@0
|
81 $count_one_up = ($after['posts_count'] - $before['posts_count']) == 1; |
franck@0
|
82 |
franck@0
|
83 $this->assertTrue($count_one_up, 'A node post in a group, counts the counter 1 up'); |
franck@0
|
84 $this->assertEqual($node->created, $after['last_node_timestamp'], 'A node post in a group, sets the last node timestamp'); |
franck@0
|
85 |
franck@0
|
86 // remove the post |
franck@0
|
87 node_delete($nid); |
franck@0
|
88 $before = $after; |
franck@0
|
89 $after = og_statistics_load($gid); |
franck@0
|
90 $count_down = ($after['posts_count'] - $before['posts_count']) == -1; |
franck@0
|
91 |
franck@0
|
92 $this->assertTrue($count_down, 'A node poast in a group was deleted, counts the counter 1 down'); |
franck@0
|
93 } |
franck@0
|
94 |
franck@0
|
95 // Tests comments hooks statistic |
franck@0
|
96 function TestOgStatisticsComment() { |
franck@0
|
97 // Create a group node content type. |
franck@0
|
98 $og_group_type = $this->drupalCreateContentType(); |
franck@0
|
99 variable_set('og_content_type_usage_'. $og_group_type->name, 'group'); |
franck@0
|
100 |
franck@0
|
101 // Create a group post content type. |
franck@0
|
102 $og_post_type = $this->drupalCreateContentType(); |
franck@0
|
103 variable_set('og_content_type_usage_'. $og_post_type->name, 'group_post_standard'); |
franck@0
|
104 |
franck@0
|
105 // Rebuild the menu so the new content types will appear in the menu. |
franck@0
|
106 menu_rebuild(); |
franck@0
|
107 |
franck@0
|
108 // create a test group |
franck@0
|
109 $gid = $this->addOgGroup($og_group_type->name); |
franck@0
|
110 $before = og_statistics_load($gid); |
franck@0
|
111 |
franck@0
|
112 // add a test post |
franck@0
|
113 $nids[] = $nid = $this->addOgPost($og_post_type->name, array($gid)); |
franck@0
|
114 |
franck@0
|
115 // adds some comments |
franck@0
|
116 $edit = array(); |
franck@0
|
117 $edit['subject'] = $this->randomName(10); |
franck@0
|
118 $edit['comment'] = $this->randomName(50); |
franck@0
|
119 $edit['nid'] = $nid; |
franck@0
|
120 $cid = comment_save($edit); |
franck@0
|
121 $comment = _comment_load($cid); |
franck@0
|
122 |
franck@0
|
123 $after = og_statistics_load($gid); |
franck@0
|
124 $count_up = ($after['comments_count'] - $before['comments_count']) == 1; |
franck@0
|
125 $this->assertTrue($count_up, 'new comment to one group post, counts up the comment counter'); |
franck@0
|
126 $this->assertEqual($comment->timestamp, $after['last_comment_timestamp'], 'new comment to one group post, counts up the comment counter'); |
franck@0
|
127 } |
franck@0
|
128 |
franck@0
|
129 function TestOgStatisticsOg() { |
franck@0
|
130 // Create a group node content type. |
franck@0
|
131 $og_group_type = $this->drupalCreateContentType(); |
franck@0
|
132 variable_set('og_content_type_usage_'. $og_group_type->name, 'group'); |
franck@0
|
133 |
franck@0
|
134 // Create a group post content type. |
franck@0
|
135 $og_post_type = $this->drupalCreateContentType(); |
franck@0
|
136 variable_set('og_content_type_usage_'. $og_post_type->name, 'group_post_standard'); |
franck@0
|
137 |
franck@0
|
138 // Rebuild the menu so the new content types will appear in the menu. |
franck@0
|
139 menu_rebuild(); |
franck@0
|
140 |
franck@0
|
141 // create a test group |
franck@0
|
142 $gid = $this->addOgGroup($og_group_type->name); |
franck@0
|
143 $before = og_statistics_load($gid); |
franck@0
|
144 |
franck@0
|
145 // let one member choine the group |
franck@0
|
146 $account = $this->drupalCreateUser(); |
franck@0
|
147 $time = time(); |
franck@0
|
148 og_save_subscription($gid, $account->uid, array('created' => $time)); |
franck@0
|
149 |
franck@0
|
150 $after = og_statistics_load($gid); |
franck@0
|
151 |
franck@0
|
152 $count_up = ($after['members_count'] - $before['members_count']) == 1; |
franck@0
|
153 |
franck@0
|
154 $this->assertTrue($count_up, 'New subscription to a group adds the counter 1 up'); |
franck@0
|
155 $this->assertEqual($time, $after['last_member_timestamp'], 'New subscription to a group adds the counter 1 up'); |
franck@0
|
156 } |
franck@0
|
157 } |
franck@0
|
158 |