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 ('admin') ;
99 $this->approveProject ('Template', 'admin');
100 $this->open( ROOT . '/projects/template') ;
101 $this->waitForPageToLoad("30000");
103 $this->click("link=Admin");
104 $this->waitForPageToLoad("30000");
105 $this->click("link=Tools");
106 $this->waitForPageToLoad("30000");
107 $this->check("//input[@name='use_forum']") ;
108 $this->check("//input[@name='use_tracker']") ;
109 $this->check("//input[@name='use_mail']") ;
110 $this->check("//input[@name='use_pm']") ;
111 $this->check("//input[@name='use_docman']") ;
112 $this->check("//input[@name='use_news']") ;
113 $this->check("//input[@name='use_frs']") ;
114 $this->click("submit");
115 $this->waitForPageToLoad("30000");
117 if (in_array ('trackers', $what)) {
118 $this->click("link=Trackers Admin");
119 $this->waitForPageToLoad("30000");
120 $this->type("name", "Bugs");
121 $this->type("description", "Tracker for bug reports");
122 $this->click("post_changes");
123 $this->waitForPageToLoad("30000");
124 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
125 $this->click("link=Bugs");
126 $this->waitForPageToLoad("30000");
127 $this->click("link=Manage Custom Fields");
128 $this->waitForPageToLoad("30000");
129 $this->type("name", "URL");
130 $this->type("alias", "url");
131 $this->click("document.forms[2].field_type[3]");
132 $this->click("post_changes");
133 $this->waitForPageToLoad("30000");
135 $this->click("link=Admin");
136 $this->waitForPageToLoad("30000");
137 $this->click("link=Tools");
138 $this->waitForPageToLoad("30000");
139 $this->click("link=Trackers Admin");
140 $this->waitForPageToLoad("30000");
141 $this->type("name", "Support Requests");
142 $this->type("description", "Tracker for support requests");
143 $this->click("post_changes");
144 $this->waitForPageToLoad("30000");
145 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
147 $this->type("name", "Patches");
148 $this->type("description", "Proposed changes to code");
149 $this->click("post_changes");
150 $this->waitForPageToLoad("30000");
151 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
153 $this->type("name", "Feature Requests");
154 $this->type("description", "New features that people want");
155 $this->click("post_changes");
156 $this->waitForPageToLoad("30000");
157 $this->assertTrue($this->isTextPresent("Tracker created successfully"));
160 if (in_array ('tasks', $what)) {
161 $this->click("link=Admin");
162 $this->waitForPageToLoad("30000");
163 $this->click("link=Tools");
164 $this->waitForPageToLoad("30000");
165 $this->click("link=Tasks Admin");
166 $this->waitForPageToLoad("30000");
167 $this->click("link=Add a Subproject");
168 $this->waitForPageToLoad("30000");
169 $this->type("project_name", "To Do");
170 $this->type("description", "Things we have to do");
171 $this->click("submit");
172 $this->waitForPageToLoad("30000");
173 $this->assertTrue($this->isTextPresent("Subproject Inserted"));
175 $this->type("project_name", "Next Release");
176 $this->type("description", "Items for our next release");
177 $this->click("submit");
178 $this->waitForPageToLoad("30000");
179 $this->assertTrue($this->isTextPresent("Subproject Inserted"));
182 if (in_array ('forums', $what)) {
183 $this->click("link=Admin");
184 $this->waitForPageToLoad("30000");
185 $this->click("link=Tools");
186 $this->waitForPageToLoad("30000");
187 $this->click("link=Forums Admin");
188 $this->waitForPageToLoad("30000");
190 $this->click("link=Add forum");
191 $this->waitForPageToLoad("30000");
192 $this->type("forum_name", "Open-Discussion");
193 $this->type("description", "General Discussion");
194 $this->click("submit");
195 $this->waitForPageToLoad("30000");
196 $this->assertTrue($this->isTextPresent("Forum added successfully"));
198 $this->type("forum_name", "Help");
199 $this->type("description", "Get Public Help");
200 $this->click("submit");
201 $this->waitForPageToLoad("30000");
202 $this->assertTrue($this->isTextPresent("Forum added successfully"));
204 $this->type("forum_name", "Developers-Discussion");
205 $this->type("description", "Project Developer Discussion");
206 $this->click("//input[@name='is_public' and @value='0']");
207 $this->click("submit");
208 $this->waitForPageToLoad("30000");
209 $this->assertTrue($this->isTextPresent("Forum added successfully"));
211 $this->click("link=Forums");
212 $this->waitForPageToLoad("30000");
213 $this->assertTrue($this->isTextPresent("open-discussion"));
214 $this->assertTrue($this->isTextPresent("Get Public Help"));
215 $this->assertTrue($this->isTextPresent("Project Developer Discussion"));
218 if (in_array ('docs', $what)) {
219 $this->click("link=Docs");
220 $this->waitForPageToLoad("30000");
221 $this->click("link=Add new documentation directory");
222 $this->waitForPageToLoad("30000");
223 $this->type("groupname", "Uncategorized Submissions");
224 $this->click("//input[@id='submitaddsubgroup']");
225 $this->waitForPageToLoad("30000");
226 $this->assertTrue($this->isTextPresent("Uncategorized Submissions"));
230 protected function initSvn($project='ProjectA', $user='admin')
232 // Remove svnroot directory before creating the project.
233 $repo = '/var/lib/gforge/chroot/scmrepos/svn/'.strtolower($project);
235 system("rm -fr $repo");
238 $this->init($project, $user);
240 // Run manually the cron for creating the svn structure.
241 $this->cron("cronjobs/create_scm_repos.php");
244 protected function login($username)
247 if ($this->isTextPresent('Log Out')) {
250 $this->clickAndWait("link=Log In");
251 $this->triggeredLogin($username);
254 protected function triggeredLogin($username)
256 if ($username == 'admin') {
257 $password = 'myadmin';
259 $password = 'password';
262 $this->type("form_loginname", $username);
263 $this->type("form_pw", $password);
264 $this->clickAndWait("login");
266 $this->logged_in = $username ;
269 protected function logout()
271 // $this->click("link=Log Out");
272 $this->open( ROOT ."/account/logout.php" );
273 $this->waitForPageToLoad("30000");
275 $this->logged_in = false ;
278 protected function switchUser($username)
280 if ($this->logged_in != $username) {
282 $this->login($username);
286 protected function isLoginRequired()
288 return $this->isTextPresent("You've been redirected to this login page") ;
291 protected function isPermissionDenied()
293 return $this->isTextPresent("Permission denied") ;
296 protected function registerProject ($name, $user) {
297 $unix_name = strtolower($name);
299 $saved_user = $this->logged_in ;
300 $this->switchUser ($user) ;
302 $this->clickAndWait("link=My Page");
303 $this->clickAndWait("link=Register Project");
304 $this->type("full_name", $name);
305 $this->type("purpose", "This is a simple description for $name");
306 $this->type("description", "This is the public description for $name.");
307 $this->type("unix_name", $unix_name);
308 $this->click("//input[@name='scm' and @value='scmsvn']");
309 $this->click("submit");
310 $this->waitForPageToLoad("30000");
311 $this->assertTrue($this->isTextPresent("Your project has been submitted"));
312 $this->assertTrue($this->isTextPresent("you will receive notification of their decision and further instructions"));
314 $this->switchUser ($saved_user) ;
317 protected function approveProject ($name, $user) {
318 $unix_name = strtolower($name);
320 $saved_user = $this->logged_in ;
321 $this->switchUser ($user) ;
323 $this->open( ROOT . '/admin/approve-pending.php') ;
324 $this->waitForPageToLoad("30000");
325 $this->click("document.forms['approve.$unix_name'].submit");
326 $this->waitForPageToLoad("60000");
328 $this->assertTrue($this->isTextPresent("Approving Project: $unix_name"));
330 $this->switchUser ($saved_user) ;
333 protected function createProject ($name) {
334 $unix_name = strtolower($name);
336 $this->switchUser ('admin') ;
338 // Create a simple project.
339 if ((!defined('PROJECTA')) || ($unix_name != "projecta")) {
340 $this->registerProject ($name, 'admin') ;
341 $this->approveProject ($name, 'admin') ;
345 protected function createAndGoto($project) {
346 $this->createProject($project);
347 $this->gotoProject($project);
350 protected function createUser ($login)
353 $this->clickAndWait("link=Site Admin");
354 $this->clickAndWait("link=Register a New User");
355 $this->type("unix_name", $login);
356 $this->type("password1", "password");
357 $this->type("password2", "password");
358 $this->type("firstname", $login);
359 $this->type("lastname", "Lastname");
360 $this->type("email", $login."@debug.log");
361 $this->clickAndWait("submit");
362 $this->clickAndWait("link=Site Admin");
363 $this->clickAndWait("link=Display Full User List/Edit Users");
364 $this->click("//table/tbody/tr/td/a[contains(@href,'useredit.php') and contains(.,'($login)')]/../..//a[contains(@href, 'userlist.php?action=activate&user_id=')]");
365 $this->waitForPageToLoad("30000");
368 protected function activatePlugin($pluginName) {
369 $this->switchUser('admin');
370 $this->open( ROOT . '/admin/pluginman.php?update='.$pluginName.'&action=deactivate');
371 $this->waitForPageToLoad("30000");
372 $this->open( ROOT . '/admin/pluginman.php?update='.$pluginName.'&action=activate');
373 $this->waitForPageToLoad("30000");
377 protected function gotoProject($project) {
378 $unix_name = strtolower($project);
380 $this->open( ROOT . '/projects/' . $unix_name) ;
381 $this->waitForPageToLoad("30000");
382 $this->assertTrue($this->isTextPresent("This is the public description for $project."));
388 // c-file-style: "bsd"