public function testAddResourceValueOnDefaultResourceBuilderWhenOthersCannotMatch()
 {
     $expData = $this->getMockBuilder('\\SMWExpData')->disableOriginalConstructor()->getMock();
     $property = $this->dataItemFactory->newDIProperty('Foo');
     $dataItem = $this->dataItemFactory->newDIBlob('Bar');
     $resourceBuilder = $this->getMockBuilder(ResourceBuilder::class)->disableOriginalConstructor()->getMock();
     $resourceBuilder->expects($this->once())->method('isResourceBuilderFor')->will($this->returnValue(false));
     $defaultResourceBuilder = $this->getMockBuilder(ResourceBuilder::class)->disableOriginalConstructor()->getMock();
     $defaultResourceBuilder->expects($this->once())->method('addResourceValue');
     $instance = new DispatchingResourceBuilder();
     $instance->addResourceBuilder($resourceBuilder);
     $instance->addDefaultResourceBuilder($defaultResourceBuilder);
     $instance->addResourceValue($expData, $property, $dataItem);
 }
Exemplo n.º 2
0
 /**
  * Extend a given SMWExpData element by adding export data for the
  * specified property data itme. This method is called when
  * constructing export data structures from SMWSemanticData objects.
  *
  * @param $property SMWDIProperty
  * @param $dataItems array of SMWDataItem objects for the given property
  * @param $data SMWExpData to add the data to
  */
 public static function addPropertyValues(SMWDIProperty $property, array $dataItems, SMWExpData &$expData)
 {
     $resourceBuilder = self::$dispatchingResourceBuilder->findResourceBuilder($property);
     if ($property->isUserDefined()) {
         foreach ($dataItems as $dataItem) {
             $resourceBuilder->addResourceValue($expData, $property, $dataItem);
         }
     } else {
         // pre-defined property, only exported if known
         $diSubject = $expData->getSubject()->getDataItem();
         // subject wikipage required for disambiguating special properties:
         if (is_null($diSubject) || $diSubject->getDIType() != SMWDataItem::TYPE_WIKIPAGE) {
             return;
         }
         $pe = self::getSpecialPropertyResource($property->getKey(), $diSubject->getNamespace());
         if (is_null($pe)) {
             return;
             // unknown special property, not exported
         }
         // have helper property ready before entering the for loop, even if not needed:
         $peHelper = self::getResourceElementForProperty($property, true);
         $filterNamespace = $property->getKey() == '_REDI' || $property->getKey() == '_URI';
         foreach ($dataItems as $dataItem) {
             // Basic namespace filtering to ensure that types match for redirects etc.
             /// TODO: currently no full check for avoiding OWL DL illegal redirects is done (OWL property type ignored)
             if ($filterNamespace && !$dataItem instanceof SMWDIUri && !$dataItem instanceof SMWDIWikiPage) {
                 continue;
             }
             $resourceBuilder->addResourceValue($expData, $property, $dataItem);
         }
     }
 }