3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
5 * This file is a part of Codendi.
7 * Codendi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * Codendi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Codendi. If not, see <http://www.gnu.org/licenses/>.
21 require_once(dirname(__FILE__).'/../include/HudsonBuild.class.php');
22 Mock::generatePartial(
24 'HudsonBuildTestVersion',
25 array('_getXMLObject')
28 require_once 'common/language/BaseLanguage.class.php';
29 Mock::generate('BaseLanguage');
31 class HudsonBuildTest extends UnitTestCase {
33 * Constructor of the test. Can be ommitted.
34 * Usefull to set the name of the test
36 function HudsonBuildTest($name = 'HudsonBuild test') {
37 $this->UnitTestCase($name);
41 $GLOBALS['Language'] = new MockBaseLanguage($this);
44 function testMalformedURL() {
45 $this->expectException('HudsonJobURLMalformedException');
47 $b = new HudsonBuild("toto");
49 function testMissingSchemeURL() {
50 $this->expectException('HudsonJobURLMalformedException');
52 $b = new HudsonBuild("code4:8080/hudson/jobs/Codendi");
54 function testMissingHostURL() {
55 $this->expectException('HudsonJobURLMalformedException');
57 $b = new HudsonBuild("http://");
60 function testWrongXMLFile() {
62 <?xml version='1.0' standalone='yes'?>
68 $xmldom = new SimpleXMLElement($xmlstr);
70 $b = new HudsonBuildTestVersion($this);
71 $b->setReturnValue('_getXMLObject', $xmldom);
72 $b->buildBuildObject();
77 function testSimpleJobBuild() {
79 $build_file = dirname(__FILE__).'/resources/jobbuild.xml';
80 $xmldom = simplexml_load_file($build_file);
82 $b = new HudsonBuildTestVersion($this);
83 $b->setReturnValue('_getXMLObject', $xmldom);
85 $b->HudsonBuild("http://myCIserver/jobs/myCIjob/lastBuild/");
87 $this->assertEqual($b->getBuildStyle(), "freeStyleBuild");
88 $this->assertFalse($b->isBuilding());
89 $this->assertEqual($b->getUrl(), "http://code4.grenoble.xrce.xerox.com:8080/hudson/job/Codendi/87/");
90 $this->assertEqual($b->getResult(), "UNSTABLE");
91 $this->assertEqual($b->getNumber(), 87);
92 $this->assertEqual($b->getDuration(), 359231);
93 $this->assertEqual($b->getTimestamp(), 1230051671000);