Skip to content

Commit

Permalink
corrected path to the autoloader
Browse files Browse the repository at this point in the history
  • Loading branch information
lapistano committed Nov 19, 2010
1 parent 101aa7e commit 9b7c52f
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 1 deletion.
54 changes: 54 additions & 0 deletions src/Jackalope/NamespaceManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* Class to gather namespace actions.
*
* @license http://www.apache.org/licenses Apache License Version 2.0, January 2004
*
* @package jackalope
*/

namespace Jackalope;

/**
* Class to gather namespace actions.
*
* @package jackalope
*
*/
class NamespaceManager {

/**
* List of predefined namespaces.
* @var array
*/
protected $defaultNamespaces = array();

/**
* Initializes the object to be instantiated.
*
* @param array $defaultNamespaces Set of predefined namespaces.
*/
public function __construct($defaultNamespaces) {
$this->defaultNamespaces = $defaultNamespaces;
}

/**
* Verifies the correctness of the given prefix.
*
* Throws the \PHPCR\NamespaceException if an attempt is made to re-assign
* a built-in prefix to a new URI or, to register a namespace with a prefix
* that begins with the characters "xml" (in any combination of case)
*
* @return void
*
* @throws \PHPCR\NamespaceException if re-assign built-in prefix or prefix starting with xml
*/
protected function checkPrefix($prefix) {
if (! strncasecmp('xml', $prefix, 3)) {
throw new \PHPCR\NamespaceException('Do not use xml in prefixes for namespace changes');
}
if (array_key_exists($prefix, $this->defaultNamespaces)) {
throw new \PHPCR\NamespaceException('Do not change the predefined prefixes');
}
}
}
67 changes: 67 additions & 0 deletions tests/Jackalope/NamespaceManagerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

class NamespaceManagerTest extends PHPUnit_Framework_TestCase {

/*************************************************************************/
/* Fixtures
/*************************************************************************/

/**
* Create a list of namespaces defined by the \PHPCR\NamespaceRegistryInterface.
*
* @return array Set of namespaces.
*/
public function getDefaultNamespacesFixture() {
return array(
"jcr" => "http://www.jcp.org/jcr/1.0",
"nt" => "http://www.jcp.org/jcr/nt/1.0",
"mix" => "http://www.jcp.org/jcr/mix/1.0",
"xml" => "http://www.w3.org/XML/1998/namespace",
"" => ""
);
}

/*************************************************************************/
/* Tests
/*************************************************************************/

/**
* @covers NamespaceManager::checkPrefix
*/
public function testCheckPrefix() {
$prefix = 'beastie';
$ns = new NamespaceManagerProxy($this->getDefaultNamespacesFixture());

$this->assertNull($ns->checkPrefix($prefix));
}

/**
* @dataProvider checkPrefixDataprovider
* @covers NamespaceManager::checkPrefix
* @expectedException \PHPCR\NamespaceException
*/
public function testCheckPrefixExpexctingNamespaceException($prefix) {
$ns = new NamespaceManagerProxy($this->getDefaultNamespacesFixture());
$ns->checkPrefix($prefix);
}


/*************************************************************************/
/* Dataprovider
/*************************************************************************/

public static function checkPrefixDataprovider() {
return array(
'XML as prefix' => array('xml'),
'prefix in list of default namespaces' => array('jcr'),
'empty prefix' => array(''),
);
}
}

class NamespaceManagerProxy extends \Jackalope\NamespaceManager {

public function checkPrefix($prefix) {
return parent::checkPrefix($prefix);
}
}
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
require_once 'PHPUnit/Framework.php';
}

require __DIR__.'/../src/jackalope/autoloader.php';
require __DIR__.'/../src/Jackalope/autoloader.php';
require __DIR__.'/Jackalope/TestCase.php';

0 comments on commit 9b7c52f

Please sign in to comment.