Location: PHPKode > scripts > NIKAcore > nikacore/PageNameCollection.test.php
<?php

// NIKAcore: core classes for PHP websites
// 
// Copyright (C) 2003 NIKA Consulting, Inc.
//
// This file is part of NIKAcore.
// 
// NIKAcore is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 2.1 of the License, or (at your option)
// any later version.
// 
// NIKAcore is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
// more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with NIKAcore; if not, write to the Free Software Foundation, Inc., 59
// Temple Place, Suite 330, Boston, MA  02111-1307  USA
// 
// Contact hide@address.com with comments, questions, or patches.

require_once('MyTestCase.php');
require_once('Habitat.test.php');
require_once('PageNameCollection.php');

class FakeCollection_overrides_createDefault extends PageNameCollection {

	var $createDefaultWasCalled = false;

	function createDefault() { $this->createDefaultWasCalled = true; }

	function createDefaultWasCalled() { return $this->createDefaultWasCalled; }
	
}

class Tst_PageNameCollection extends MyTestCase {

	function setUp() {
		$this->coll = PageNameCollection::createFromFile('test-1.urlmap');
	}

	function test_createFromFile() {
		$this->assertClass('PageNameCollection', $this->coll);
		$this->assert(! $this->coll->isNull());
		$noncoll = PageNameCollection::createFromFile('nonexistentfile.urlmap');
		$this->assertClass('NullPageNameCollection', $noncoll);
		$this->assert($noncoll->isNull(), 'NullPageNameCollection isNull()');
	}

	function test_getLongSiteName() {
		$this->assertEquals(
			'Grand Big Site Name', $this->coll->getLongSiteName()
		);
		$c2 = new PageNameCollection;
		$c2->add(PageName::createFromLine($c2, '/=Siteynamey|Sny'));
		$this->assertEquals('Siteynamey', $c2->getLongSiteName());
		$this->assertEquals('Sny', $c2->getSiteName());
	}

	function test_getSiteName() {
		$this->assertEquals('Site Name', $this->coll->getSiteName());
	}

	function test_count() {
		$newcoll = new PageNameCollection;
		$this->assertEquals(0, $newcoll->count());
		$newcoll->add(new PageName($newcoll, '/', 'Name'));
		$this->assertEquals(1, $newcoll->count());
		$this->assertEquals(4, $this->coll->count(), "Nulls shouldn't be added, right?");
	}

	function test_null_add_and_count() {
		$npnc = PageNameCollection::newNull();
		$this->assertEquals(0, $npnc->count());
		$npnc->add(PageName::createFromLine($npnc, '/=Me'));
		$this->assertEquals(0, $npnc->count(), "can't add to a null coll");
	}

	function test_getCurrent_uses_habitat_to_populate() {
		$mh = new MockHabitat;
		$mh->setUrlmapFilename('test-1.urlmap');
		$coll = new PageNameCollection;
		$forgetting_this = $coll->getCurrent($mh);
		$this->assertEquals(4, $coll->count());
	}

	function test_getCurrent_returns_PageName_using_habitats_requesturi() {
		$mh = new MockHabitat;
		$mh->setUrlmapFilename('test-1.urlmap');
		$mh->setRequestUri('/about/granules.html');
		$coll = new PageNameCollection;
		$pn = $coll->getCurrent($mh);
		$this->assertEquals('What Our Granules Say', $pn->getLongName());
	}

}
$nikacore_suite->addTest(new TestSuite('Tst_PageNameCollection'));

?>
Return current item: NIKAcore