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("/usr/bin/php -q ".HOME_FORGE."/$cmd");
117 protected function init() {
118 $this->createAndGoto('ProjectA');
121 protected function populateStandardTemplate($what='all')
123 if ($what == 'all') {
124 $what = array('trackers','tasks','forums','docs');
125 } elseif ($what == 'empty') {
127 } elseif (!is_array($what)) {
128 $what = array($what) ;
130 $this->switchUser (FORGE_ADMIN_USERNAME) ;
132 $this->createProject ('Tmpl');
134 $this->click("link=Site Admin");
135 $this->waitForPageToLoad("30000");
136 $this->click("link=Display Full Project List/Edit Projects");
137 $this->waitForPageToLoad("30000");
138 $this->click("link=Tmpl");
139 $this->waitForPageToLoad("30000");
140 $this->select ("//select[@name='form_template']", "label=Yes") ;
141 $this->click("submit");
142 $this->waitForPageToLoad("30000");
144 $this->open( ROOT . '/projects/tmpl') ;
145 $this->waitForPageToLoad("30000");
147 $this->click("link=Admin");
148 $this->waitForPageToLoad("30000");
149 $this->click("link=Tools");
150 $this->waitForPageToLoad("30000");
151 $this->check("//input[@name='use_forum']") ;
152 $this->check("//input[@name='use_tracker']") ;
153 $this->check("//input[@name='use_mail']") ;
154 $this->check("//input[@name='use_pm']") ;
155 $this->check("//input[@name='use_docman']") ;
156 $this->check("//input[@name='use_news']") ;
157 $this->check("//input[@name='use_frs']") ;
158 $this->click("submit");
159 $this->waitForPageToLoad("30000");
161 if (in_array ('trackers', $what)) {
162 $this->click("link=Trackers Admin");
163 $this->waitForPageToLoad("30000");
164 $this->type("name", "Bugs");
165 $this->type("//input[@name='description']", "Tracker for bug reports");
166 $this->click("post_changes");
167 $this->waitForPageToLoad("30000");
168 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
169 $this->click("link=Bugs");
170 $this->waitForPageToLoad("30000");
171 $this->click("link=Manage Custom Fields");
172 $this->waitForPageToLoad("30000");
173 $this->type("name", "URL");
174 $this->type("alias", "url");
175 $this->click("//input[@name='field_type' and @value=4]");
176 $this->click("post_changes");
177 $this->waitForPageToLoad("30000");
179 $this->click("link=Admin");
180 $this->waitForPageToLoad("30000");
181 $this->click("link=Tools");
182 $this->waitForPageToLoad("30000");
183 $this->click("link=Trackers Admin");
184 $this->waitForPageToLoad("30000");
185 $this->type("name", "Support Requests");
186 $this->type("//input[@name='description']", "Tracker for support requests");
187 $this->click("post_changes");
188 $this->waitForPageToLoad("30000");
189 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
191 $this->type("name", "Patches");
192 $this->type("//input[@name='description']", "Proposed changes to code");
193 $this->click("post_changes");
194 $this->waitForPageToLoad("30000");
195 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
197 $this->type("name", "Feature Requests");
198 $this->type("//input[@name='description']", "New features that people want");
199 $this->click("post_changes");
200 $this->waitForPageToLoad("30000");
201 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
204 if (in_array ('tasks', $what)) {
205 $this->click("link=Admin");
206 $this->waitForPageToLoad("30000");
207 $this->click("link=Tools");
208 $this->waitForPageToLoad("30000");
209 $this->click("link=Tasks Admin");
210 $this->waitForPageToLoad("30000");
211 $this->click("link=Add a Subproject");
212 $this->waitForPageToLoad("30000");
213 $this->type("project_name", "To Do");
214 $this->type("//input[@name='description']", "Things we have to do");
215 $this->click("submit");
216 $this->waitForPageToLoad("30000");
217 $this->assertTrue($this->isTextPresent("Subproject Inserted"));
219 $this->type("project_name", "Next Release");
220 $this->type("//input[@name='description']", "Items for our next release");
221 $this->click("submit");
222 $this->waitForPageToLoad("30000");
223 $this->assertTrue($this->isTextPresent("Subproject Inserted"));
226 if (in_array ('forums', $what)) {
227 $this->click("link=Admin");
228 $this->waitForPageToLoad("30000");
229 $this->click("link=Tools");
230 $this->waitForPageToLoad("30000");
231 $this->click("link=Forums Admin");
232 $this->waitForPageToLoad("30000");
234 $this->click("link=Add forum");
235 $this->waitForPageToLoad("30000");
236 $this->type("forum_name", "Open-Discussion");
237 $this->type("//input[@name='description']", "General Discussion");
238 $this->click("submit");
239 $this->waitForPageToLoad("30000");
240 $this->assertTrue($this->isTextPresent("Forum added successfully"));
242 $this->type("forum_name", "Help");
243 $this->type("//input[@name='description']", "Get Public Help");
244 $this->click("submit");
245 $this->waitForPageToLoad("30000");
246 $this->assertTrue($this->isTextPresent("Forum added successfully"));
248 $this->type("forum_name", "Developers-Discussion");
249 $this->type("//input[@name='description']", "Project Developer Discussion");
250 $this->click("submit");
251 $this->waitForPageToLoad("30000");
252 $this->assertTrue($this->isTextPresent("Forum added successfully"));
254 $this->click("link=Forums");
255 $this->waitForPageToLoad("30000");
256 $this->assertTrue($this->isTextPresent("open-discussion"));
257 $this->assertTrue($this->isTextPresent("Get Public Help"));
258 $this->assertTrue($this->isTextPresent("Project Developer Discussion"));
261 if (in_array ('docs', $what)) {
262 $this->click("link=Docs");
263 $this->waitForPageToLoad("30000");
264 $this->click("link=Add new item");
265 $this->waitForPageToLoad("30000");
266 $this->click("link=Add new item");
267 $this->waitForPageToLoad("30000");
268 $this->click("//input[@name='type' and @value='folder']");
269 $this->type("groupname", "Uncategorized Submissions2");
270 $this->click("//input[@id='submitaddsubgroup']");
271 $this->waitForPageToLoad("30000");
272 $this->assertTrue($this->isTextPresent("Uncategorized Submissions2"));
276 protected function initSvn($project='ProjectA', $user=FORGE_ADMIN_USERNAME)
278 // Remove svnroot directory before creating the project.
279 $repo = '/var/lib/gforge/chroot/scmrepos/svn/'.strtolower($project);
281 system("rm -fr $repo");
284 $this->init($project, $user);
286 // Run manually the cron for creating the svn structure.
287 $this->cron("cronjobs/create_scm_repos.php");
290 protected function login($username)
293 if ($this->isTextPresent('Log Out')) {
296 $this->clickAndWait("link=Log In");
297 $this->triggeredLogin($username);
300 protected function triggeredLogin($username)
302 if ($username == FORGE_ADMIN_USERNAME) {
303 $password = FORGE_ADMIN_PASSWORD;
305 $password = FORGE_OTHER_PASSWORD;
308 $this->type("form_loginname", $username);
309 $this->type("form_pw", $password);
310 $this->clickAndWait("login");
312 $this->logged_in = $username ;
315 protected function logout()
317 // $this->click("link=Log Out");
318 $this->open( ROOT ."/account/logout.php" );
319 $this->waitForPageToLoad("30000");
321 $this->logged_in = false ;
324 protected function switchUser($username)
326 if ($this->logged_in != $username) {
328 $this->login($username);
332 protected function isLoginRequired()
334 return $this->isTextPresent("You've been redirected to this login page") ;
337 protected function isPermissionDenied()
339 return $this->isTextPresent("Permission denied") ;
342 protected function registerProject ($name, $user, $scm='scmsvn') {
343 $unix_name = strtolower($name);
345 $saved_user = $this->logged_in ;
346 $this->switchUser ($user) ;
348 $this->clickAndWait("link=My Page");
349 $this->clickAndWait("link=Register Project");
350 $this->type("full_name", $name);
351 $this->type("purpose", "This is a simple description for $name");
352 $this->type("//textarea[@name='description']", "This is the public description for $name.");
353 $this->type("unix_name", $unix_name);
354 $this->click("//input[@name='scm' and @value='$scm']");
356 if ($this->isElementPresent("//select[@name='built_from_template']/option[.='Tmpl']")) {
357 $this->select("//select[@name='built_from_template']", "label=Tmpl");
360 $this->clickAndWait("submit");
361 $this->assertTextPresent("Your project has been submitted");
362 $this->assertTextPresent("you will receive notification of their decision and further instructions");
364 $this->switchUser ($saved_user) ;
367 protected function approveProject ($name, $user) {
368 $unix_name = strtolower($name);
370 $saved_user = $this->logged_in ;
371 $this->switchUser ($user) ;
373 $this->open( ROOT . '/admin/approve-pending.php') ;
374 $this->waitForPageToLoad("30000");
375 $this->click("document.forms['approve.$unix_name'].submit");
376 $this->waitForPageToLoad("60000");
378 $this->assertTrue($this->isTextPresent("Approving Project: $unix_name"));
380 $this->switchUser ($saved_user) ;
383 protected function createProject ($name, $scm='scmsvn') {
384 $unix_name = strtolower($name);
386 $this->switchUser (FORGE_ADMIN_USERNAME) ;
388 // Create a simple project.
389 if ((!defined('PROJECTA')) || ($unix_name != "projecta")) {
390 $this->registerProject ($name, FORGE_ADMIN_USERNAME, $scm) ;
391 $this->approveProject ($name, FORGE_ADMIN_USERNAME) ;
395 protected function createAndGoto($project) {
396 $this->createProject($project);
397 $this->gotoProject($project);
400 protected function createUser ($login)
403 $this->clickAndWait("link=Site Admin");
404 $this->clickAndWait("link=Register a New User");
405 $this->type("unix_name", $login);
406 $this->type("password1", FORGE_OTHER_PASSWORD);
407 $this->type("password2", FORGE_OTHER_PASSWORD);
408 $this->type("firstname", $login);
409 $this->type("lastname", "Lastname");
410 $this->type("email", $login."@debug.log");
411 $this->clickAndWait("submit");
412 $this->clickAndWait("link=Site Admin");
413 $this->clickAndWait("link=Display Full User List/Edit Users");
414 $this->clickAndWait("//table/tbody/tr/td/a[contains(@href,'useredit.php') and contains(.,'($login)')]/../..//a[contains(@href, 'userlist.php?action=activate&user_id=')]");
417 protected function activatePlugin($pluginName) {
418 $this->switchUser(FORGE_ADMIN_USERNAME);
419 $this->open( ROOT . '/admin/pluginman.php?update='.$pluginName.'&action=deactivate');
420 $this->waitForPageToLoad("30000");
421 $this->open( ROOT . '/admin/pluginman.php?update='.$pluginName.'&action=activate');
422 $this->waitForPageToLoad("30000");
426 protected function gotoProject($project) {
427 $unix_name = strtolower($project);
429 $this->open( ROOT . '/projects/' . $unix_name) ;
430 $this->waitForPageToLoad("30000");
431 $this->assertTrue($this->isTextPresent("This is the public description for $project."));
437 // c-file-style: "bsd"