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'): 'func/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->createProject('ProjectA');
84 $this->click("link=ProjectA");
85 $this->waitForPageToLoad("30000");
88 protected function login($username)
91 $this->click("link=Log In");
92 $this->waitForPageToLoad("30000");
93 $this->triggeredLogin($username);
96 protected function triggeredLogin($username)
98 if ($username == 'admin') {
99 $password = 'myadmin';
101 $password = 'password';
104 $this->type("form_loginname", $username);
105 $this->type("form_pw", $password);
106 $this->click("login");
107 $this->waitForPageToLoad("30000");
109 $this->logged_in = $username ;
112 protected function logout()
114 // $this->click("link=Log Out");
115 $this->open( ROOT ."/account/logout.php" );
116 $this->waitForPageToLoad("30000");
118 $this->logged_in = false ;
121 protected function switchUser($username)
123 if ($this->logged_in != $username) {
125 $this->login($username);
129 protected function isLoginRequired()
131 return $this->isTextPresent("You've been redirected to this login page") ;
134 protected function isPermissionDenied()
136 return $this->isTextPresent("Permission denied") ;
139 protected function registerProject ($name, $user) {
140 $unix_name = strtolower($name);
142 $this->switchUser ($user) ;
143 $this->click("link=My Page");
144 $this->waitForPageToLoad("30000");
145 $this->click("link=Register Project");
146 $this->waitForPageToLoad("30000");
147 $this->type("full_name", $name);
148 $this->type("purpose", "This is a simple description for $name");
149 $this->type("description", "This is the public description for $name.");
150 $this->type("unix_name", $unix_name);
151 $this->click("//input[@name='scm' and @value='scmsvn']");
152 $this->click("submit");
153 $this->waitForPageToLoad("30000");
154 $this->assertTrue($this->isTextPresent("Your project has been submitted"));
155 $this->assertTrue($this->isTextPresent("you will receive notification of their decision and further instructions"));
158 protected function approveProject ($name, $user) {
159 $unix_name = strtolower($name);
160 $this->switchUser ($user) ;
162 if ($user == 'admin') {
163 $this->click("link=Site Admin");
164 $this->waitForPageToLoad("30000");
165 $this->click("link=Pending projects (new project approval)");
166 $this->waitForPageToLoad("30000");
168 $this->open( ROOT . '/admin/approve-pending.php') ;
169 $this->waitForPageToLoad("30000");
171 $this->click("document.forms['approve.$unix_name'].submit");
172 $this->waitForPageToLoad("30000");
173 $this->click("link=Home");
174 $this->waitForPageToLoad("30000");
175 $this->assertTrue($this->isTextPresent($name));
176 $this->click("link=$name");
177 $this->waitForPageToLoad("30000");
178 $this->assertTrue($this->isTextPresent("This is the public description for $name."));
179 $this->assertTrue($this->isTextPresent("This project has not yet categorized itself"));
182 protected function createProject ($name) {
183 $unix_name = strtolower($name);
185 // Create a simple project.
186 if ((!defined('PROJECTA')) || ($unix_name != "projecta")) {
187 $this->registerProject ($name, 'admin') ;
188 $this->approveProject ($name, 'admin') ;
192 protected function createUser ($login)
195 $this->click("link=Site Admin");
196 $this->waitForPageToLoad("30000");
197 $this->click("link=Register a New User");
198 $this->waitForPageToLoad("30000");
199 $this->type("unix_name", $login);
200 $this->type("password1", "password");
201 $this->type("password2", "password");
202 $this->type("firstname", $login);
203 $this->type("lastname", "Lastname");
204 $this->type("email", $login."@debug.log");
205 $this->click("submit");
206 $this->waitForPageToLoad("30000");
207 $this->click("link=Site Admin");
208 $this->waitForPageToLoad("30000");
209 $this->click("link=Display Full User List/Edit Users");
210 $this->waitForPageToLoad("30000");
211 $this->click("//*[@id='maindiv']/table/tbody/tr/td/a[contains(@href,'useredit.php') and contains(.,'($login)')]/../..//a[contains(@href, 'userlist.php?action=activate&user_id=')]");
212 $this->waitForPageToLoad("30000");
215 protected function activatePlugin($pluginName) {
216 $this->open( ROOT . '/admin/pluginman.php?update='.$pluginName.'&action=deactivate');
217 $this->waitForPageToLoad("30000");
219 $this->waitForPageToLoad("30000");
220 $this->login('admin');
221 $this->click("link=Site Admin");
222 $this->waitForPageToLoad("30000");
223 $this->click("link=Plugin Manager");
224 $this->waitForPageToLoad("30000");
225 $this->click($pluginName);
226 $this->click("//a[contains(@href, \"javascript:change('".ROOT."/admin/pluginman.php?update=$pluginName&action=activate','$pluginName');\")]");
227 $this->waitForPageToLoad("30000");
231 protected function gotoProject($project) {
232 $this->open( ROOT . '/projects/' . $project) ;
233 $this->waitForPageToLoad("30000");
234 $this->assertTrue($this->isTextPresent("This is the public description for $name."));