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);
72 * Method that is called after Selenium actions.
74 * @param string $action
76 protected function defaultAssertions($action)
78 if ($action == 'waitForPageToLoad') {
79 $this->assertElementPresent("//h1");
80 // $this->assertFalse($this->isElementPresent("//div[@id='ffErrors']"));
81 // $this->assertFalse($this->isTextPresent("PhpWiki Warning:"));
85 protected function clickAndWait($link)
88 $this->waitForPageToLoad();
91 protected function waitForTextPresent($text)
93 for ($second = 0; ; $second++) {
94 if ($second >= 30) $this->fail("timeout");
96 if ($this->isTextPresent($text)) break;
97 } catch (Exception $e) {}
102 protected function runCommand($cmd)
107 protected function db($sql)
109 system("echo \"$sql\" | psql -q -Upostgres ".DB_NAME);
112 protected function cron($cmd)
114 $this->runCommand(RUN_JOB_PATH."forge_run_job $cmd");
117 protected function cron_for_plugin($cmd, $plugin)
119 $this->runCommand(RUN_JOB_PATH."forge_run_plugin_job $plugin $cmd");
122 protected function init() {
123 $this->createAndGoto('ProjectA');
126 protected function populateStandardTemplate($what='all')
128 if ($what == 'all') {
129 $what = array('trackers','tasks','forums','docs');
130 } elseif ($what == 'empty') {
132 } elseif (!is_array($what)) {
133 $what = array($what) ;
135 $this->switchUser (FORGE_ADMIN_USERNAME) ;
137 $this->createProject ('Tmpl');
139 $this->click("link=Site Admin");
140 $this->waitForPageToLoad("30000");
141 $this->click("link=Display Full Project List/Edit Projects");
142 $this->waitForPageToLoad("30000");
143 $this->click("link=Tmpl");
144 $this->waitForPageToLoad("30000");
145 $this->select ("//select[@name='form_template']", "label=Yes") ;
146 $this->click("submit");
147 $this->waitForPageToLoad("30000");
149 $this->open( ROOT . '/projects/tmpl') ;
150 $this->waitForPageToLoad("30000");
152 $this->click("link=Admin");
153 $this->waitForPageToLoad("30000");
154 $this->click("link=Tools");
155 $this->waitForPageToLoad("30000");
156 $this->check("//input[@name='use_forum']") ;
157 $this->check("//input[@name='use_tracker']") ;
158 $this->check("//input[@name='use_mail']") ;
159 $this->check("//input[@name='use_pm']") ;
160 $this->check("//input[@name='use_docman']") ;
161 $this->check("//input[@name='use_news']") ;
162 $this->check("//input[@name='use_frs']") ;
163 $this->click("submit");
164 $this->waitForPageToLoad("30000");
166 if (in_array ('trackers', $what)) {
167 $this->click("link=Trackers Admin");
168 $this->waitForPageToLoad("30000");
169 $this->type("name", "Bugs");
170 $this->type("//input[@name='description']", "Tracker for bug reports");
171 $this->click("post_changes");
172 $this->waitForPageToLoad("30000");
173 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
174 $this->click("link=Bugs");
175 $this->waitForPageToLoad("30000");
176 $this->click("link=Manage Custom Fields");
177 $this->waitForPageToLoad("30000");
178 $this->type("name", "URL");
179 $this->type("alias", "url");
180 $this->click("//input[@name='field_type' and @value=4]");
181 $this->click("post_changes");
182 $this->waitForPageToLoad("30000");
184 $this->click("link=Admin");
185 $this->waitForPageToLoad("30000");
186 $this->click("link=Tools");
187 $this->waitForPageToLoad("30000");
188 $this->click("link=Trackers Admin");
189 $this->waitForPageToLoad("30000");
190 $this->type("name", "Support Requests");
191 $this->type("//input[@name='description']", "Tracker for support requests");
192 $this->click("post_changes");
193 $this->waitForPageToLoad("30000");
194 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
196 $this->type("name", "Patches");
197 $this->type("//input[@name='description']", "Proposed changes to code");
198 $this->click("post_changes");
199 $this->waitForPageToLoad("30000");
200 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
202 $this->type("name", "Feature Requests");
203 $this->type("//input[@name='description']", "New features that people want");
204 $this->click("post_changes");
205 $this->waitForPageToLoad("30000");
206 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
209 if (in_array ('tasks', $what)) {
210 $this->click("link=Admin");
211 $this->waitForPageToLoad("30000");
212 $this->click("link=Tools");
213 $this->waitForPageToLoad("30000");
214 $this->click("link=Tasks Admin");
215 $this->waitForPageToLoad("30000");
216 $this->click("link=Add a Subproject");
217 $this->waitForPageToLoad("30000");
218 $this->type("project_name", "To Do");
219 $this->type("//input[@name='description']", "Things we have to do");
220 $this->click("submit");
221 $this->waitForPageToLoad("30000");
222 $this->assertTrue($this->isTextPresent("Subproject Inserted"));
224 $this->type("project_name", "Next Release");
225 $this->type("//input[@name='description']", "Items for our next release");
226 $this->click("submit");
227 $this->waitForPageToLoad("30000");
228 $this->assertTrue($this->isTextPresent("Subproject Inserted"));
231 if (in_array ('forums', $what)) {
232 $this->click("link=Admin");
233 $this->waitForPageToLoad("30000");
234 $this->click("link=Tools");
235 $this->waitForPageToLoad("30000");
236 $this->click("link=Forums Admin");
237 $this->waitForPageToLoad("30000");
239 $this->click("link=Add forum");
240 $this->waitForPageToLoad("30000");
241 $this->type("forum_name", "Open-Discussion");
242 $this->type("//input[@name='description']", "General Discussion");
243 $this->click("submit");
244 $this->waitForPageToLoad("30000");
245 $this->assertTrue($this->isTextPresent("Forum added successfully"));
247 $this->type("forum_name", "Help");
248 $this->type("//input[@name='description']", "Get Public Help");
249 $this->click("submit");
250 $this->waitForPageToLoad("30000");
251 $this->assertTrue($this->isTextPresent("Forum added successfully"));
253 $this->type("forum_name", "Developers-Discussion");
254 $this->type("//input[@name='description']", "Project Developer Discussion");
255 $this->click("submit");
256 $this->waitForPageToLoad("30000");
257 $this->assertTrue($this->isTextPresent("Forum added successfully"));
259 $this->click("link=Forums");
260 $this->waitForPageToLoad("30000");
261 $this->assertTrue($this->isTextPresent("open-discussion"));
262 $this->assertTrue($this->isTextPresent("Get Public Help"));
263 $this->assertTrue($this->isTextPresent("Project Developer Discussion"));
266 if (in_array ('docs', $what)) {
267 $this->click("link=Docs");
268 $this->waitForPageToLoad("30000");
269 $this->click("link=Add new item");
270 $this->waitForPageToLoad("30000");
271 $this->click("link=Add new item");
272 $this->waitForPageToLoad("30000");
273 $this->click("//input[@name='type' and @value='folder']");
274 $this->type("groupname", "Uncategorized Submissions2");
275 $this->click("//input[@id='submitaddsubgroup']");
276 $this->waitForPageToLoad("30000");
277 $this->assertTrue($this->isTextPresent("Uncategorized Submissions2"));
281 protected function initSvn($project='ProjectA', $user=FORGE_ADMIN_USERNAME)
283 // Remove svnroot directory before creating the project.
284 $repo = '/var/lib/gforge/chroot/scmrepos/svn/'.strtolower($project);
286 system("rm -fr $repo");
289 $this->init($project, $user);
291 // Run manually the cron for creating the svn structure.
292 $this->cron("create_scm_repos.php");
295 protected function login($username)
298 if ($this->isTextPresent('Log Out')) {
301 $this->clickAndWait("link=Log In");
302 $this->triggeredLogin($username);
305 protected function triggeredLogin($username)
307 if ($username == FORGE_ADMIN_USERNAME) {
308 $password = FORGE_ADMIN_PASSWORD;
310 $password = FORGE_OTHER_PASSWORD;
313 $this->type("form_loginname", $username);
314 $this->type("form_pw", $password);
315 $this->clickAndWait("login");
317 $this->logged_in = $username ;
320 protected function logout()
322 // $this->click("link=Log Out");
323 $this->open( ROOT ."/account/logout.php" );
324 $this->waitForPageToLoad("30000");
326 $this->logged_in = false ;
329 protected function switchUser($username)
331 if ($this->logged_in != $username) {
333 $this->login($username);
337 protected function isLoginRequired()
339 return $this->isTextPresent("You've been redirected to this login page") ;
342 protected function isPermissionDenied()
344 return $this->isTextPresent("Permission denied") ;
347 protected function registerProject ($name, $user, $scm='scmsvn') {
348 $unix_name = strtolower($name);
350 $saved_user = $this->logged_in ;
351 $this->switchUser ($user) ;
353 $this->clickAndWait("link=My Page");
354 $this->clickAndWait("link=Register Project");
355 $this->type("full_name", $name);
356 $this->type("purpose", "This is a simple description for $name");
357 $this->type("//textarea[@name='description']", "This is the public description for $name.");
358 $this->type("unix_name", $unix_name);
359 $this->click("//input[@name='scm' and @value='$scm']");
361 if ($this->isElementPresent("//select[@name='built_from_template']/option[.='Tmpl']")) {
362 $this->select("//select[@name='built_from_template']", "label=Tmpl");
365 $this->clickAndWait("submit");
366 $this->assertTextPresent("Your project has been submitted");
367 $this->assertTextPresent("you will receive notification of their decision and further instructions");
369 $this->switchUser ($saved_user) ;
372 protected function approveProject ($name, $user) {
373 $unix_name = strtolower($name);
375 $saved_user = $this->logged_in ;
376 $this->switchUser ($user) ;
378 $this->open( ROOT . '/admin/approve-pending.php') ;
379 $this->waitForPageToLoad("30000");
380 $this->click("document.forms['approve.$unix_name'].submit");
381 $this->waitForPageToLoad("60000");
383 $this->assertTrue($this->isTextPresent("Approving Project: $unix_name"));
385 $this->switchUser ($saved_user) ;
388 protected function createProject ($name, $scm='scmsvn') {
389 $unix_name = strtolower($name);
391 $this->switchUser (FORGE_ADMIN_USERNAME) ;
393 // Create a simple project.
394 if ((!defined('PROJECTA')) || ($unix_name != "projecta")) {
395 $this->registerProject ($name, FORGE_ADMIN_USERNAME, $scm) ;
396 $this->approveProject ($name, FORGE_ADMIN_USERNAME) ;
400 protected function createAndGoto($project) {
401 $this->createProject($project);
402 $this->gotoProject($project);
405 protected function createUser ($login)
408 $this->clickAndWait("link=Site Admin");
409 $this->clickAndWait("link=Register a New User");
410 $this->type("unix_name", $login);
411 $this->type("password1", FORGE_OTHER_PASSWORD);
412 $this->type("password2", FORGE_OTHER_PASSWORD);
413 $this->type("firstname", $login);
414 $this->type("lastname", "Lastname");
415 $this->type("email", $login."@debug.log");
416 $this->clickAndWait("submit");
417 $this->clickAndWait("link=Site Admin");
418 $this->clickAndWait("link=Display Full User List/Edit Users");
419 $this->clickAndWait("//table/tbody/tr/td/a[contains(@href,'useredit.php') and contains(.,'($login)')]/../..//a[contains(@href, 'userlist.php?action=activate&user_id=')]");
422 protected function activatePlugin($pluginName) {
423 $this->switchUser(FORGE_ADMIN_USERNAME);
424 $this->open( ROOT . '/admin/pluginman.php?update='.$pluginName.'&action=deactivate');
425 $this->waitForPageToLoad("30000");
426 $this->open( ROOT . '/admin/pluginman.php?update='.$pluginName.'&action=activate');
427 $this->waitForPageToLoad("30000");
431 protected function gotoProject($project) {
432 $unix_name = strtolower($project);
434 $this->open( ROOT . '/projects/' . $unix_name) ;
435 $this->waitForPageToLoad("30000");
436 $this->assertTrue($this->isTextPresent("This is the public description for $project."));
442 // c-file-style: "bsd"