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 along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * Standard Alcatel-Lucent disclaimer for contributing to open source
26 * "The test suite ("Contribution") has not been tested and/or
27 * validated for release as or in products, combinations with products or
28 * other commercial use. Any use of the Contribution is entirely made at
29 * the user's own responsibility and the user can not rely on any features,
30 * functionalities or performances Alcatel-Lucent has attributed to the
33 * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
34 * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
35 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
36 * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
37 * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
38 * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
39 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
40 * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
41 * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
45 $config = getenv('CONFIG_PHP') ? getenv('CONFIG_PHP'): dirname(dirname(__FILE__)).'/config.php';
48 require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
50 class FForge_SeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase
52 protected $logged_in = false ;
54 protected function setUp()
56 if (getenv('SELENIUM_RC_DIR') && getenv('SELENIUM_RC_URL')) {
57 $this->captureScreenshotOnFailure = true;
58 $this->screenshotPath = getenv('SELENIUM_RC_DIR');
59 $this->screenshotUrl = getenv('SELENIUM_RC_URL');
61 if (defined('DB_INIT_CMD')) {
62 // Reload a fresh database before running this test suite.
66 $this->setBrowser('*firefox');
67 $this->setBrowserUrl(URL);
68 $this->setHost(SELENIUM_RC_HOST);
71 // protected function waitForPageToLoad($timeout)
73 // parent::waitForPageToLoad($timeout);
74 // $this->test->assertFalse($this->isTextPresent("Notice: Undefined variable:"));
75 // $this->test->assertFalse($this->isTextPresent("Notice: Undefined index:"));
76 // $this->test->assertFalse($this->isTextPresent("Warning: Missing argument"));
79 protected function cron($cmd)
81 system("/usr/bin/php -q /usr/share/gforge/$cmd");
84 protected function init() {
85 $this->createAndGoto('ProjectA');
88 protected function populateStandardTemplate($what='all')
91 $what = array('trackers','tasks','forums','docs');
92 } elseif ($what == 'empty') {
94 } elseif (!is_array($what)) {
95 $what = array($what) ;
97 $this->switchUser (FORGE_ADMIN_USERNAME) ;
99 $this->createProject ('Tmpl');
101 $this->click("link=Site Admin");
102 $this->waitForPageToLoad("30000");
103 $this->click("link=Display Full Project List/Edit Projects");
104 $this->waitForPageToLoad("30000");
105 $this->click("link=Tmpl");
106 $this->waitForPageToLoad("30000");
107 $this->select ("//select[@name='form_template']", "label=Yes") ;
108 $this->click("submit");
109 $this->waitForPageToLoad("30000");
111 $this->open( ROOT . '/projects/tmpl') ;
112 $this->waitForPageToLoad("30000");
114 $this->click("link=Admin");
115 $this->waitForPageToLoad("30000");
116 $this->click("link=Tools");
117 $this->waitForPageToLoad("30000");
118 $this->check("//input[@name='use_forum']") ;
119 $this->check("//input[@name='use_tracker']") ;
120 $this->check("//input[@name='use_mail']") ;
121 $this->check("//input[@name='use_pm']") ;
122 $this->check("//input[@name='use_docman']") ;
123 $this->check("//input[@name='use_news']") ;
124 $this->check("//input[@name='use_frs']") ;
125 $this->click("submit");
126 $this->waitForPageToLoad("30000");
128 if (in_array ('trackers', $what)) {
129 $this->click("link=Trackers Admin");
130 $this->waitForPageToLoad("30000");
131 $this->type("name", "Bugs");
132 $this->type("description", "Tracker for bug reports");
133 $this->click("post_changes");
134 $this->waitForPageToLoad("30000");
135 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
136 $this->click("link=Bugs");
137 $this->waitForPageToLoad("30000");
138 $this->click("link=Manage Custom Fields");
139 $this->waitForPageToLoad("30000");
140 $this->type("name", "URL");
141 $this->type("alias", "url");
142 $this->click("//input[@name='field_type' and @value=4]");
143 $this->click("post_changes");
144 $this->waitForPageToLoad("30000");
146 $this->click("link=Admin");
147 $this->waitForPageToLoad("30000");
148 $this->click("link=Tools");
149 $this->waitForPageToLoad("30000");
150 $this->click("link=Trackers Admin");
151 $this->waitForPageToLoad("30000");
152 $this->type("name", "Support Requests");
153 $this->type("description", "Tracker for support requests");
154 $this->click("post_changes");
155 $this->waitForPageToLoad("30000");
156 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
158 $this->type("name", "Patches");
159 $this->type("description", "Proposed changes to code");
160 $this->click("post_changes");
161 $this->waitForPageToLoad("30000");
162 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
164 $this->type("name", "Feature Requests");
165 $this->type("description", "New features that people want");
166 $this->click("post_changes");
167 $this->waitForPageToLoad("30000");
168 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
171 if (in_array ('tasks', $what)) {
172 $this->click("link=Admin");
173 $this->waitForPageToLoad("30000");
174 $this->click("link=Tools");
175 $this->waitForPageToLoad("30000");
176 $this->click("link=Tasks Admin");
177 $this->waitForPageToLoad("30000");
178 $this->click("link=Add a Subproject");
179 $this->waitForPageToLoad("30000");
180 $this->type("project_name", "To Do");
181 $this->type("description", "Things we have to do");
182 $this->click("submit");
183 $this->waitForPageToLoad("30000");
184 $this->assertTrue($this->isTextPresent("Subproject Inserted"));
186 $this->type("project_name", "Next Release");
187 $this->type("description", "Items for our next release");
188 $this->click("submit");
189 $this->waitForPageToLoad("30000");
190 $this->assertTrue($this->isTextPresent("Subproject Inserted"));
193 if (in_array ('forums', $what)) {
194 $this->click("link=Admin");
195 $this->waitForPageToLoad("30000");
196 $this->click("link=Tools");
197 $this->waitForPageToLoad("30000");
198 $this->click("link=Forums Admin");
199 $this->waitForPageToLoad("30000");
201 $this->click("link=Add forum");
202 $this->waitForPageToLoad("30000");
203 $this->type("forum_name", "Open-Discussion");
204 $this->type("description", "General Discussion");
205 $this->click("submit");
206 $this->waitForPageToLoad("30000");
207 $this->assertTrue($this->isTextPresent("Forum added successfully"));
209 $this->type("forum_name", "Help");
210 $this->type("description", "Get Public Help");
211 $this->click("submit");
212 $this->waitForPageToLoad("30000");
213 $this->assertTrue($this->isTextPresent("Forum added successfully"));
215 $this->type("forum_name", "Developers-Discussion");
216 $this->type("description", "Project Developer Discussion");
217 $this->click("submit");
218 $this->waitForPageToLoad("30000");
219 $this->assertTrue($this->isTextPresent("Forum added successfully"));
221 $this->click("link=Forums");
222 $this->waitForPageToLoad("30000");
223 $this->assertTrue($this->isTextPresent("open-discussion"));
224 $this->assertTrue($this->isTextPresent("Get Public Help"));
225 $this->assertTrue($this->isTextPresent("Project Developer Discussion"));
228 if (in_array ('docs', $what)) {
229 $this->click("link=Docs");
230 $this->waitForPageToLoad("30000");
231 $this->click("link=Add new item");
232 $this->waitForPageToLoad("30000");
233 $this->click("link=Add new item");
234 $this->waitForPageToLoad("30000");
235 $this->click("//input[@name='type' and @value='folder']");
236 $this->type("groupname", "Uncategorized Submissions2");
237 $this->click("//input[@id='submitaddsubgroup']");
238 $this->waitForPageToLoad("30000");
239 $this->assertTrue($this->isTextPresent("Uncategorized Submissions2"));
243 protected function initSvn($project='ProjectA', $user=FORGE_ADMIN_USERNAME)
245 // Remove svnroot directory before creating the project.
246 $repo = '/var/lib/gforge/chroot/scmrepos/svn/'.strtolower($project);
248 system("rm -fr $repo");
251 $this->init($project, $user);
253 // Run manually the cron for creating the svn structure.
254 $this->cron("cronjobs/create_scm_repos.php");
257 protected function login($username)
260 if ($this->isTextPresent('Log Out')) {
263 $this->clickAndWait("link=Log In");
264 $this->triggeredLogin($username);
267 protected function triggeredLogin($username)
269 if ($username == FORGE_ADMIN_USERNAME) {
270 $password = FORGE_ADMIN_PASSWORD;
272 $password = FORGE_OTHER_PASSWORD;
275 $this->type("form_loginname", $username);
276 $this->type("form_pw", $password);
277 $this->clickAndWait("login");
279 $this->logged_in = $username ;
282 protected function logout()
284 // $this->click("link=Log Out");
285 $this->open( ROOT ."/account/logout.php" );
286 $this->waitForPageToLoad("30000");
288 $this->logged_in = false ;
291 protected function switchUser($username)
293 if ($this->logged_in != $username) {
295 $this->login($username);
299 protected function isLoginRequired()
301 return $this->isTextPresent("You've been redirected to this login page") ;
304 protected function isPermissionDenied()
306 return $this->isTextPresent("Permission denied") ;
309 protected function registerProject ($name, $user) {
310 $unix_name = strtolower($name);
312 $saved_user = $this->logged_in ;
313 $this->switchUser ($user) ;
315 $this->clickAndWait("link=My Page");
316 $this->clickAndWait("link=Register Project");
317 $this->type("full_name", $name);
318 $this->type("purpose", "This is a simple description for $name");
319 $this->type("description", "This is the public description for $name.");
320 $this->type("unix_name", $unix_name);
321 $this->click("//input[@name='scm' and @value='scmsvn']");
323 if ($this->isElementPresent("//select[@name='built_from_template']/option[.='Tmpl']")) {
324 $this->select("//select[@name='built_from_template']", "label=Tmpl");
327 $this->click("submit");
328 $this->waitForPageToLoad("30000");
329 $this->assertTrue($this->isTextPresent("Your project has been submitted"));
330 $this->assertTrue($this->isTextPresent("you will receive notification of their decision and further instructions"));
332 $this->switchUser ($saved_user) ;
335 protected function approveProject ($name, $user) {
336 $unix_name = strtolower($name);
338 $saved_user = $this->logged_in ;
339 $this->switchUser ($user) ;
341 $this->open( ROOT . '/admin/approve-pending.php') ;
342 $this->waitForPageToLoad("30000");
343 $this->click("document.forms['approve.$unix_name'].submit");
344 $this->waitForPageToLoad("60000");
346 $this->assertTrue($this->isTextPresent("Approving Project: $unix_name"));
348 $this->switchUser ($saved_user) ;
351 protected function createProject ($name) {
352 $unix_name = strtolower($name);
354 $this->switchUser (FORGE_ADMIN_USERNAME) ;
356 // Create a simple project.
357 if ((!defined('PROJECTA')) || ($unix_name != "projecta")) {
358 $this->registerProject ($name, FORGE_ADMIN_USERNAME) ;
359 $this->approveProject ($name, FORGE_ADMIN_USERNAME) ;
363 protected function createAndGoto($project) {
364 $this->createProject($project);
365 $this->gotoProject($project);
368 protected function createUser ($login)
371 $this->clickAndWait("link=Site Admin");
372 $this->clickAndWait("link=Register a New User");
373 $this->type("unix_name", $login);
374 $this->type("password1", FORGE_OTHER_PASSWORD);
375 $this->type("password2", FORGE_OTHER_PASSWORD);
376 $this->type("firstname", $login);
377 $this->type("lastname", "Lastname");
378 $this->type("email", $login."@debug.log");
379 $this->clickAndWait("submit");
380 $this->clickAndWait("link=Site Admin");
381 $this->clickAndWait("link=Display Full User List/Edit Users");
382 $this->click("//table/tbody/tr/td/a[contains(@href,'useredit.php') and contains(.,'($login)')]/../..//a[contains(@href, 'userlist.php?action=activate&user_id=')]");
383 $this->waitForPageToLoad("30000");
386 protected function activatePlugin($pluginName) {
387 $this->switchUser(FORGE_ADMIN_USERNAME);
388 $this->open( ROOT . '/admin/pluginman.php?update='.$pluginName.'&action=deactivate');
389 $this->waitForPageToLoad("30000");
390 $this->open( ROOT . '/admin/pluginman.php?update='.$pluginName.'&action=activate');
391 $this->waitForPageToLoad("30000");
395 protected function gotoProject($project) {
396 $unix_name = strtolower($project);
398 $this->open( ROOT . '/projects/' . $unix_name) ;
399 $this->waitForPageToLoad("30000");
400 $this->assertTrue($this->isTextPresent("This is the public description for $project."));
406 // c-file-style: "bsd"