diff options
Diffstat (limited to 'SemanticMediaWiki/tests/phpunit/Integration/MediaWiki/ApiBrowseBySubjectDBIntegrationTest.php')
-rw-r--r-- | SemanticMediaWiki/tests/phpunit/Integration/MediaWiki/ApiBrowseBySubjectDBIntegrationTest.php | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/SemanticMediaWiki/tests/phpunit/Integration/MediaWiki/ApiBrowseBySubjectDBIntegrationTest.php b/SemanticMediaWiki/tests/phpunit/Integration/MediaWiki/ApiBrowseBySubjectDBIntegrationTest.php new file mode 100644 index 00000000..e815dbc6 --- /dev/null +++ b/SemanticMediaWiki/tests/phpunit/Integration/MediaWiki/ApiBrowseBySubjectDBIntegrationTest.php @@ -0,0 +1,156 @@ +<?php + +namespace SMW\Tests\Integration\MediaWiki; + +use SMW\Tests\MwDBaseUnitTestCase; +use SMW\Tests\Util\MwApiFactory; +use SMW\Tests\Util\SemanticDataFactory; + +use SMW\MediaWiki\Api\BrowseBySubject; + +use SMW\SemanticData; +use SMW\DIWikiPage; +use SMW\DataValueFactory; +use SMW\Subobject; +use SMW\SerializerFactory; + +/** + * @ingroup Test + * + * @group SMW + * @group SMWExtension + * @group semantic-mediawiki-integration + * @group mediawiki-database + * + * @license GNU GPL v2+ + * @since 2.0 + * + * @author mwjames + */ +class ApiBrowseBySubjectDBIntegrationTest extends MwDBaseUnitTestCase { + + protected $destroyDatabaseTablesOnEachRun = true; + + private $apiFactory; + private $dataValueFactory; + private $serializerFactory; + private $semanticDataFactory; + + protected function setUp() { + parent::setUp(); + + $this->apiFactory = new MwApiFactory(); + $this->dataValueFactory = DataValueFactory::getInstance(); + $this->serializerFactory = new SerializerFactory(); + $this->semanticDataFactory = new SemanticDataFactory(); + } + + public function testResultDataForEmptySemanticData() { + + $semanticData = $this->semanticDataFactory->newEmptySemanticData( __METHOD__ ); + + $this->getStore()->updateData( $semanticData ); + + $resultData = $this->newBrowseBySubject( __METHOD__ )->getResultData(); + + $this->assertInternalType( + 'array', + $resultData + ); + + $this->assertInstanceOf( + '\SMW\SemanticData', + $this->serializerFactory->deserialize( $resultData['query'] ) + ); + + $this->assertInternalType( + 'array', + $this->newBrowseBySubject( __METHOD__, true )->getResultData() + ); + } + + public function testResultDataForSingleSemanticDataValueAssignment() { + + $semanticData = $this->semanticDataFactory->newEmptySemanticData( __METHOD__ ); + + $semanticData->addDataValue( + $this->dataValueFactory->newPropertyValue( __METHOD__ , 'Bar' ) + ); + + $this->getStore()->updateData( $semanticData ); + + $resultData = $this->newBrowseBySubject( __METHOD__ )->getResultData(); + + $this->assertInternalType( + 'array', + $resultData + ); + + $this->assertInstanceOf( + '\SMW\SemanticData', + $this->serializerFactory->deserialize( $resultData['query'] ) + ); + + $this->assertInternalType( + 'array', + $this->newBrowseBySubject( __METHOD__, true )->getResultData() + ); + } + + public function testResultDataFoSubobjectExtendedSemanticData() { + + $semanticData = $this->semanticDataFactory->newEmptySemanticData( __METHOD__ ); + + $semanticData->addDataValue( + $this->dataValueFactory->newPropertyValue( __METHOD__ , 'Bar' ) + ); + + $subobject = new Subobject( $semanticData->getSubject()->getTitle() ); + $subobject->setEmptySemanticDataForId( 'Foo' ); + + $subobject->addDataValue( + $this->dataValueFactory->newPropertyValue( __METHOD__ , 'Bam' ) + ); + + $semanticData->addPropertyObjectValue( + $subobject->getProperty(), + $subobject->getContainer() + ); + + $this->getStore()->updateData( $semanticData ); + + $resultData = $this->newBrowseBySubject( __METHOD__ )->getResultData(); + + $this->assertInternalType( + 'array', + $resultData + ); + + $this->assertInstanceOf( + '\SMW\SemanticData', + $this->serializerFactory->deserialize( $resultData['query'] ) + ); + + $this->assertInternalType( + 'array', + $this->newBrowseBySubject( __METHOD__, true )->getResultData() + ); + } + + private function newBrowseBySubject( $subject, $asRawMode = false ) { + + $instance = new BrowseBySubject( + $this->apiFactory->newApiMain( array( 'subject' => $subject ) ), + 'browsebysubject' + ); + + if ( $asRawMode ) { + $instance->getMain()->getResult()->setRawMode(); + } + + $instance->execute(); + + return $instance; + } + +} |