dataValueFactory = DataValueFactory::getInstance(); $utilityFactory = UtilityFactory::getInstance(); $utilityFactory->newMwHooksHandler()->invokeHooksFromRegistry(); $this->semanticDataFactory = $utilityFactory->newSemanticDataFactory(); $this->queryResultValidator = $utilityFactory->newValidatorFactory()->newQueryResultValidator(); $this->fixturesProvider = $utilityFactory->newFixturesFactory()->newFixturesProvider(); $this->fixturesProvider->setupDependencies( $this->getStore() ); } protected function tearDown(): void { $fixturesCleaner = UtilityFactory::getInstance()->newFixturesFactory()->newFixturesCleaner(); $fixturesCleaner ->purgeAllKnownFacts() ->purgeSubjects( $this->subjectsToBeCleared ); parent::tearDown(); } public function testUserDefinedDateProperty() { $property = new DIProperty( 'SomeDateProperty' ); $property->setPropertyTypeId( '_dat' ); $dataValue = $this->dataValueFactory->newDataValueByProperty( $property, '1 January 1970' ); $semanticData = $this->semanticDataFactory->newEmptySemanticData( __METHOD__ ); $semanticData->addDataValue( $dataValue ); $this->getStore()->updateData( $semanticData ); Exporter::getInstance()->clear(); $this->assertArrayHasKey( $property->getKey(), $this->getStore()->getSemanticData( $semanticData->getSubject() )->getProperties() ); $propertyValue = new PropertyValue( '__pro' ); $propertyValue->setDataItem( $property ); $description = new SomeProperty( $property, new ThingDescription() ); $description->addPrintRequest( new PrintRequest( PrintRequest::PRINT_PROP, null, $propertyValue ) ); $query = new Query( $description, false, false ); $query->querymode = Query::MODE_INSTANCES; $queryResult = $this->getStore()->getQueryResult( $query ); $this->queryResultValidator->assertThatQueryResultContains( $dataValue, $queryResult ); $this->subjectsToBeCleared[] = $semanticData->getSubject(); } /** * #576 */ public function testSortableDateQuery() { $this->getStore()->updateData( $this->fixturesProvider->getFactsheet( 'Berlin' )->asEntity() ); // #576 introduced resource caching, therefore make sure that the // instance is cleared after data have been created before further // tests are carried out Exporter::getInstance()->clear(); /** * @query {{#ask: [[Founded::SomeDistinctValue]] }} */ $foundedValue = $this->fixturesProvider->getFactsheet( 'Berlin' )->getFoundedValue(); $description = new SomeProperty( $foundedValue->getProperty(), new ValueDescription( $foundedValue->getDataItem(), null, SMW_CMP_EQ ) ); $propertyValue = new PropertyValue( '__pro' ); $propertyValue->setDataItem( $foundedValue->getProperty() ); $query = new Query( $description, false, false ); $query->querymode = Query::MODE_INSTANCES; $query->sortkeys = [ $foundedValue->getProperty()->getLabel() => 'ASC' ]; // Be aware of // Virtuoso 22023 Error SR353: Sorted TOP clause specifies more then // 10001 rows to sort. Only 10000 are allowed. Either decrease the // offset and/or row count or use a scrollable cursor $query->setLimit( 100 ); $query->setExtraPrintouts( [ new PrintRequest( PrintRequest::PRINT_THIS, '' ), new PrintRequest( PrintRequest::PRINT_PROP, null, $propertyValue ) ] ); $queryResult = $this->getStore()->getQueryResult( $query ); $this->queryResultValidator->assertThatQueryResultHasSubjects( $this->fixturesProvider->getFactsheet( 'Berlin' )->asSubject(), $queryResult ); } }