3 * Copyright (C) 2012 Roland Mas
5 * This file is part of FusionForge.
7 * FusionForge is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2 of the License,
10 * or (at your option) any later version.
12 * FusionForge is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 require_once dirname(dirname(__FILE__)).'/Testing/SeleniumGforge.php';
24 class ScmGitSSHTest extends FForge_SeleniumTestCase
26 function testScmGitSSH()
28 $this->activatePlugin('scmgit');
29 $this->populateStandardTemplate('empty');
33 $this->clickAndWait("link=ProjectA");
34 $this->clickAndWait("link=Admin");
35 $this->clickAndWait("link=Tools");
36 $this->clickAndWait("link=Source Code Admin");
37 $this->click("//input[@name='scmradio' and @value='scmgit']");
38 $this->clickAndWait("submit");
40 $this->uploadSshKey();
42 // Run the cronjob to create repositories
44 $this->cron("create_scm_repos.php");
45 $this->cron("homedirs.php");
46 $this->cron("ssh_create.php");
48 // Get the address of the repo
50 $this->clickAndWait("link=ProjectA");
51 $this->clickAndWait("link=SCM");
52 $p = $this->getText("//tt[contains(.,'git clone git+ssh')]");
53 $p = preg_replace(",^git clone ,", "", $p);
55 // Create a local clone, add stuff, push it to the repo
56 system("git config --global core.askpass ''", $ret);
57 $this->assertEquals($ret, 0);
58 $t = exec("mktemp -d /tmp/gitTest.XXXXXX");
59 system("cd $t && git clone --quiet $p", $ret);
60 $this->assertEquals($ret, 0);
62 system("echo 'this is a simple text' > $t/projecta/mytext.txt");
63 system("cd $t/projecta && git add mytext.txt && git commit --quiet -a -m'Adding file'", $ret);
64 system("echo 'another simple text' >> $t/projecta/mytext.txt");
65 system("cd $t/projecta && git commit --quiet -a -m'Modifying file'", $ret);
66 $this->assertEquals($ret, 0);
68 system("cd $t/projecta && git push --quiet --all", $ret);
69 $this->assertEquals($ret, 0);
71 // Check that the changes appear in gitweb
72 $this->open(ROOT.'/plugins/scmgit/cgi-bin/gitweb.cgi?a=project_list;pf=projecta');
73 $this->waitForPageToLoad();
74 $this->assertElementPresent("//.[@class='page_footer']");
75 $this->assertTextPresent("projecta.git");
76 $this->click("link=projecta/projecta.git");
77 $this->waitForPageToLoad();
78 $this->assertTextPresent("Modifying file");
79 $this->assertTextPresent("Adding file");
85 * Method that is called after Selenium actions.
87 * @param string $action
89 protected function defaultAssertions($action)
91 if ($action == 'waitForPageToLoad') {
92 $this->assertTrue($this->isElementPresent("//h1")
93 || $this->isElementPresent("//.[@class='page_footer']"));