3 * Copyright (C) 2007-2008 Alain Peyrat <aljeux at free dot fr>
4 * Copyright (C) 2009 Alain Peyrat, Alcatel-Lucent
5 * Copyright 2013, Franck Villaume - TrivialDev
7 * This file is part of FusionForge.
9 * FusionForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
14 * FusionForge is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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);
73 * Method that is called after Selenium actions.
75 * @param string $action
77 protected function defaultAssertions($action)
79 if ($action == 'waitForPageToLoad') {
80 $this->assertElementPresent("//h1");
81 // $this->assertFalse($this->isElementPresent("//div[@id='ffErrors']"));
82 // $this->assertFalse($this->isTextPresent("PhpWiki Warning:"));
86 protected function clickAndWait($link)
89 $this->waitForPageToLoad();
92 protected function waitForTextPresent($text)
94 for ($second = 0; ; $second++) {
95 if ($second >= 30) $this->fail("timeout");
97 if ($this->isTextPresent($text)) break;
98 } catch (Exception $e) {}
103 protected function runCommand($cmd)
108 protected function db($sql)
110 system("echo \"$sql\" | psql -q -Upostgres ".DB_NAME);
113 protected function cron($cmd)
115 $this->runCommand(RUN_JOB_PATH."forge_run_job $cmd");
118 protected function cron_for_plugin($cmd, $plugin)
120 $this->runCommand(RUN_JOB_PATH."forge_run_plugin_job $plugin $cmd");
123 protected function init() {
124 $this->createAndGoto('ProjectA');
127 protected function populateStandardTemplate($what='all')
129 if ($what == 'all') {
130 $what = array('trackers','tasks','forums');
131 } elseif ($what == 'empty') {
133 } elseif (!is_array($what)) {
134 $what = array($what) ;
136 $this->switchUser (FORGE_ADMIN_USERNAME) ;
138 $this->createProject ('Tmpl');
140 $this->click("link=Site Admin");
141 $this->waitForPageToLoad("30000");
142 $this->click("link=Display Full Project List/Edit Projects");
143 $this->waitForPageToLoad("30000");
144 $this->click("link=Tmpl");
145 $this->waitForPageToLoad("30000");
146 $this->select ("//select[@name='form_template']", "label=Yes") ;
147 $this->click("submit");
148 $this->waitForPageToLoad("30000");
150 $this->open( ROOT . '/projects/tmpl') ;
151 $this->waitForPageToLoad("30000");
153 $this->click("link=Admin");
154 $this->waitForPageToLoad("30000");
155 $this->click("link=Tools");
156 $this->waitForPageToLoad("30000");
157 $this->check("//input[@name='use_forum']") ;
158 $this->check("//input[@name='use_tracker']") ;
159 $this->check("//input[@name='use_mail']") ;
160 $this->check("//input[@name='use_pm']") ;
161 $this->check("//input[@name='use_docman']") ;
162 $this->check("//input[@name='use_news']") ;
163 $this->check("//input[@name='use_frs']") ;
164 $this->click("submit");
165 $this->waitForPageToLoad("30000");
167 if (in_array ('trackers', $what)) {
168 $this->click("link=Trackers Admin");
169 $this->waitForPageToLoad("30000");
170 $this->type("name", "Bugs");
171 $this->type("//input[@name='description']", "Tracker for bug reports");
172 $this->click("post_changes");
173 $this->waitForPageToLoad("30000");
174 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
175 $this->click("link=Bugs");
176 $this->waitForPageToLoad("30000");
177 $this->click("link=Manage Custom Fields");
178 $this->waitForPageToLoad("30000");
179 $this->type("name", "URL");
180 $this->type("alias", "url");
181 $this->click("//input[@name='field_type' and @value=4]");
182 $this->click("post_changes");
183 $this->waitForPageToLoad("30000");
185 $this->click("link=Admin");
186 $this->waitForPageToLoad("30000");
187 $this->click("link=Tools");
188 $this->waitForPageToLoad("30000");
189 $this->click("link=Trackers Admin");
190 $this->waitForPageToLoad("30000");
191 $this->type("name", "Support Requests");
192 $this->type("//input[@name='description']", "Tracker for support requests");
193 $this->click("post_changes");
194 $this->waitForPageToLoad("30000");
195 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
197 $this->type("name", "Patches");
198 $this->type("//input[@name='description']", "Proposed changes to code");
199 $this->click("post_changes");
200 $this->waitForPageToLoad("30000");
201 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
203 $this->type("name", "Feature Requests");
204 $this->type("//input[@name='description']", "New features that people want");
205 $this->click("post_changes");
206 $this->waitForPageToLoad("30000");
207 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
210 if (in_array ('tasks', $what)) {
211 $this->click("link=Admin");
212 $this->waitForPageToLoad("30000");
213 $this->click("link=Tools");
214 $this->waitForPageToLoad("30000");
215 $this->click("link=Tasks Administration");
216 $this->waitForPageToLoad("30000");
217 $this->click("link=Add a Subproject");
218 $this->waitForPageToLoad("30000");
219 $this->type("project_name", "To Do");
220 $this->type("//input[@name='description']", "Things we have to do");
221 $this->click("submit");
222 $this->waitForPageToLoad("30000");
223 $this->assertTrue($this->isTextPresent("Subproject Inserted"));
225 $this->type("project_name", "Next Release");
226 $this->type("//input[@name='description']", "Items for our next release");
227 $this->click("submit");
228 $this->waitForPageToLoad("30000");
229 $this->assertTrue($this->isTextPresent("Subproject Inserted"));
232 if (in_array ('forums', $what)) {
233 $this->click("link=Admin");
234 $this->waitForPageToLoad("30000");
235 $this->click("link=Tools");
236 $this->waitForPageToLoad("30000");
237 $this->click("link=Forums Admin");
238 $this->waitForPageToLoad("30000");
240 $this->click("link=Add forum");
241 $this->waitForPageToLoad("30000");
242 $this->type("forum_name", "Open-Discussion");
243 $this->type("//input[@name='description']", "General Discussion");
244 $this->click("submit");
245 $this->waitForPageToLoad("30000");
246 $this->assertTrue($this->isTextPresent("Forum added successfully"));
248 $this->type("forum_name", "Help");
249 $this->type("//input[@name='description']", "Get Public Help");
250 $this->click("submit");
251 $this->waitForPageToLoad("30000");
252 $this->assertTrue($this->isTextPresent("Forum added successfully"));
254 $this->type("forum_name", "Developers-Discussion");
255 $this->type("//input[@name='description']", "Project Developer Discussion");
256 $this->click("submit");
257 $this->waitForPageToLoad("30000");
258 $this->assertTrue($this->isTextPresent("Forum added successfully"));
260 $this->click("link=Forums");
261 $this->waitForPageToLoad("30000");
262 $this->assertTrue($this->isTextPresent("open-discussion"));
263 $this->assertTrue($this->isTextPresent("Get Public Help"));
264 $this->assertTrue($this->isTextPresent("Project Developer Discussion"));
268 protected function initSvn($project='ProjectA', $user=FORGE_ADMIN_USERNAME)
270 // Remove svnroot directory before creating the project.
271 $repo = '/var/lib/gforge/chroot/scmrepos/svn/'.strtolower($project);
273 system("rm -fr $repo");
276 $this->init($project, $user);
278 // Run manually the cron for creating the svn structure.
279 $this->cron("create_scm_repos.php");
282 protected function login($username)
285 if ($this->isTextPresent('Log Out')) {
288 $this->clickAndWait("link=Log In");
289 $this->triggeredLogin($username);
292 protected function triggeredLogin($username)
294 if ($username == FORGE_ADMIN_USERNAME) {
295 $password = FORGE_ADMIN_PASSWORD;
297 $password = FORGE_OTHER_PASSWORD;
300 $this->type("form_loginname", $username);
301 $this->type("form_pw", $password);
302 $this->clickAndWait("login");
304 $this->logged_in = $username ;
307 protected function logout()
309 // $this->click("link=Log Out");
310 $this->open( ROOT ."/account/logout.php" );
311 $this->waitForPageToLoad("30000");
313 $this->logged_in = false ;
316 protected function switchUser($username)
318 if ($this->logged_in != $username) {
320 $this->login($username);
324 protected function isLoginRequired()
326 return $this->isTextPresent("You've been redirected to this login page") ;
329 protected function isPermissionDenied()
331 return $this->isTextPresent("Permission denied") ;
334 protected function registerProject ($name, $user, $scm='scmsvn') {
335 $unix_name = strtolower($name);
337 $saved_user = $this->logged_in ;
338 $this->switchUser ($user) ;
340 $this->clickAndWait("link=My Page");
341 $this->clickAndWait("link=Register Project");
342 $this->type("full_name", $name);
343 $this->type("purpose", "This is a simple description for $name");
344 $this->type("//textarea[@name='description']", "This is the public description for $name.");
345 $this->type("unix_name", $unix_name);
346 $this->click("//input[@name='scm' and @value='$scm']");
348 if ($this->isElementPresent("//select[@name='built_from_template']/option[.='Tmpl']")) {
349 $this->select("//select[@name='built_from_template']", "label=Tmpl");
352 $this->clickAndWait("submit");
353 $this->assertTextPresent("Your project has been automatically approved");
355 $this->switchUser ($saved_user) ;
358 protected function approveProject ($name, $user) {
359 $unix_name = strtolower($name);
361 $saved_user = $this->logged_in ;
362 $this->switchUser ($user) ;
364 $this->open( ROOT . '/admin/approve-pending.php') ;
365 $this->waitForPageToLoad("30000");
366 $this->click("document.forms['approve.$unix_name'].submit");
367 $this->waitForPageToLoad("60000");
369 $this->assertTrue($this->isTextPresent("Approving Project: $unix_name"));
371 $this->switchUser ($saved_user) ;
374 protected function createProject ($name, $scm='scmsvn') {
375 $unix_name = strtolower($name);
377 $this->switchUser (FORGE_ADMIN_USERNAME) ;
379 // Create a simple project.
380 if ((!defined('PROJECTA')) || ($unix_name != "projecta")) {
381 $this->registerProject ($name, FORGE_ADMIN_USERNAME, $scm) ;
385 protected function createAndGoto($project) {
386 $this->createProject($project);
387 $this->gotoProject($project);
390 protected function createUser ($login)
393 $this->clickAndWait("link=Site Admin");
394 $this->clickAndWait("link=Register a New User");
395 $this->type("unix_name", $login);
396 $this->type("password1", FORGE_OTHER_PASSWORD);
397 $this->type("password2", FORGE_OTHER_PASSWORD);
398 $this->type("firstname", $login);
399 $this->type("lastname", "Lastname");
400 $this->type("email", $login."@debug.log");
401 $this->clickAndWait("submit");
402 $this->clickAndWait("link=Site Admin");
403 $this->clickAndWait("link=Display Full User List/Edit Users");
404 $this->clickAndWait("//table/tbody/tr/td/a[contains(@href,'useredit.php') and contains(.,'($login)')]/../..//a[contains(@href, 'userlist.php?action=activate&user_id=')]");
407 protected function activatePlugin($pluginName) {
408 $this->switchUser(FORGE_ADMIN_USERNAME);
409 $this->open( ROOT . '/admin/pluginman.php?update='.$pluginName.'&action=deactivate');
410 $this->waitForPageToLoad("30000");
411 $this->open( ROOT . '/admin/pluginman.php?update='.$pluginName.'&action=activate');
412 $this->waitForPageToLoad("30000");
416 protected function gotoProject($project) {
417 $unix_name = strtolower($project);
419 $this->open( ROOT . '/projects/' . $unix_name) ;
420 $this->waitForPageToLoad("30000");
421 $this->assertTrue($this->isTextPresent("This is the public description for $project."));
427 // c-file-style: "bsd"