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
19 * along with FusionForge; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
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);
72 // protected function waitForPageToLoad($timeout)
74 // parent::waitForPageToLoad($timeout);
75 // $this->test->assertFalse($this->isTextPresent("Notice: Undefined variable:"));
76 // $this->test->assertFalse($this->isTextPresent("Notice: Undefined index:"));
77 // $this->test->assertFalse($this->isTextPresent("Warning: Missing argument"));
80 protected function init() {
81 $this->createAndGoto('ProjectA');
84 protected function login($username)
87 $this->clickAndWait("link=Log In");
88 $this->triggeredLogin($username);
91 protected function triggeredLogin($username)
93 if ($username == 'admin') {
94 $password = 'myadmin';
96 $password = 'password';
99 $this->type("form_loginname", $username);
100 $this->type("form_pw", $password);
101 $this->clickAndWait("login");
103 $this->logged_in = $username ;
106 protected function logout()
108 // $this->click("link=Log Out");
109 $this->open( ROOT ."/account/logout.php" );
110 $this->waitForPageToLoad("30000");
112 $this->logged_in = false ;
115 protected function switchUser($username)
117 if ($this->logged_in != $username) {
119 $this->login($username);
123 protected function isLoginRequired()
125 return $this->isTextPresent("You've been redirected to this login page") ;
128 protected function isPermissionDenied()
130 return $this->isTextPresent("Permission denied") ;
133 protected function registerProject ($name, $user) {
134 $unix_name = strtolower($name);
136 $saved_user = $this->logged_in ;
137 $this->switchUser ($user) ;
139 $this->clickAndWait("link=My Page");
140 $this->clickAndWait("link=Register Project");
141 $this->type("full_name", $name);
142 $this->type("purpose", "This is a simple description for $name");
143 $this->type("description", "This is the public description for $name.");
144 $this->type("unix_name", $unix_name);
145 $this->click("//input[@name='scm' and @value='scmsvn']");
146 $this->click("submit");
147 $this->waitForPageToLoad("30000");
148 $this->assertTrue($this->isTextPresent("Your project has been submitted"));
149 $this->assertTrue($this->isTextPresent("you will receive notification of their decision and further instructions"));
151 $this->switchUser ($saved_user) ;
154 protected function approveProject ($name, $user) {
155 $unix_name = strtolower($name);
157 $saved_user = $this->logged_in ;
158 $this->switchUser ($user) ;
160 $this->open( ROOT . '/admin/approve-pending.php') ;
161 $this->waitForPageToLoad("30000");
162 $this->click("document.forms['approve.$unix_name'].submit");
163 $this->waitForPageToLoad("60000");
165 $this->assertTrue($this->isTextPresent("Approving Project: $unix_name"));
167 $this->switchUser ($saved_user) ;
170 protected function createProject ($name) {
171 $unix_name = strtolower($name);
173 $this->switchUser ('admin') ;
175 // Create a simple project.
176 if ((!defined('PROJECTA')) || ($unix_name != "projecta")) {
177 $this->registerProject ($name, 'admin') ;
178 $this->approveProject ($name, 'admin') ;
182 protected function createAndGoto($project) {
183 $this->createProject($project);
184 $this->gotoProject($project);
187 protected function createUser ($login)
190 $this->clickAndWait("link=Site Admin");
191 $this->clickAndWait("link=Register a New User");
192 $this->type("unix_name", $login);
193 $this->type("password1", "password");
194 $this->type("password2", "password");
195 $this->type("firstname", $login);
196 $this->type("lastname", "Lastname");
197 $this->type("email", $login."@debug.log");
198 $this->clickAndWait("submit");
199 $this->clickAndWait("link=Site Admin");
200 $this->clickAndWait("link=Display Full User List/Edit Users");
201 $this->click("//table/tbody/tr/td/a[contains(@href,'useredit.php') and contains(.,'($login)')]/../..//a[contains(@href, 'userlist.php?action=activate&user_id=')]");
202 $this->waitForPageToLoad("30000");
205 protected function activatePlugin($pluginName) {
206 $this->switchUser('admin');
207 $this->open( ROOT . '/admin/pluginman.php?update='.$pluginName.'&action=deactivate');
208 $this->waitForPageToLoad("30000");
209 $this->open( ROOT . '/admin/pluginman.php?update='.$pluginName.'&action=activate');
210 $this->waitForPageToLoad("30000");
214 protected function gotoProject($project) {
215 $unix_name = strtolower($project);
217 $this->open( ROOT . '/projects/' . $unix_name) ;
218 $this->waitForPageToLoad("30000");
219 $this->assertTrue($this->isTextPresent("This is the public description for $project."));
225 // c-file-style: "bsd"