This repository has been archived by the owner on Aug 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CommonNamespaces: fixed shortenUri; added basic tests
* shortenUri uses the first prefix it found and not the one with longest URI. without the fix, results like happen: foo:bar/baz * added tests for shortenUri and extendUri
- Loading branch information
Showing
2 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Saft\Rdf\Test; | ||
|
||
use Saft\Rdf\CommonNamespaces; | ||
use Saft\Test\TestCase; | ||
|
||
class CommonNamespacesTest extends TestCase | ||
{ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->fixture = new CommonNamespaces(); | ||
} | ||
|
||
/* | ||
* Tests for extendUri | ||
*/ | ||
|
||
public function testExtendUri() | ||
{ | ||
$this->fixture->add('foo', 'http://foo/'); | ||
|
||
$this->assertEquals('http://foo/bar', $this->fixture->extendUri('foo:bar')); | ||
} | ||
|
||
public function testExtendUriOverlappingPrefixes() | ||
{ | ||
$this->fixture->add('foo', 'http://foo/'); | ||
$this->fixture->add('foo2', 'http://foo/baz/'); | ||
|
||
$this->assertEquals('http://foo/baz/bar', $this->fixture->extendUri('foo2:bar')); | ||
} | ||
|
||
/* | ||
* Tests for shortenUri | ||
*/ | ||
|
||
public function testShortenUri() | ||
{ | ||
$this->fixture->add('foo', 'http://foo/'); | ||
|
||
$this->assertEquals('foo:bar', $this->fixture->shortenUri('http://foo/bar')); | ||
} | ||
|
||
// test that in case you have overlapping namespace URIs, the longest will be used | ||
// to avoid results like foo:bar/baz | ||
public function testShortenUriOverlappingPrefixes() | ||
{ | ||
$this->fixture->add('foo', 'http://foo/'); | ||
$this->fixture->add('foo2', 'http://foo/baz/'); | ||
|
||
$this->assertEquals('foo2:bar', $this->fixture->shortenUri('http://foo/baz/bar')); | ||
} | ||
} |