3 * Copyright (C) 2007-2008 Alain Peyrat <aljeux at free dot fr>
4 * Copyright (C) 2009 Alain Peyrat, Alcatel-Lucent
6 * This file is part of FusionForge.
8 * FusionForge is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published
10 * by the Free Software Foundation; either version 2 of the License,
11 * or (at your option) any later version.
13 * FusionForge is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with FusionForge; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 * Standard Alcatel-Lucent disclaimer for contributing to open source
27 * "The test suite ("Contribution") has not been tested and/or
28 * validated for release as or in products, combinations with products or
29 * other commercial use. Any use of the Contribution is entirely made at
30 * the user's own responsibility and the user can not rely on any features,
31 * functionalities or performances Alcatel-Lucent has attributed to the
34 * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
35 * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
36 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
37 * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
38 * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
39 * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
40 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
41 * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
42 * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
46 $config = getenv('CONFIG_PHP') ? getenv('CONFIG_PHP'): dirname(dirname(__FILE__)).'/config.php';
49 require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
51 class FForge_SeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase
53 protected $logged_in = false ;
55 protected function setUp()
57 if (getenv('SELENIUM_RC_DIR') && getenv('SELENIUM_RC_URL')) {
58 $this->captureScreenshotOnFailure = true;
59 $this->screenshotPath = getenv('SELENIUM_RC_DIR');
60 $this->screenshotUrl = getenv('SELENIUM_RC_URL');
62 if (defined('DB_INIT_CMD')) {
63 // Reload a fresh database before running this test suite.
67 $this->setBrowser('*firefox');
68 $this->setBrowserUrl(URL);
69 $this->setHost(SELENIUM_RC_HOST);
72 // protected function waitForPageToLoad($timeout)
74 // parent::waitForPageToLoad($timeout);
75 // $this->test->assertFalse($this->isTextPresent("Notice: Undefined variable:"));
76 // $this->test->assertFalse($this->isTextPresent("Notice: Undefined index:"));
77 // $this->test->assertFalse($this->isTextPresent("Warning: Missing argument"));
80 protected function init() {
81 $this->createAndGoto('ProjectA');
84 protected function populateStandardTemplate($what='all')
87 $what = array('trackers','tasks','forums','docs');
88 } elseif ($what == 'empty') {
90 } elseif (!is_array($what)) {
91 $what = array($what) ;
93 $this->switchUser ('admin') ;
95 $this->approveProject ('Template', 'admin');
96 $this->open( ROOT . '/projects/template') ;
97 $this->waitForPageToLoad("30000");
99 $this->click("link=Admin");
100 $this->waitForPageToLoad("30000");
101 $this->click("link=Tools");
102 $this->waitForPageToLoad("30000");
103 $this->click("//input[@name='use_forum']") ;
104 $this->click("//input[@name='use_tracker']") ;
105 $this->click("//input[@name='use_mail']") ;
106 $this->click("//input[@name='use_pm']") ;
107 $this->click("//input[@name='use_docman']") ;
108 $this->click("//input[@name='use_news']") ;
109 $this->click("//input[@name='use_frs']") ;
110 $this->click("submit");
111 $this->waitForPageToLoad("30000");
113 if (in_array ('trackers', $what)) {
114 $this->click("link=Trackers Admin");
115 $this->waitForPageToLoad("30000");
116 $this->type("name", "Bugs");
117 $this->type("description", "Tracker for bug reports");
118 $this->click("post_changes");
119 $this->waitForPageToLoad("30000");
120 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
121 $this->click("link=Bugs");
122 $this->waitForPageToLoad("30000");
123 $this->click("link=Manage Custom Fields");
124 $this->waitForPageToLoad("30000");
125 $this->type("name", "URL");
126 $this->type("alias", "url");
127 $this->click("document.forms[2].field_type[3]");
128 $this->click("post_changes");
129 $this->waitForPageToLoad("30000");
131 $this->click("link=Admin");
132 $this->waitForPageToLoad("30000");
133 $this->click("link=Tools");
134 $this->waitForPageToLoad("30000");
135 $this->click("link=Trackers Admin");
136 $this->waitForPageToLoad("30000");
137 $this->type("name", "Support Requests");
138 $this->type("description", "Tracker for support requests");
139 $this->click("post_changes");
140 $this->waitForPageToLoad("30000");
141 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
143 $this->type("name", "Patches");
144 $this->type("description", "Proposed changes to code");
145 $this->click("post_changes");
146 $this->waitForPageToLoad("30000");
147 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
149 $this->type("name", "Feature Requests");
150 $this->type("description", "New features that people want");
151 $this->click("post_changes");
152 $this->waitForPageToLoad("30000");
153 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
156 if (in_array ('tasks', $what)) {
157 $this->click("link=Admin");
158 $this->waitForPageToLoad("30000");
159 $this->click("link=Tools");
160 $this->waitForPageToLoad("30000");
161 $this->click("link=Tasks Admin");
162 $this->waitForPageToLoad("30000");
163 $this->click("link=Add a Subproject");
164 $this->waitForPageToLoad("30000");
165 $this->type("project_name", "To Do");
166 $this->type("description", "Things we have to do");
167 $this->click("submit");
168 $this->waitForPageToLoad("30000");
169 $this->assertTrue($this->isTextPresent("Subproject Inserted"));
171 $this->type("project_name", "Next Release");
172 $this->type("description", "Items for our next release");
173 $this->click("submit");
174 $this->waitForPageToLoad("30000");
175 $this->assertTrue($this->isTextPresent("Subproject Inserted"));
178 if (in_array ('forums', $what)) {
179 $this->click("link=Admin");
180 $this->waitForPageToLoad("30000");
181 $this->click("link=Tools");
182 $this->waitForPageToLoad("30000");
183 $this->click("link=Forums Admin");
184 $this->waitForPageToLoad("30000");
186 $this->click("link=Add forum");
187 $this->waitForPageToLoad("30000");
188 $this->type("forum_name", "Open-Discussion");
189 $this->type("description", "General Discussion");
190 $this->click("submit");
191 $this->waitForPageToLoad("30000");
192 $this->assertTrue($this->isTextPresent("Forum added successfully"));
194 $this->type("forum_name", "Help");
195 $this->type("description", "Get Public Help");
196 $this->click("submit");
197 $this->waitForPageToLoad("30000");
198 $this->assertTrue($this->isTextPresent("Forum added successfully"));
200 $this->type("forum_name", "Developers-Discussion");
201 $this->type("description", "Project Developer Discussion");
202 $this->click("//input[@name='is_public' and @value='0']");
203 $this->click("submit");
204 $this->waitForPageToLoad("30000");
205 $this->assertTrue($this->isTextPresent("Forum added successfully"));
207 $this->click("link=Forums");
208 $this->waitForPageToLoad("30000");
209 $this->assertTrue($this->isTextPresent("open-discussion"));
210 $this->assertTrue($this->isTextPresent("Get Public Help"));
211 $this->assertTrue($this->isTextPresent("Project Developer Discussion"));
214 if (in_array ('docs', $what)) {
215 $this->click("link=Docs");
216 $this->waitForPageToLoad("30000");
217 $this->click("link=Add new documentation directory");
218 $this->waitForPageToLoad("30000");
219 $this->type("groupname", "Uncategorized Submissions");
220 $this->click("//input[@id='submitaddsubgroup']");
221 $this->waitForPageToLoad("30000");
222 $this->assertTrue($this->isTextPresent("Uncategorized Submissions"));
226 protected function login($username)
229 $this->clickAndWait("link=Log In");
230 $this->triggeredLogin($username);
233 protected function triggeredLogin($username)
235 if ($username == 'admin') {
236 $password = 'myadmin';
238 $password = 'password';
241 $this->type("form_loginname", $username);
242 $this->type("form_pw", $password);
243 $this->clickAndWait("login");
245 $this->logged_in = $username ;
248 protected function logout()
250 // $this->click("link=Log Out");
251 $this->open( ROOT ."/account/logout.php" );
252 $this->waitForPageToLoad("30000");
254 $this->logged_in = false ;
257 protected function switchUser($username)
259 if ($this->logged_in != $username) {
261 $this->login($username);
265 protected function isLoginRequired()
267 return $this->isTextPresent("You've been redirected to this login page") ;
270 protected function isPermissionDenied()
272 return $this->isTextPresent("Permission denied") ;
275 protected function registerProject ($name, $user) {
276 $unix_name = strtolower($name);
278 $saved_user = $this->logged_in ;
279 $this->switchUser ($user) ;
281 $this->clickAndWait("link=My Page");
282 $this->clickAndWait("link=Register Project");
283 $this->type("full_name", $name);
284 $this->type("purpose", "This is a simple description for $name");
285 $this->type("description", "This is the public description for $name.");
286 $this->type("unix_name", $unix_name);
287 $this->click("//input[@name='scm' and @value='scmsvn']");
288 $this->click("submit");
289 $this->waitForPageToLoad("30000");
290 $this->assertTrue($this->isTextPresent("Your project has been submitted"));
291 $this->assertTrue($this->isTextPresent("you will receive notification of their decision and further instructions"));
293 $this->switchUser ($saved_user) ;
296 protected function approveProject ($name, $user) {
297 $unix_name = strtolower($name);
299 $saved_user = $this->logged_in ;
300 $this->switchUser ($user) ;
302 $this->open( ROOT . '/admin/approve-pending.php') ;
303 $this->waitForPageToLoad("30000");
304 $this->click("document.forms['approve.$unix_name'].submit");
305 $this->waitForPageToLoad("60000");
307 $this->assertTrue($this->isTextPresent("Approving Project: $unix_name"));
309 $this->switchUser ($saved_user) ;
312 protected function createProject ($name) {
313 $unix_name = strtolower($name);
315 $this->switchUser ('admin') ;
317 // Create a simple project.
318 if ((!defined('PROJECTA')) || ($unix_name != "projecta")) {
319 $this->registerProject ($name, 'admin') ;
320 $this->approveProject ($name, 'admin') ;
324 protected function createAndGoto($project) {
325 $this->createProject($project);
326 $this->gotoProject($project);
329 protected function createUser ($login)
332 $this->clickAndWait("link=Site Admin");
333 $this->clickAndWait("link=Register a New User");
334 $this->type("unix_name", $login);
335 $this->type("password1", "password");
336 $this->type("password2", "password");
337 $this->type("firstname", $login);
338 $this->type("lastname", "Lastname");
339 $this->type("email", $login."@debug.log");
340 $this->clickAndWait("submit");
341 $this->clickAndWait("link=Site Admin");
342 $this->clickAndWait("link=Display Full User List/Edit Users");
343 $this->click("//table/tbody/tr/td/a[contains(@href,'useredit.php') and contains(.,'($login)')]/../..//a[contains(@href, 'userlist.php?action=activate&user_id=')]");
344 $this->waitForPageToLoad("30000");
347 protected function activatePlugin($pluginName) {
348 $this->switchUser('admin');
349 $this->open( ROOT . '/admin/pluginman.php?update='.$pluginName.'&action=deactivate');
350 $this->waitForPageToLoad("30000");
351 $this->open( ROOT . '/admin/pluginman.php?update='.$pluginName.'&action=activate');
352 $this->waitForPageToLoad("30000");
356 protected function gotoProject($project) {
357 $unix_name = strtolower($project);
359 $this->open( ROOT . '/projects/' . $unix_name) ;
360 $this->waitForPageToLoad("30000");
361 $this->assertTrue($this->isTextPresent("This is the public description for $project."));
367 // c-file-style: "bsd"