public function semanticDataProvider()
 {
     // Is a dataprovider therefore can't use the setUp
     $this->semanticDataFactory = UtilityFactory::getInstance()->newSemanticDataFactory();
     $this->dataValueFactory = DataValueFactory::getInstance();
     $title = Title::newFromText('Foo');
     #0 Empty container
     $foo = $this->semanticDataFactory->setSubject(DIWikiPage::newFromTitle($title))->newEmptySemanticData();
     $provider[] = array($foo);
     #1 Single entry
     $foo = $this->semanticDataFactory->setSubject(DIWikiPage::newFromTitle($title))->newEmptySemanticData();
     $foo->addDataValue($this->dataValueFactory->newPropertyValue('Has fooQuex', 'Bar'));
     $provider[] = array($foo);
     // #2 Single + single subobject entry
     $foo = $this->semanticDataFactory->setSubject(DIWikiPage::newFromTitle($title))->newEmptySemanticData();
     $foo->addDataValue($this->dataValueFactory->newPropertyValue('Has fooQuex', 'Bar'));
     $subobject = new Subobject($title);
     $subobject->setSemanticData('Foo');
     $subobject->addDataValue($this->dataValueFactory->newPropertyValue('Has subobjects', 'Bam'));
     $foo->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer());
     $provider[] = array($foo);
     #3 Multiple entries
     $foo = $this->semanticDataFactory->setSubject(DIWikiPage::newFromTitle($title))->newEmptySemanticData();
     $foo->addDataValue($this->dataValueFactory->newPropertyValue('Has fooQuex', 'Bar'));
     $foo->addDataValue($this->dataValueFactory->newPropertyValue('Has queez', 'Xeey'));
     $subobject = new Subobject($title);
     $subobject->setSemanticData('Foo');
     $subobject->addDataValue($this->dataValueFactory->newPropertyValue('Has subobjects', 'Bam'));
     $subobject->addDataValue($this->dataValueFactory->newPropertyValue('Has fooQuex', 'Fuz'));
     $subobject->setSemanticData('Bar');
     $subobject->addDataValue($this->dataValueFactory->newPropertyValue('Has fooQuex', 'Fuz'));
     $foo->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer());
     $provider[] = array($foo);
     return $provider;
 }
 protected function processExifData($rawExif)
 {
     $this->subobject = new Subobject($this->getSemanticData()->getSubject()->getTitle());
     $this->subobject->setSemanticData('_EXIFDATA');
     $this->addPropertyValuesFromExifData($rawExif);
     if ($this->subobject->getSemanticData()->isEmpty()) {
         return true;
     }
     $this->getSemanticData()->addPropertyObjectValue(new DIProperty(PropertyRegistry::getInstance()->getPropertyId('_EXIFDATA')), $this->subobject->getContainer());
     return true;
 }
 public function testResultDataFoSubobjectExtendedSemanticData()
 {
     $semanticData = $this->semanticDataFactory->newEmptySemanticData(__METHOD__);
     $semanticData->addDataValue($this->dataValueFactory->newPropertyValue(__METHOD__, 'Bar'));
     $subobject = new Subobject($semanticData->getSubject()->getTitle());
     $subobject->setEmptyContainerForId('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->getDeserializerFor($resultData['query'])->deserialize($resultData['query']));
     $this->assertInternalType('array', $this->newBrowseBySubject(__METHOD__, true)->getResultData());
 }
 public function testNoDeleteTaskForSubobjectsDuringUpdate()
 {
     $expectedSubjectForDeleteTask = DIWikiPage::newFromTitle(Title::newFromText(__METHOD__));
     $subobject = new Subobject($expectedSubjectForDeleteTask->getTitle());
     $subobject->setEmptyContainerForId('Foo');
     $semanticData = $this->semanticDataFactory->setSubject($expectedSubjectForDeleteTask)->newEmptySemanticData();
     $semanticData->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer());
     $repositoryResult = $this->getMockBuilder('\\SMW\\SPARQLStore\\QueryEngine\\RepositoryResult')->disableOriginalConstructor()->getMock();
     $connection = $this->getMockBuilder('\\SMW\\SPARQLStore\\RepositoryConnectors\\GenericHttpRepositoryConnector')->disableOriginalConstructor()->getMock();
     $connection->expects($this->atLeastOnce())->method('select')->will($this->returnValue($repositoryResult));
     $connection->expects($this->atLeastOnce())->method('insertData');
     $instance = $this->getMockBuilder('\\SMW\\SPARQLStore\\SPARQLStore')->disableOriginalConstructor()->setMethods(array('doSparqlDataDelete', 'getConnection'))->getMock();
     $instance->expects($this->once())->method('doSparqlDataDelete')->with($this->equalTo($expectedSubjectForDeleteTask));
     $instance->expects($this->atLeastOnce())->method('getConnection')->will($this->returnValue($connection));
     $instance->doSparqlDataUpdate($semanticData);
 }
Example #5
0
 /**
  * @since 2.1
  *
  * @param Subobject $subobject
  */
 public function addSubobject(Subobject $subobject)
 {
     $this->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer());
 }
 /**
  * {{#ask: [[LocatedIn.Has subobject.MemberOf::+]] }}
  */
 public function testSubqueryForCombinedSubobjectPropertyChainForWilcardSearch()
 {
     /**
      * Page ...-dreamland annotated with [[LocatedIn::BananaWonderland]]
      */
     $semanticDataOfDreamland = $this->semanticDataFactory->setTitle(__METHOD__ . '-dreamland')->newEmptySemanticData();
     $semanticDataOfDreamland->addDataValue($this->newDataValueForPagePropertyValue('LocatedIn', 'BananaWonderland'));
     /**
      * Page ...-fairyland annotated with [[LocatedIn::BananaWonderland]]
      */
     $semanticDataOfFairyland = $this->semanticDataFactory->setTitle(__METHOD__ . '-fairyland')->newEmptySemanticData();
     $semanticDataOfFairyland->addDataValue($this->newDataValueForPagePropertyValue('LocatedIn', 'BananaWonderland'));
     /**
      * Page BananaWonderland annotated with [[Has subobject.MemberOf::Wonderland]]
      */
     $semanticDataOfWonderland = $this->semanticDataFactory->setTitle('BananaWonderland')->newEmptySemanticData();
     $subobject = new Subobject($semanticDataOfWonderland->getSubject()->getTitle());
     $subobject->setEmptyContainerForId('SomeSubobjectOnWonderland');
     $subobject->addDataValue($this->newDataValueForPagePropertyValue('MemberOf', 'Wonderland'));
     $semanticDataOfWonderland->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer());
     $this->getStore()->updateData($semanticDataOfDreamland);
     $this->getStore()->updateData($semanticDataOfFairyland);
     $this->getStore()->updateData($semanticDataOfWonderland);
     $description = new SomeProperty(DIProperty::newFromUserLabel('LocatedIn')->setPropertyTypeId('_wpg'), new SomeProperty(DIProperty::newFromUserLabel('_SOBJ')->setPropertyTypeId('__sob'), new SomeProperty(DIProperty::newFromUserLabel('MemberOf')->setPropertyTypeId('_wpg'), new ThingDescription())));
     $this->assertEquals($description, $this->queryParser->getQueryDescription('[[LocatedIn.Has subobject.MemberOf::+]]'));
     $query = new Query($description, false, false);
     $query->querymode = Query::MODE_INSTANCES;
     $queryResult = $this->getStore()->getQueryResult($query);
     $expectedSubjects = array($semanticDataOfDreamland->getSubject(), $semanticDataOfFairyland->getSubject());
     $this->assertEquals(2, $queryResult->getCount());
     $this->queryResultValidator->assertThatQueryResultHasSubjects($expectedSubjects, $queryResult);
     $this->subjectsToBeCleared = array($semanticDataOfWonderland->getSubject(), $semanticDataOfDreamland->getSubject(), $semanticDataOfFairyland->getSubject());
 }
 /**
  * @return array
  */
 public function typeChangeSemanticDataProvider()
 {
     $provider = array();
     $title = \Title::newFromText(__METHOD__);
     // #0 Single entry
     $foo = new SemanticData(DIWikiPage::newFromTitle($title));
     $foo->addDataValue(DataValueFactory::getInstance()->newPropertyValue('Has fooQuex', 'Bar'));
     $provider[] = array($foo, 'Has_fooQuex');
     // #1 Single subobject entry
     $foo = new SemanticData(DIWikiPage::newFromTitle($title));
     $subobject = new Subobject($title);
     $subobject->setSemanticData('Foo');
     $subobject->addDataValue(DataValueFactory::getInstance()->newPropertyValue('Has fomQuex', 'Bam'));
     $foo->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer());
     $provider[] = array($foo, 'Has_fomQuex');
     // #2 Combined
     $foo = new SemanticData(DIWikiPage::newFromTitle($title));
     $foo->addDataValue(DataValueFactory::getInstance()->newPropertyValue('Has fooQuex', 'Bar'));
     $foo->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer());
     $provider[] = array($foo, 'Has_fomQuex');
     return $provider;
 }
 public function testExportSubobject()
 {
     $semanticData = $this->semanticDataFactory->newEmptySemanticData(__METHOD__);
     $subobject = new Subobject($semanticData->getSubject()->getTitle());
     $subobject->setEmptyContainerForId('Foo');
     $semanticData->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer());
     $exportData = Exporter::getInstance()->makeExportData($semanticData);
     $expectedProperty = new ExpNsResource($this->transformPropertyLabelToAuxiliary($subobject->getProperty()), Exporter::getInstance()->getNamespaceUri('property'), 'property', new DIWikiPage('Has_subobject', SMW_NS_PROPERTY));
     $this->assertTrue(Exporter::getInstance()->hasHelperExpElement($subobject->getProperty()));
     $this->assertCount(1, $exportData->getValues($expectedProperty));
     $this->exportDataValidator->assertThatExportDataContainsProperty($expectedProperty, $exportData);
     $expectedResource = new ExpNsResource(Escaper::encodePage($subobject->getSemanticData()->getSubject()) . '-23' . 'Foo', Exporter::getInstance()->getNamespaceUri('wiki'), 'wiki', $subobject->getSemanticData()->getSubject());
     $this->exportDataValidator->assertThatExportDataContainsResource($expectedResource, $expectedProperty, $exportData);
 }
 public function testAddSubobjectToSemanticDataForStorage()
 {
     $this->subjects[] = $subject = DIWikiPage::newFromTitle(Title::newFromText(__METHOD__));
     $semanticData = new SemanticData($subject);
     $subobject = new Subobject($subject->getTitle());
     $subobject->setEmptyContainerForId('SomeSubobject');
     $subobject->getSemanticData()->addDataValue(DataValueFactory::getInstance()->newPropertyValue('Foo', 'Bar'));
     $semanticData->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer());
     $this->getStore()->updateData($semanticData);
     $expected = array('propertyCount' => 2, 'properties' => array(new DIProperty('Foo'), new DIProperty('_SKEY')), 'propertyValues' => array('Bar', __METHOD__));
     $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $this->getStore()->getSemanticData($subject)->findSubSemanticData('SomeSubobject'));
 }
 public function testQuerySubobjects_afterUpdatingWithEmptyContainerAllAssociatedEntitiesGetRemovedFromGraph()
 {
     $semanticData = $this->semanticDataFactory->newEmptySemanticData(__METHOD__);
     $subobject = new Subobject($semanticData->getSubject()->getTitle());
     $subobject->setEmptyContainerForId('SubobjectToTestReferenceAfterUpdate');
     $property = new DIProperty('SomeNumericPropertyToCompareReference');
     $property->setPropertyTypeId('_num');
     $dataItem = new DINumber(99999);
     $subobject->addDataValue($this->dataValueFactory->newDataItemValue($dataItem, $property));
     $semanticData->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer());
     $this->store->doSparqlDataUpdate($semanticData);
     $description = new SomeProperty($property, new ValueDescription($dataItem, null, SMW_CMP_EQ));
     $query = new Query($description, false, false);
     $query->querymode = Query::MODE_INSTANCES;
     $this->assertSame(1, $this->store->getQueryResult($query)->getCount());
     $this->queryResultValidator->assertThatQueryResultHasSubjects($subobject->getSemanticData()->getSubject(), $this->store->getQueryResult($query));
     $this->store->doSparqlDataUpdate($this->semanticDataFactory->newEmptySemanticData(__METHOD__));
     $this->assertSame(0, $this->store->getQueryResult($query)->getCount());
 }
Example #11
0
 /**
  * ProfileAnnotator::getContainer
  *
  * @since 1.9
  *
  * @return SemanticData
  */
 public function getContainer()
 {
     return $this->subobject->getContainer();
 }
 /**
  * {{#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());
 }