summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/includes/querypages/UnusedPropertiesQueryPageTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/includes/querypages/UnusedPropertiesQueryPageTest.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/tests/phpunit/includes/querypages/UnusedPropertiesQueryPageTest.php155
1 files changed, 155 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/includes/querypages/UnusedPropertiesQueryPageTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/includes/querypages/UnusedPropertiesQueryPageTest.php
new file mode 100644
index 00000000..5301f120
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/includes/querypages/UnusedPropertiesQueryPageTest.php
@@ -0,0 +1,155 @@
+<?php
+
+namespace SMW\Test;
+
+use SMW\DataItemFactory;
+use SMW\Settings;
+use SMW\Tests\TestEnvironment;
+use SMW\UnusedPropertiesQueryPage;
+use SMW\Tests\PHPUnitCompat;
+
+/**
+ * @covers \SMW\UnusedPropertiesQueryPage
+ * @group semantic-mediawiki
+ *
+ * @license GNU GPL v2+
+ * @since 1.9
+ *
+ * @author mwjames
+ */
+class UnusedPropertiesQueryPageTest extends \PHPUnit_Framework_TestCase {
+
+ use PHPUnitCompat;
+
+ private $store;
+ private $skin;
+ private $settings;
+ private $dataItemFactory;
+ private $testEnvironment;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->testEnvironment = new TestEnvironment();
+
+ $this->store = $this->getMockBuilder( '\SMW\Store' )
+ ->disableOriginalConstructor()
+ ->getMockForAbstractClass();
+
+ $this->skin = $this->getMockBuilder( '\Skin' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $container = $this->getMockBuilder( '\Onoi\BlobStore\Container' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $blobStore = $this->getMockBuilder( '\Onoi\BlobStore\BlobStore' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $blobStore->expects( $this->any() )
+ ->method( 'read' )
+ ->will( $this->returnValue( $container ) );
+
+ $cachedPropertyValuesPrefetcher = $this->getMockBuilder( '\SMW\CachedPropertyValuesPrefetcher' )
+ ->setConstructorArgs( [ $this->store, $blobStore ] )
+ ->setMethods( null )
+ ->getMock();
+
+ $this->testEnvironment->registerObject( 'CachedPropertyValuesPrefetcher', $cachedPropertyValuesPrefetcher );
+
+ $this->settings = Settings::newFromArray( [] );
+
+ $this->dataItemFactory = new DataItemFactory();
+ }
+
+ protected function tearDown() {
+ $this->testEnvironment->tearDown();
+ }
+
+ public function testCanConstruct() {
+
+ $this->assertInstanceOf(
+ '\SMW\UnusedPropertiesQueryPage',
+ new UnusedPropertiesQueryPage( $this->store, $this->settings )
+ );
+ }
+
+ public function testFormatResultDIError() {
+
+ $error = $this->dataItemFactory->newDIError( 'Foo');
+
+ $instance = new UnusedPropertiesQueryPage(
+ $this->store,
+ $this->settings
+ );
+
+ $result = $instance->formatResult(
+ $this->skin,
+ $error
+ );
+
+ $this->assertInternalType(
+ 'string',
+ $result
+ );
+
+ $this->assertContains(
+ 'Foo',
+ $result
+ );
+ }
+
+ public function testInvalidResultThrowsException() {
+
+ $instance = new UnusedPropertiesQueryPage(
+ $this->store,
+ $this->settings
+ );
+
+ $this->setExpectedException( '\SMW\Exception\PropertyNotFoundException' );
+ $instance->formatResult( $this->skin, null );
+ }
+
+ public function testFormatPropertyItemOnUserDefinedProperty() {
+
+ $property = $this->dataItemFactory->newDIProperty( 'Foo' );
+
+ $instance = new UnusedPropertiesQueryPage(
+ $this->store,
+ $this->settings
+ );
+
+ $result = $instance->formatResult(
+ $this->skin,
+ $property
+ );
+
+ $this->assertContains(
+ 'Foo',
+ $result
+ );
+ }
+
+ public function testFormatPropertyItemOnPredefinedProperty() {
+
+ $property = $this->dataItemFactory->newDIProperty( '_MDAT' );
+
+ $instance = new UnusedPropertiesQueryPage(
+ $this->store,
+ $this->settings
+ );
+
+ $result = $instance->formatResult(
+ $this->skin,
+ $property
+ );
+
+ $this->assertContains(
+ 'Help:Special_properties',
+ $result
+ );
+ }
+
+}