diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Page/PageFactoryTest.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Page/PageFactoryTest.php | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Page/PageFactoryTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Page/PageFactoryTest.php new file mode 100644 index 00000000..af5503a5 --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Page/PageFactoryTest.php @@ -0,0 +1,91 @@ +<?php + +namespace SMW\Tests\Page; + +use SMW\Page\PageFactory; +use SMW\Tests\PHPUnitCompat; + +/** + * @covers \SMW\Page\PageFactory + * @group semantic-mediawiki + * + * @license GNU GPL v2+ + * @since 3.0 + * + * @author mwjames + */ +class PageFactoryTest extends \PHPUnit_Framework_TestCase { + + use PHPUnitCompat; + + private $store; + + protected function setUp() { + parent::setUp(); + + $this->store = $this->getMockBuilder( '\SMW\Store' ) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + } + + public function testCanConstruct() { + + $this->assertInstanceOf( + PageFactory::class, + new PageFactory( $this->store ) + ); + } + + public function testNewPageFromNotRegisteredNamespaceThrowsException() { + + $title = $this->getMockBuilder( '\Title' ) + ->disableOriginalConstructor() + ->getMock(); + + $title->expects( $this->atLeastOnce() ) + ->method( 'getNamespace' ) + ->will( $this->returnValue( NS_MAIN ) ); + + $instance = new PageFactory( $this->store ); + + $this->setExpectedException( 'RuntimeException' ); + $instance->newPageFromTitle( $title ); + } + + /** + * @dataProvider namespaceProvider + */ + public function testNewPageFromTitle( $namespace, $expected ) { + + $title = $this->getMockBuilder( '\Title' ) + ->disableOriginalConstructor() + ->getMock(); + + $title->expects( $this->atLeastOnce() ) + ->method( 'getNamespace' ) + ->will( $this->returnValue( $namespace ) ); + + $instance = new PageFactory( $this->store ); + + $this->assertInstanceOf( + $expected, + $instance->newPageFromTitle( $title ) + ); + } + + public function namespaceProvider() { + + $provider[] = [ + SMW_NS_PROPERTY, + 'SMW\Page\PropertyPage' + ]; + + $provider[] = [ + SMW_NS_CONCEPT, + 'SMW\Page\ConceptPage' + ]; + + return $provider; + } + +} |