public function testRedirectTragetLookupForExistingEntry()
 {
     $property = new DIProperty('RedirectLookupForExistingEntry');
     $semanticData = new SemanticData(new DIWikiPage(__METHOD__, NS_MAIN, ''));
     $semanticData->addDataValue(DataValueFactory::getInstance()->newPropertyObjectValue($property, 'Bar'));
     $this->store->doSparqlDataUpdate($semanticData);
     $expNsResource = new ExpNsResource('RedirectLookupForExistingEntry', Exporter::getNamespaceUri('property'), 'property');
     $instance = new RedirectLookup($this->sparqlDatabase);
     $instance->clear();
     $exists = null;
     $this->assertSame($expNsResource, $instance->findRedirectTargetResource($expNsResource, $exists));
     $this->assertTrue($exists);
 }
 /**
  * Find a normalized representation of the given SMWExpResource that can
  * be used in an update of the stored data. Normalization uses
  * redirects. The type of the ExpElement might change, especially into
  * SMWExpData in order to store auxiliary properties.
  * Moreover, the method records any auxiliary data that should be
  * written to the store when including this SMWExpElement into updates.
  * This auxiliary data is collected in a call-by-ref array.
  *
  * @since 1.6
  *
  * @param ExpResource $expResource object containing the update data
  * @param $auxiliaryExpData array of SMWExpData
  *
  * @return ExpElement
  */
 private function expandUpdateExpResource(ExpResource $expResource, array &$auxiliaryExpData)
 {
     $exists = true;
     if ($expResource instanceof ExpNsResource) {
         $elementTarget = $this->redirectLookup->findRedirectTargetResource($expResource, $exists);
     } else {
         $elementTarget = $expResource;
     }
     if (!$exists && $elementTarget->getDataItem() instanceof DIWikiPage) {
         $diWikiPage = $elementTarget->getDataItem();
         $hash = $diWikiPage->getHash();
         if (!isset(self::$dataItemExportCache[$hash])) {
             self::$dataItemExportCache[$hash] = Exporter::getInstance()->makeExportDataForSubject($diWikiPage, true);
         }
         $auxiliaryExpData[$hash] = self::$dataItemExportCache[$hash];
     }
     return $elementTarget;
 }
 /**
  * @dataProvider nonRedirectableResourceProvider
  */
 public function testRedirectTargetForNonRedirectableResource($expNsResource)
 {
     $repositoryConnection = $this->getMockBuilder('\\SMW\\SPARQLStore\\RepositoryConnection')->disableOriginalConstructor()->getMock();
     $instance = new RedirectLookup($repositoryConnection);
     $instance->reset();
     $exists = null;
     $instance->findRedirectTargetResource($expNsResource, $exists);
     $instance->reset();
     $this->assertFalse($exists);
 }
 /**
  * @dataProvider nonRedirectableResourceProvider
  */
 public function testRedirectTargetForNonRedirectableResource($expNsResource)
 {
     $cache = $this->getMockBuilder('\\Onoi\\Cache\\Cache')->disableOriginalConstructor()->getMock();
     $cache->expects($this->never())->method('contains');
     $connection = $this->getMockBuilder('\\SMWSparqlDatabase')->disableOriginalConstructor()->getMock();
     $instance = new RedirectLookup($connection, $cache);
     $exists = null;
     $instance->findRedirectTargetResource($expNsResource, $exists);
     $this->assertFalse($exists);
     $instance->clear();
 }