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','docs');
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"));
267 if (in_array ('docs', $what)) {
268 $this->click("link=Docs");
269 $this->waitForPageToLoad("30000");
270 $this->click("link=Add new item");
271 $this->waitForPageToLoad("30000");
272 $this->click("link=Add new item");
273 $this->waitForPageToLoad("30000");
274 $this->click("//input[@name='type' and @value='folder']");
275 $this->type("groupname", "Uncategorized Submissions2");
276 $this->click("//input[@id='submitaddsubgroup']");
277 $this->waitForPageToLoad("30000");
278 $this->assertTrue($this->isTextPresent("Uncategorized Submissions2"));
282 protected function initSvn($project='ProjectA', $user=FORGE_ADMIN_USERNAME)
284 // Remove svnroot directory before creating the project.
285 $repo = '/var/lib/gforge/chroot/scmrepos/svn/'.strtolower($project);
287 system("rm -fr $repo");
290 $this->init($project, $user);
292 // Run manually the cron for creating the svn structure.
293 $this->cron("create_scm_repos.php");
296 protected function login($username)
299 if ($this->isTextPresent('Log Out')) {
302 $this->clickAndWait("link=Log In");
303 $this->triggeredLogin($username);
306 protected function triggeredLogin($username)
308 if ($username == FORGE_ADMIN_USERNAME) {
309 $password = FORGE_ADMIN_PASSWORD;
311 $password = FORGE_OTHER_PASSWORD;
314 $this->type("form_loginname", $username);
315 $this->type("form_pw", $password);
316 $this->clickAndWait("login");
318 $this->logged_in = $username ;
321 protected function logout()
323 // $this->click("link=Log Out");
324 $this->open( ROOT ."/account/logout.php" );
325 $this->waitForPageToLoad("30000");
327 $this->logged_in = false ;
330 protected function switchUser($username)
332 if ($this->logged_in != $username) {
334 $this->login($username);
338 protected function isLoginRequired()
340 return $this->isTextPresent("You've been redirected to this login page") ;
343 protected function isPermissionDenied()
345 return $this->isTextPresent("Permission denied") ;
348 protected function registerProject ($name, $user, $scm='scmsvn') {
349 $unix_name = strtolower($name);
351 $saved_user = $this->logged_in ;
352 $this->switchUser ($user) ;
354 $this->clickAndWait("link=My Page");
355 $this->clickAndWait("link=Register Project");
356 $this->type("full_name", $name);
357 $this->type("purpose", "This is a simple description for $name");
358 $this->type("//textarea[@name='description']", "This is the public description for $name.");
359 $this->type("unix_name", $unix_name);
360 $this->click("//input[@name='scm' and @value='$scm']");
362 if ($this->isElementPresent("//select[@name='built_from_template']/option[.='Tmpl']")) {
363 $this->select("//select[@name='built_from_template']", "label=Tmpl");
366 $this->clickAndWait("submit");
367 $this->assertTextPresent("Your project has been automatically approved");
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) ;
399 protected function createAndGoto($project) {
400 $this->createProject($project);
401 $this->gotoProject($project);
404 protected function createUser ($login)
407 $this->clickAndWait("link=Site Admin");
408 $this->clickAndWait("link=Register a New User");
409 $this->type("unix_name", $login);
410 $this->type("password1", FORGE_OTHER_PASSWORD);
411 $this->type("password2", FORGE_OTHER_PASSWORD);
412 $this->type("firstname", $login);
413 $this->type("lastname", "Lastname");
414 $this->type("email", $login."@debug.log");
415 $this->clickAndWait("submit");
416 $this->clickAndWait("link=Site Admin");
417 $this->clickAndWait("link=Display Full User List/Edit Users");
418 $this->clickAndWait("//table/tbody/tr/td/a[contains(@href,'useredit.php') and contains(.,'($login)')]/../..//a[contains(@href, 'userlist.php?action=activate&user_id=')]");
421 protected function activatePlugin($pluginName) {
422 $this->switchUser(FORGE_ADMIN_USERNAME);
423 $this->open( ROOT . '/admin/pluginman.php?update='.$pluginName.'&action=deactivate');
424 $this->waitForPageToLoad("30000");
425 $this->open( ROOT . '/admin/pluginman.php?update='.$pluginName.'&action=activate');
426 $this->waitForPageToLoad("30000");
430 protected function gotoProject($project) {
431 $unix_name = strtolower($project);
433 $this->open( ROOT . '/projects/' . $unix_name) ;
434 $this->waitForPageToLoad("30000");
435 $this->assertTrue($this->isTextPresent("This is the public description for $project."));
441 // c-file-style: "bsd"