| <?php |
| /******************************************************************************* |
| * Copyright (c) 2010 Eclipse Foundation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Wayne Beaton (Eclipse Foundation)- initial API and implementation |
| *******************************************************************************/ |
| |
| require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/app.class.php"); |
| $App = new App(); |
| |
| require_once '../classes/ProjectRoot.class.php'; |
| require_once '../classes/TestRunner.class.php'; |
| |
| class ProjectTests extends TestCase { |
| function testProjectNameIsValid() { |
| $this->assertTrue(ProjectRoot::isValidProjectName("eclipse")); |
| $this->assertTrue(ProjectRoot::isValidProjectName("eclipse.technology")); |
| $this->assertTrue(ProjectRoot::isValidProjectName("eclipse.technology.foo")); |
| $this->assertTrue(ProjectRoot::isValidProjectName("eclipse.technology.g-foo")); |
| |
| $this->assertFalse(ProjectRoot::isValidProjectName("")); |
| $this->assertFalse(ProjectRoot::isValidProjectName("eclipse.technology.foo.stuff")); |
| } |
| |
| // function testNormalizeDescriptionUrl() { |
| // $this->assertNull(Project::normalizeProjectDescriptionUrl("")); |
| // $this->assertNull(Project::normalizeProjectDescriptionUrl("http://other.site/description.html")); |
| // $this->assertNull(Project::normalizeProjectDescriptionUrl("http://.eclipse.org/technology/description.html")); |
| // |
| // $this->assertEquals("http://www.eclipse.org/technology/description.html", Project::normalizeProjectDescriptionUrl("http://www.eclipse.org/technology/description.html")); |
| // $this->assertEquals("http://eclipse.org/technology/description.html", Project::normalizeProjectDescriptionUrl("http://eclipse.org/technology/description.html")); |
| // $this->assertEquals("http://www.eclipse.org/technology/description.html", Project::normalizeProjectDescriptionUrl("/technology/description.html")); |
| // $this->assertEquals("http://www.eclipse.org/technology/description.html", Project::normalizeProjectDescriptionUrl("technology/description.html")); |
| // } |
| |
| function testExtractShortDescription() { |
| $this->assertEquals("Description1", Project::extractShortDescription("<p>Description1</p>")); |
| $this->assertEquals("Description2", Project::extractShortDescription("<div><p>Description2</p>\n<p>Junk</p></div>")); |
| $this->assertEquals("Description3\nline2", Project::extractShortDescription("<p>Description3\nline2</p>")); |
| $this->assertEquals("Description4", Project::extractShortDescription("<h1>Ignore</h1><p>Description4</p><p>line2</p>")); |
| |
| $this->assertEquals("x <b>q</b> z", Project::extractShortDescription("<h1>Ignore</h1><p>x <b>q</b> z</p><p>line2</p>")); |
| $this->assertEquals("x q", Project::extractShortDescription("<h1>Ignore</h1><p>x q<br> c</p><p>line2</p>")); |
| $this->assertEquals("x q", Project::extractShortDescription("<h1>Ignore</h1><p>x q<br/> c</p><p>line2</p>")); |
| $this->assertEquals("x q", Project::extractShortDescription("<h1>Ignore</h1><p>x q<br /> c</p><p>line2</p>")); |
| $this->assertEquals("x q", Project::extractShortDescription("<p><div>x q</div></p>")); |
| $this->assertEquals("x q", Project::extractShortDescription("<p><div style=\"blah\">x q</div></p>")); |
| } |
| |
| function testExtractShortDescription2() { |
| $this->assertEquals("Two words ...", Project::extractShortDescription("<p>Two words are better than one.</p>", 2)); |
| } |
| |
| function testSingleProjectInitialLoad() { |
| global $App; |
| if (!$App->devmode) return $this->fail("This test can only be run in development mode."); |
| |
| $root = new ProjectRoot(); |
| $project = $root->get_project("technology.dash"); |
| |
| $this->assertEquals("technology.dash", $project->getId()); |
| $this->assertFalse($project->root->isProjectInfoLoaded); |
| } |
| |
| function testSingleProjectLoadProjectInfo() { |
| global $App; |
| if (!$App->devmode) return $this->fail("This test can only be run in development mode."); |
| |
| $root = new ProjectRoot(); |
| |
| $project = $root->get_project("technology.foo"); |
| |
| $this->assertEquals("http://www.eclipse.org/foo/downloads.php", $project->getDownloadsUrl()); |
| $this->assertTrue($root->isProjectInfoLoaded); |
| } |
| |
| /* |
| * When the same ProjectRoot is used to get the same project, it should |
| * answer the same object (i.e. object identity is preserved). |
| */ |
| function testMultipleGetIdentity() { |
| global $App; |
| if (!$App->devmode) return $this->fail("This test can only be run in development mode."); |
| |
| $root = new ProjectRoot(); |
| |
| $project1 = $root->get_project("technology.foo"); |
| $project2 = $root->get_project("technology.foo"); |
| |
| $this->assertSame($project1, $project2); |
| } |
| |
| function testGetSourceRepository() { |
| $this->assertEquals('cvs', getSourceRepository('/cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.emf4net.releng')->getType()); |
| $this->assertEquals('/cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.emf4net.releng', getSourceRepository('/cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.emf4net.releng')->getPath()); |
| $this->assertEquals('/cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.emf4net.releng', getSourceRepository('/cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.emf4net.releng/')->getPath()); |
| |
| $this->assertEquals('svn', getSourceRepository('/technology/org.eclipse.imp')->getType()); |
| $this->assertEquals('/svnroot/technology/org.eclipse.imp', getSourceRepository('technology/org.eclipse.imp')->getPath()); |
| $this->assertEquals('/svnroot/technology/org.eclipse.imp', getSourceRepository('technology/org.eclipse.imp/')->getPath()); |
| $this->assertEquals('/svnroot/technology/org.eclipse.imp', getSourceRepository('/technology/org.eclipse.imp')->getPath()); |
| $this->assertEquals('/svnroot/technology/org.eclipse.imp', getSourceRepository('/technology/org.eclipse.imp/')->getPath()); |
| $this->assertEquals('/svnroot/technology/org.eclipse.imp', getSourceRepository('/svnroot/technology/org.eclipse.imp')->getPath()); |
| $this->assertEquals('/svnroot/technology/org.eclipse.imp', getSourceRepository('/svnroot/technology/org.eclipse.imp/')->getPath()); |
| |
| $this->assertEquals('git', getSourceRepository('git://git.eclipse.org/gitroot/sketch/org.eclipse.sketch.git')->getType()); |
| $this->assertEquals('git', getSourceRepository('/gitroot/ecf/org.eclipse.ecf.git/')->getType()); |
| $this->assertEquals('git', getSourceRepository('/gitroot/ecf/org.eclipse.ecf.git')->getType()); |
| $this->assertEquals('git', getSourceRepository('git://egit.eclipse.org/egit.git')->getType()); |
| $this->assertEquals('/gitroot/sketch/org.eclipse.sketch.git', getSourceRepository('git://git.eclipse.org/gitroot/sketch/org.eclipse.sketch.git')->getPath()); |
| $this->assertEquals('/gitroot/ecf/org.eclipse.ecf.git', getSourceRepository('/gitroot/ecf/org.eclipse.ecf.git')->getPath()); |
| $this->assertEquals('/gitroot/ecf/org.eclipse.ecf.git', getSourceRepository('/gitroot/ecf/org.eclipse.ecf.git/')->getPath()); |
| $this->assertEquals('/gitroot/ecf/org.eclipse.ecf.git', getSourceRepository('http://git.eclipse.org/c/gitroot/ecf/org.eclipse.ecf.git/')->getPath()); |
| } |
| } |
| |
| $App = new App(); |
| |
| $runner = new TestRunner("ProjectTests"); |
| $runner->run_tests(); |
| |
| ?> |