private function searchForResultsThatCompareEqualToOnlySingularPropertyOf(DIProperty $property)
 {
     $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);
     $query->querymode = Query::MODE_INSTANCES;
     return $this->getStore()->getQueryResult($query);
 }
 public function testSubjects_onCategoryCondition()
 {
     $property = new DIProperty('_INST');
     $dataValue = $this->dataValueFactory->newPropertyObjectValue($property, 'SomeCategory');
     $semanticData = $this->semanticDataFactory->newEmptySemanticData(__METHOD__);
     $semanticData->addDataValue($dataValue);
     $this->getStore()->updateData($semanticData);
     $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->assertThatQueryResultHasSubjects($semanticData->getSubject(), $this->searchForResultsThatCompareEqualToClassOf('SomeCategory'));
     $this->queryResultValidator->assertThatQueryResultContains($dataValue, $this->searchForResultsThatCompareEqualToClassOf('SomeCategory'));
 }
 public function testUserDefinedBlobProperty()
 {
     $property = new DIProperty('SomeBlobProperty');
     $property->setPropertyTypeId('_txt');
     $dataItem = new DIBlob('SomePropertyBlobValue');
     $semanticData = $this->semanticDataFactory->newEmptySemanticData(__METHOD__);
     $semanticData->addDataValue($this->dataValueFactory->newDataItemValue($dataItem, $property));
     $this->getStore()->updateData($semanticData);
     $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($dataItem, $queryResult);
 }
 public function testCreatePageWithSubobjectParserFunctionForQueryResultLookup()
 {
     $this->titles[] = Title::newFromText('CreatePageWithSubobjectParserFunction');
     $pageCreator = new PageCreator();
     $pageCreator->createPage(Title::newFromText('Has subobject parser function test', SMW_NS_PROPERTY))->doEdit('[[Has type::Page]]');
     $property = DIProperty::newFromUserLabel('Has subobject parser function test');
     $pageCreator->createPage($this->titles[0])->doEdit('{{#subobject:|Has subobject parser function test=WXYZ|@sortkey=B}}' . '{{#subobject:|Has subobject parser function test=ABCD|@sortkey=A}}' . '{{#subobject:|Has subobject parser function test=ABCD|@sortkey=A}}' . '{{#subobject:|Has subobject parser function test=ABCD|@sortkey=C}}');
     $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_COUNT;
     $result = $this->getStore()->getQueryResult($query);
     $this->assertEquals(3, $result instanceof \SMWQueryResult ? $result->getCountValue() : $result);
     $query->querymode = Query::MODE_INSTANCES;
     $this->assertCount(3, $this->getStore()->getQueryResult($query)->getResults());
 }
 public function testRandomOrder()
 {
     $factsheet = $this->fixturesProvider->getFactsheet('Berlin');
     $populationValue = $factsheet->getPopulationValue();
     $this->getStore()->updateData($factsheet->asEntity());
     /**
      * @query [[Population::+]]
      */
     $property = $this->fixturesProvider->getProperty('Population');
     $description = new SomeProperty($property, new ThingDescription());
     $propertyValue = new PropertyValue('__pro');
     $propertyValue->setDataItem($property);
     $description->addPrintRequest(new PrintRequest(PrintRequest::PRINT_PROP, null, $propertyValue));
     $query = new Query($description, false, false);
     $query->querymode = Query::MODE_INSTANCES;
     $query->sort = true;
     $query->sortkeys = array('Population' => 'RANDOM');
     $queryResult = $this->getStore()->getQueryResult($query);
     $this->assertEquals(3, $queryResult->getCount());
 }
 /**
  * @dataProvider specialCharactersNameProvider
  */
 public function testSpecialCharactersInQuery($subject, $subobjectId, $property, $dataItem)
 {
     $dataValue = $this->dataValueFactory->newDataItemValue($dataItem, $property);
     $semanticData = $this->semanticDataFactory->newEmptySemanticData($subject);
     $semanticData->addDataValue($dataValue);
     $subobject = new Subobject($semanticData->getSubject()->getTitle());
     $subobject->setEmptyContainerForId($subobjectId);
     $subobject->addDataValue($dataValue);
     $semanticData->addSubobject($subobject);
     $this->getStore()->updateData($semanticData);
     $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;
     $this->queryResultValidator->assertThatQueryResultHasSubjects(array($semanticData->getSubject(), $subobject->getSubject()), $this->getStore()->getQueryResult($query));
     $this->queryResultValidator->assertThatQueryResultContains($dataValue, $this->getStore()->getQueryResult($query));
     $this->subjectsToBeCleared = array($semanticData->getSubject(), $subobject->getSubject(), $property->getDIWikiPage());
 }
 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();
 }
 public function testSubpropertyToQueryFromTopHierarchy()
 {
     if (!$this->getStore() instanceof \SMWSQLStore3) {
         $this->markTestSkipped("Subproperty/property hierarchies are currently only supported by the SQLStore");
     }
     $semanticDataOfSpouse = $this->semanticDataFactory->setSubject(new DIWikiPage('Spouse', SMW_NS_PROPERTY, ''))->newEmptySemanticData();
     $property = new DIProperty('Wife');
     $property->setPropertyTypeId('_wpg');
     $this->addPropertyHierarchy($property, 'Spouse');
     $dataValue = $this->dataValueFactory->newPropertyObjectValue($property, 'Lien');
     $semanticData = $this->semanticDataFactory->newEmptySemanticData(__METHOD__);
     $semanticData->addDataValue($dataValue);
     $this->getStore()->updateData($semanticDataOfSpouse);
     $this->getStore()->updateData($semanticData);
     $description = new SomeProperty(new DIProperty('Spouse'), new ThingDescription());
     $propertyValue = new PropertyValue('__pro');
     $propertyValue->setDataItem($property);
     $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 = array($semanticData->getSubject(), $semanticDataOfSpouse->getSubject(), $property->getDiWikiPage());
 }
 public function queryProvider()
 {
     $subject = DIWikiPage::newFromText('Foo');
     #0
     $description = new SomeProperty(new DIProperty('Foobar'), new ValueDescription(DIWikiPage::newFromText('Bar')));
     $query = new Query($description);
     $query->setSubject($subject);
     $provider[] = array($query, array(DIWikiPage::newFromText('Foo'), DIWikiPage::newFromText('Bar'), DIWikiPage::newFromText('Foobar', SMW_NS_PROPERTY)));
     #1
     $description = new SomeProperty(new DIProperty('Foobar'), new ValueDescription(new DIBlob('Bar')));
     $query = new Query($description);
     $query->setSubject($subject);
     $provider[] = array($query, array(DIWikiPage::newFromText('Foo'), DIWikiPage::newFromText('Foobar', SMW_NS_PROPERTY)));
     #2 uses inverse property declaration
     $description = new SomeProperty(new DIProperty('Foobar', true), new ValueDescription(DIWikiPage::newFromText('Bar')));
     $query = new Query($description);
     $query->setSubject($subject);
     $provider[] = array($query, array(DIWikiPage::newFromText('Foo'), DIWikiPage::newFromText('Bar'), DIWikiPage::newFromText('Foobar', SMW_NS_PROPERTY)));
     #3 Conjunction
     $description = new SomeProperty(new DIProperty('Foobar'), new ValueDescription(DIWikiPage::newFromText('Bar')));
     $query = new Query(new Conjunction(array($description, new NamespaceDescription(NS_MAIN))));
     $query->setSubject($subject);
     $provider[] = array($query, array(DIWikiPage::newFromText('Foo'), DIWikiPage::newFromText('Bar'), DIWikiPage::newFromText('Foobar', SMW_NS_PROPERTY)));
     #4 Disjunction
     $description = new SomeProperty(new DIProperty('Foobar'), new ValueDescription(DIWikiPage::newFromText('Bar')));
     $query = new Query(new Disjunction(array($description, new NamespaceDescription(NS_MAIN))));
     $query->setSubject($subject);
     $provider[] = array($query, array(DIWikiPage::newFromText('Foo'), DIWikiPage::newFromText('Bar'), DIWikiPage::newFromText('Foobar', SMW_NS_PROPERTY)));
     #5
     $description = new ClassDescription(DIWikiPage::newFromText('Foocat', NS_CATEGORY));
     $query = new Query($description);
     $query->setSubject($subject);
     $provider[] = array($query, array(DIWikiPage::newFromText('Foo'), DIWikiPage::newFromText('Foocat', NS_CATEGORY)));
     #6
     $description = new ConceptDescription(DIWikiPage::newFromText('FooConcept', SMW_NS_CONCEPT));
     $query = new Query($description);
     $query->setSubject($subject);
     $provider[] = array($query, array(DIWikiPage::newFromText('Foo'), DIWikiPage::newFromText('FooConcept', SMW_NS_CONCEPT)));
     #7 Printrequest
     $pv = \SMWPropertyValue::makeUserProperty('Foobaz');
     $description = new SomeProperty(new DIProperty('Foobar', true), new ValueDescription(DIWikiPage::newFromText('Bar')));
     $description->addPrintRequest(new PrintRequest(PrintRequest::PRINT_PROP, '', $pv));
     $query = new Query($description);
     $query->setSubject($subject);
     $provider[] = array($query, array(DIWikiPage::newFromText('Foo'), DIWikiPage::newFromText('Bar'), DIWikiPage::newFromText('Foobar', SMW_NS_PROPERTY), DIWikiPage::newFromText('Foobaz', SMW_NS_PROPERTY)));
     #8 Inverse printrequest
     $pv = \SMWPropertyValue::makeUserProperty('Foobaz');
     $pv->setInverse(true);
     $description = new SomeProperty(new DIProperty('Foobar', true), new ValueDescription(DIWikiPage::newFromText('Bar')));
     $description->addPrintRequest(new PrintRequest(PrintRequest::PRINT_PROP, '', $pv));
     $query = new Query($description);
     $query->setSubject($subject);
     $provider[] = array($query, array(DIWikiPage::newFromText('Foo'), DIWikiPage::newFromText('Bar'), DIWikiPage::newFromText('Foobar', SMW_NS_PROPERTY), DIWikiPage::newFromText('Foobaz', SMW_NS_PROPERTY)));
     return $provider;
 }
 public function testUserDefinedTemperatureProperty()
 {
     $semanticData = $this->semanticDataFactory->newEmptySemanticData(__METHOD__);
     $this->subjects[] = $semanticData->getSubject();
     $factsheet = $this->fixturesProvider->getFactsheet('Berlin');
     $factsheet->setTargetSubject($semanticData->getSubject());
     $temperatureValue = $factsheet->getAverageHighTemperatureValue();
     $temperatureProperty = $temperatureValue->getProperty();
     $semanticData->addDataValue($temperatureValue);
     $this->getStore()->updateData($semanticData);
     $this->assertArrayHasKey($temperatureProperty->getKey(), $this->getStore()->getSemanticData($semanticData->getSubject())->getProperties());
     /**
      * @query [[Temperature::+]]|?Temperature
      */
     $description = new SomeProperty($temperatureProperty, new ThingDescription());
     $description->addPrintRequest($this->printRequestFactory->newPropertyPrintRequest($temperatureProperty));
     $query = new Query($description, false, false);
     $query->querymode = Query::MODE_INSTANCES;
     $queryResult = $this->getStore()->getQueryResult($query);
     $this->queryResultValidator->assertThatQueryResultContains($temperatureValue, $queryResult);
 }
 /**
  * {{#ask: [[SomeNumericPropertyToDifferentSubject::9999]]
  *  |?SomeNumericPropertyToDifferentSubject
  * }}
  */
 public function testQueryToCompareEqualNumericPropertyValuesAssignedToDifferentSubject()
 {
     $semanticDataWithSubobject = $this->semanticDataFactory->setTitle(__METHOD__ . '-withSobj')->newEmptySemanticData();
     $semanticDataWithoutSubobject = $this->semanticDataFactory->setTitle(__METHOD__ . '-wwithoutSobj')->newEmptySemanticData();
     $expectedDataValueToMatchCondition = $this->newDataValueForNumericPropertyValue('SomeNumericPropertyToDifferentSubject', 9999);
     $dataValueWithSamePropertyButDifferentValue = $this->newDataValueForNumericPropertyValue('SomeNumericPropertyToDifferentSubject', 1111);
     $subobject = new Subobject($semanticDataWithSubobject->getSubject()->getTitle());
     $subobject->setEmptyContainerForId('SomeSubobjectToDifferentSubject');
     $subobject->addDataValue($expectedDataValueToMatchCondition);
     $semanticDataWithSubobject->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer());
     $semanticDataWithSubobject->addDataValue($dataValueWithSamePropertyButDifferentValue);
     $semanticDataWithoutSubobject->addDataValue($expectedDataValueToMatchCondition);
     $this->getStore()->updateData($semanticDataWithSubobject);
     $this->getStore()->updateData($semanticDataWithoutSubobject);
     $property = new DIProperty('SomeNumericPropertyToDifferentSubject');
     $property->setPropertyTypeId('_num');
     $dataItem = new DINumber(9999);
     $description = new SomeProperty($property, new ValueDescription($dataItem, null, SMW_CMP_EQ));
     $propertyValue = new PropertyValue('__pro');
     $propertyValue->setDataItem($property);
     $description->addPrintRequest(new PrintRequest(PrintRequest::PRINT_PROP, null, $propertyValue));
     $query = new Query($description, false, false);
     $queryResult = $this->getStore()->getQueryResult($query);
     $this->assertEquals(2, $queryResult->getCount());
     $this->queryResultValidator->assertThatQueryResultContains($expectedDataValueToMatchCondition, $queryResult);
     $expectedSubjects = array($subobject->getSemanticData()->getSubject(), $semanticDataWithoutSubobject->getSubject());
     $this->queryResultValidator->assertThatQueryResultHasSubjects($expectedSubjects, $queryResult);
     $this->subjectsToBeCleared = array($semanticDataWithoutSubobject->getSubject(), $semanticDataWithSubobject->getSubject());
 }
 public function createQueryForSamplePagesThatContain($property, array &$expectedSubjects)
 {
     foreach ($expectedSubjects as $key => $expectedSubject) {
         $subjectTitle = $expectedSubject->getTitle()->getText() . '-' . __METHOD__;
         $semanticData = $this->semanticDataFactory->newEmptySemanticData($subjectTitle);
         $semanticData->addPropertyObjectValue($property, $expectedSubject);
         $this->subjectsToBeCleared[] = $semanticData->getSubject();
         $expectedSubjects[$key] = $semanticData->getSubject();
         $this->getStore()->updateData($semanticData);
     }
     $description = new SomeProperty($property, new ThingDescription());
     $propertyValue = new PropertyValue('__pro');
     $propertyValue->setDataItem($property);
     $description->addPrintRequest(new PrintRequest(PrintRequest::PRINT_PROP, null, $propertyValue));
     $query = new Query($description, false, false);
     $query->querymode = Query::MODE_INSTANCES;
     return $query;
 }