-
Notifications
You must be signed in to change notification settings - Fork 676
/
TestOfThreadJSController.php
224 lines (201 loc) · 11.2 KB
/
TestOfThreadJSController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
/**
*
* ThinkUp/webapp/plugins/embedthread/tests/TestOfThreadJSController.php
*
* Copyright (c) 2009-2011 Gina Trapani
*
* LICENSE:
*
* This file is part of ThinkUp (http://thinkupapp.com).
*
* ThinkUp is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any
* later version.
*
* ThinkUp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with ThinkUp. If not, see
* <http://www.gnu.org/licenses/>.
*
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2009-2011 Gina Trapani
*/
require_once 'tests/init.tests.php';
require_once THINKUP_ROOT_PATH.'webapp/_lib/extlib/simpletest/autorun.php';
require_once THINKUP_ROOT_PATH.'webapp/config.inc.php';
class TestOfThreadJSController extends ThinkUpUnitTestCase {
public function setUp() {
parent::setUp();
$webapp = Webapp::getInstance();
$webapp->registerPlugin('embedthread', 'EmbedThreadPlugin');
}
//test plugin not enabled
public function testPluginDisabled() {
$fixture = FixtureBuilder::build('options', array('namespace'=>'application_options',
'option_name'=>'is_embed_disabled', 'option_value'=>'true'));
$controller = new ThreadJSController(true);
$results = $controller->go();
$v_mgr = $controller->getViewManager();
$this->assertPattern('/ThinkUp embedding is not enabled./', $results);
$this->debug($results);
}
//test missing parameters
public function testMissingParameters() {
$b = $this->activateEmbedThread();
$plugin_dao = new PluginMySQLDAO();
$plugin_id = $plugin_dao->getPluginId('embedthread');
$this->debug(($plugin_dao->isPluginActive($plugin_id))?"EmbedThread is active":"Not active");
$controller = new ThreadJSController(true);
$results = $controller->go();
$v_mgr = $controller->getViewManager();
$config = Config::getInstance();
$this->assertPattern('/No ThinkUp thread specified./', $results);
$this->debug($results);
}
//test nonexistent post ID
public function testNonexistentPost() {
$b = $this->activateEmbedThread();
$_GET['p'] = 1001;
$_GET['n'] = 'YouFace';
$plugin_dao = new PluginMySQLDAO();
$plugin_id = $plugin_dao->getPluginId('embedthread');
$this->debug(($plugin_dao->isPluginActive($plugin_id))?"EmbedThread is active":"Not active");
$controller = new ThreadJSController(true);
$results = $controller->go();
$v_mgr = $controller->getViewManager();
$config = Config::getInstance();
$this->assertPattern('/Post does not exist/', $results);
$this->debug($results);
}
//test protected post
public function testProtectedPost() {
$b = $this->activateEmbedThread();
$post_builder = FixtureBuilder::build('posts', array('post_id'=>'1001', 'author_user_id'=>'10',
'author_username'=>'ev', 'post_text'=>'This is a test post', 'retweet_count_cache'=>'5',
'network'=>'twitter', 'is_protected'=>1));
$user_builder = FixtureBuilder::build('users', array('user_id'=>'10', 'username'=>'ev', 'is_protected'=>'1',
'network'=>'twitter'));
$_GET['p'] = 1001;
$_GET['n'] = 'twitter';
$plugin_dao = new PluginMySQLDAO();
$plugin_id = $plugin_dao->getPluginId('embedthread');
$this->debug(($plugin_dao->isPluginActive($plugin_id))?"EmbedThread is active":"Not active");
$controller = new ThreadJSController(true);
$results = $controller->go();
$v_mgr = $controller->getViewManager();
$config = Config::getInstance();
$this->assertPattern('/Private post/', $results);
$this->debug($results);
}
//test valid public post with all public replies
public function testPublicPostWithAllPublicReplies() {
$b = $this->activateEmbedThread();
$post_builder = FixtureBuilder::build('posts', array('post_id'=>'1001', 'author_user_id'=>'10',
'author_username'=>'ev', 'post_text'=>'This is a test post', 'retweet_count_cache'=>'5',
'network'=>'twitter', 'is_protected'=>0));
$user_builder = FixtureBuilder::build('users', array('user_id'=>'10', 'username'=>'ev', 'is_protected'=>'0',
'network'=>'twitter'));
$public_reply_author_builder1 = FixtureBuilder::build('users', array('user_id'=>'11', 'username'=>'jack',
'is_protected'=>'0', 'network'=>'twitter'));
$reply_builder1 = FixtureBuilder::build('posts', array('post_id'=>'1002', 'author_user_id'=>'11',
'author_username'=>'jack', 'post_text'=>'This is a public reply to 1001', 'network'=>'twitter',
'in_reply_to_post_id'=>1001, 'is_protected'=>'0'));
$public_reply_author_builder2 = FixtureBuilder::build('users', array('user_id'=>'12', 'username'=>'jill',
'is_protected'=>'0', 'network'=>'twitter'));
$reply_builder2 = FixtureBuilder::build('posts', array('post_id'=>'1003', 'author_user_id'=>'12',
'author_username'=>'jill', 'post_text'=>'This is another public reply to 1001', 'network'=>'twitter',
'in_reply_to_post_id'=>1001, 'is_protected'=>'0'));
$public_reply_author_builder3 = FixtureBuilder::build('users', array('user_id'=>'13', 'username'=>'mary',
'is_protected'=>'0', 'network'=>'twitter'));
$reply_builder3 = FixtureBuilder::build('posts', array('post_id'=>'1004', 'author_user_id'=>'13',
'author_username'=>'mary', 'post_text'=>'This is yet another public reply to 1001', 'network'=>'twitter',
'in_reply_to_post_id'=>1001, 'is_protected'=>0));
$_GET['p'] = 1001;
$_GET['n'] = 'twitter';
$plugin_dao = new PluginMySQLDAO();
$plugin_id = $plugin_dao->getPluginId('embedthread');
$this->debug(($plugin_dao->isPluginActive($plugin_id))?"EmbedThread is active":"Not active");
$controller = new ThreadJSController(true);
$results = $controller->go();
$v_mgr = $controller->getViewManager();
$config = Config::getInstance();
$this->assertPattern('/This is a test post/', $results);
$this->assertPattern('/This is a public reply to 1001/', $results);
$this->assertPattern('/This is another public reply to 1001/', $results);
$this->assertPattern('/This is yet another public reply to 1001/', $results);
$this->debug($results);
}
//test valid public post with all protected replies
public function testPublicPostWithProtectedReplies() {
$b = $this->activateEmbedThread();
$post_builder = FixtureBuilder::build('posts', array('post_id'=>'1001', 'author_user_id'=>'10',
'author_username'=>'ev', 'post_text'=>'This is a test post', 'retweet_count_cache'=>'5',
'network'=>'twitter', 'is_protected'=>0));
$user_builder = FixtureBuilder::build('users', array('user_id'=>'10', 'username'=>'ev', 'is_protected'=>'0',
'network'=>'twitter'));
$private_reply_author_builder1 = FixtureBuilder::build('users', array('user_id'=>'13', 'username'=>'mary',
'is_protected'=>'1', 'network'=>'twitter'));
$reply_builder3 = FixtureBuilder::build('posts', array('post_id'=>'1004', 'author_user_id'=>'13',
'author_username'=>'mary', 'post_text'=>'This is a private reply to 1001', 'network'=>'twitter',
'in_reply_to_post_id'=>1001, 'is_protected'=>'1'));
$_GET['p'] = 1001;
$_GET['n'] = 'twitter';
$plugin_dao = new PluginMySQLDAO();
$plugin_id = $plugin_dao->getPluginId('embedthread');
$this->debug(($plugin_dao->isPluginActive($plugin_id))?"EmbedThread is active":"Not active");
$controller = new ThreadJSController(true);
$results = $controller->go();
$v_mgr = $controller->getViewManager();
$config = Config::getInstance();
$this->assertPattern('/This is a test post/', $results);
$this->assertNoPattern('/This is a private reply to 1001/', $results);
$this->debug($results);
}
//test valid public post with some protected replies
public function testPublicPostWithMixedAccessReplies() {
$b = $this->activateEmbedThread();
$post_builder = FixtureBuilder::build('posts', array('post_id'=>'1001', 'author_user_id'=>'10',
'author_username'=>'ev', 'post_text'=>'This is a test post', 'retweet_count_cache'=>'5',
'network'=>'twitter', 'is_protected'=>0));
$user_builder = FixtureBuilder::build('users', array('user_id'=>'10', 'username'=>'ev', 'is_protected'=>'0',
'network'=>'twitter'));
$public_reply_author_builder1 = FixtureBuilder::build('users', array('user_id'=>'11', 'username'=>'jack',
'is_protected'=>'0', 'network'=>'twitter'));
$reply_builder1 = FixtureBuilder::build('posts', array('post_id'=>'1002', 'author_user_id'=>'11',
'author_username'=>'jack', 'post_text'=>'This is a public reply to 1001', 'network'=>'twitter',
'in_reply_to_post_id'=>1001, 'is_protected'=>'0'));
$public_reply_author_builder2 = FixtureBuilder::build('users', array('user_id'=>'12', 'username'=>'jill',
'is_protected'=>'0', 'network'=>'twitter'));
$reply_builder2 = FixtureBuilder::build('posts', array('post_id'=>'1003', 'author_user_id'=>'12',
'author_username'=>'jill', 'post_text'=>'This is another public reply to 1001', 'network'=>'twitter',
'in_reply_to_post_id'=>1001, 'is_protected'=>'0'));
$private_reply_author_builder1 = FixtureBuilder::build('users', array('user_id'=>'13', 'username'=>'mary',
'is_protected'=>'1', 'network'=>'twitter'));
$reply_builder3 = FixtureBuilder::build('posts', array('post_id'=>'1004', 'author_user_id'=>'13',
'author_username'=>'mary', 'post_text'=>'This is a private reply to 1001', 'network'=>'twitter',
'in_reply_to_post_id'=>1001, 'is_protected'=>'1'));
$_GET['p'] = 1001;
$_GET['n'] = 'twitter';
$plugin_dao = new PluginMySQLDAO();
$plugin_id = $plugin_dao->getPluginId('embedthread');
$this->debug(($plugin_dao->isPluginActive($plugin_id))?"EmbedThread is active":"Not active");
$controller = new ThreadJSController(true);
$results = $controller->go();
$v_mgr = $controller->getViewManager();
$config = Config::getInstance();
$this->assertPattern('/This is a test post/', $results);
$this->assertPattern('/This is a public reply to 1001/', $results);
$this->assertPattern('/This is another public reply to 1001/', $results);
$this->assertNoPattern('/This is a private reply to 1001/', $results);
$this->debug($results);
}
private function activateEmbedThread(){
$builder = FixtureBuilder::build('plugins', array('name'=>'Embed Thread', 'folder_name'=>'embedthread',
'is_active'=>1));
return $builder;
}
}