2015-09-11 14:21:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers WikiReference
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
class WikiReferenceTest extends PHPUnit_Framework_TestCase {
|
|
|
|
|
|
|
|
|
|
public function provideGetHostname() {
|
|
|
|
|
return array(
|
|
|
|
|
'http' => array( 'foo.bar', 'http://foo.bar' ),
|
|
|
|
|
'https' => array( 'foo.bar', 'https://foo.bar' ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetHostname
|
|
|
|
|
*/
|
|
|
|
|
public function testGetHostname( $expected, $canonicalServer ) {
|
|
|
|
|
$this->markTestSkipped( 'The implementation is patently broken.' );
|
|
|
|
|
|
|
|
|
|
$reference = new WikiReference( 'wiki', 'xx', $canonicalServer, '/wiki/$1' );
|
|
|
|
|
$this->assertEquals( $expected, $reference->getHostname() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideGetDisplayName() {
|
|
|
|
|
return array(
|
|
|
|
|
'http' => array( 'foo.bar', 'http://foo.bar' ),
|
|
|
|
|
'https' => array( 'foo.bar', 'http://foo.bar' ),
|
|
|
|
|
|
|
|
|
|
// apparently, this is the expected behavior
|
|
|
|
|
'invalid' => array( 'purple kittens/wiki/', 'purple kittens' ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetDisplayName
|
|
|
|
|
*/
|
|
|
|
|
public function testGetDisplayName( $expected, $canonicalServer ) {
|
|
|
|
|
$reference = new WikiReference( 'wiki', 'xx', $canonicalServer, '/wiki/$1' );
|
|
|
|
|
$this->assertEquals( $expected, $reference->getDisplayName() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetCanonicalServer() {
|
|
|
|
|
$reference = new WikiReference( 'wiki', 'xx', 'https://acme.com', '/wiki/$1', '//acme.com' );
|
|
|
|
|
$this->assertEquals( 'https://acme.com', $reference->getCanonicalServer() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideGetCanonicalUrl() {
|
|
|
|
|
return array(
|
2015-09-11 14:17:52 +00:00
|
|
|
'no fragement' => array( 'https://acme.com/wiki/Foo', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', null ),
|
|
|
|
|
'empty fragement' => array( 'https://acme.com/wiki/Foo', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', '' ),
|
|
|
|
|
'fragment' => array( 'https://acme.com/wiki/Foo#Bar', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', 'Bar' ),
|
|
|
|
|
'double fragment' => array( 'https://acme.com/wiki/Foo#Bar%23Xus', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', 'Bar#Xus' ),
|
|
|
|
|
'escaped fragement' => array( 'https://acme.com/wiki/Foo%23Bar', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo#Bar', null ),
|
|
|
|
|
'empty path' => array( 'https://acme.com/Foo', 'https://acme.com', '//acme.com', '/$1', 'Foo', null ),
|
2015-09-11 14:21:16 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetCanonicalUrl
|
|
|
|
|
*/
|
2015-09-11 14:17:52 +00:00
|
|
|
public function testGetCanonicalUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
|
2015-09-11 14:21:16 +00:00
|
|
|
$reference = new WikiReference( 'wiki', 'xx', $canonicalServer, $path, $server );
|
2015-09-11 14:17:52 +00:00
|
|
|
$this->assertEquals( $expected, $reference->getCanonicalUrl( $page, $fragmentId ) );
|
2015-09-11 14:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetCanonicalUrl
|
|
|
|
|
*/
|
2015-09-11 14:17:52 +00:00
|
|
|
public function testGetUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
|
2015-09-11 14:21:16 +00:00
|
|
|
$reference = new WikiReference( 'wiki', 'xx', $canonicalServer, $path, $server );
|
2015-09-11 14:17:52 +00:00
|
|
|
$this->assertEquals( $expected, $reference->getUrl( $page, $fragmentId ) );
|
2015-09-11 14:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideGetFullUrl() {
|
|
|
|
|
return array(
|
2015-09-11 14:17:52 +00:00
|
|
|
'no fragement' => array( '//acme.com/wiki/Foo', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', null ),
|
|
|
|
|
'empty fragement' => array( '//acme.com/wiki/Foo', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', '' ),
|
|
|
|
|
'fragment' => array( '//acme.com/wiki/Foo#Bar', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', 'Bar' ),
|
|
|
|
|
'double fragment' => array( '//acme.com/wiki/Foo#Bar%23Xus', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', 'Bar#Xus' ),
|
|
|
|
|
'escaped fragement' => array( '//acme.com/wiki/Foo%23Bar', 'https://acme.com', '//acme.com', '/wiki/$1', 'Foo#Bar', null ),
|
2015-09-11 14:21:16 +00:00
|
|
|
'empty path' => array( '//acme.com/Foo', 'https://acme.com', '//acme.com', '/$1', 'Foo', null ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetFullUrl
|
|
|
|
|
*/
|
2015-09-11 14:17:52 +00:00
|
|
|
public function testGetFullUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
|
2015-09-11 14:21:16 +00:00
|
|
|
$reference = new WikiReference( 'wiki', 'xx', $canonicalServer, $path, $server );
|
2015-09-11 14:17:52 +00:00
|
|
|
$this->assertEquals( $expected, $reference->getFullUrl( $page, $fragmentId ) );
|
2015-09-11 14:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|