public function getDataTypeForPropertyProvider()
 {
     $argLists = array();
     $emptyInfoStore = new MockPropertyInfoStore();
     $mockInfoStore = new MockPropertyInfoStore();
     $entityLookup = new MockRepository();
     $propertyDataTypeLookup = new EntityRetrievingDataTypeLookup($entityLookup);
     foreach ($this->propertiesAndTypes as $propertyId => $dataTypeId) {
         $id = new PropertyId($propertyId);
         // register property info
         $mockInfoStore->setPropertyInfo($id, array(PropertyInfoStore::KEY_DATA_TYPE => $dataTypeId));
         // register property as an entity, for the fallback
         $property = Property::newFromType($dataTypeId);
         $property->setId($id);
         $entityLookup->putEntity($property);
         // try with a working info store
         $argLists[] = array($mockInfoStore, null, $id, $dataTypeId);
         // try with via fallback
         $argLists[] = array($emptyInfoStore, $propertyDataTypeLookup, $id, $dataTypeId);
     }
     // try unknown property
     $id = new PropertyId('P23');
     // try with a working info store
     $argLists[] = array($mockInfoStore, null, $id, false);
     // try with via fallback
     $argLists[] = array($emptyInfoStore, $propertyDataTypeLookup, $id, false);
     return $argLists;
 }
 private function getPropertyInfoStore()
 {
     $propertyInfoStore = new MockPropertyInfoStore();
     $propertyInfoStore->setPropertyInfo(new PropertyId('P789'), array(PropertyInfoStore::KEY_DATA_TYPE => 'string'));
     $propertyInfoStore->setPropertyInfo(new PropertyId('P456'), array(PropertyInfoStore::KEY_DATA_TYPE => 'wikibase-item'));
     $propertyInfoStore->setPropertyInfo(new PropertyId('P123'), array(PropertyInfoStore::KEY_DATA_TYPE => 'wikibase-item'));
     return $propertyInfoStore;
 }
 public function provideExpandUrl()
 {
     $p66 = new PropertyId('P66');
     $p2 = new PropertyId('P2');
     $p3 = new PropertyId('P3');
     $infoStore = new MockPropertyInfoStore();
     $infoStore->setPropertyInfo($p2, array(PropertyInfoStore::KEY_DATA_TYPE => 'string'));
     $infoStore->setPropertyInfo($p3, array(PropertyInfoStore::KEY_DATA_TYPE => 'string', PropertyInfoStore::KEY_FORMATTER_URL => 'http://acme.info/foo/$1'));
     $infoProvider = new FieldPropertyInfoProvider($infoStore, PropertyInfoStore::KEY_FORMATTER_URL);
     $value = new StringValue('X&Y');
     return array('unknown property' => array($infoProvider, new PropertyValueSnak($p66, $value), null), 'no url pattern' => array($infoProvider, new PropertyValueSnak($p2, $value), null), 'url pattern defined' => array($infoProvider, new PropertyValueSnak($p3, $value), 'http://acme.info/foo/X%26Y'));
 }
 /**
  * @return WikibaseSnakFormatterBuilders
  */
 private function getWikibaseSnakFormatterBuilders()
 {
     $p1 = new PropertyId('P1');
     $valueFormatterBuilders = $this->getMockBuilder('Wikibase\\Lib\\WikibaseValueFormatterBuilders')->disableOriginalConstructor()->getMock();
     $valueFormatterBuilders->expects($this->any())->method('newStringFormatter')->will($this->returnValue(new StringFormatter()));
     $propertyInfoStore = new MockPropertyInfoStore();
     $propertyInfoStore->setPropertyInfo($p1, array(PropertyInfoStore::KEY_DATA_TYPE => 'external-id', PropertyInfoStore::KEY_FORMATTER_URL => 'http://acme.com/vocab/$1'));
     $dataTypeLookup = new InMemoryDataTypeLookup();
     $dataTypeLookup->setDataTypeForProperty($p1, 'external-id');
     $dataTypeFactory = new DataTypeFactory(array('external-id' => 'string'));
     return new WikibaseSnakFormatterBuilders($valueFormatterBuilders, $propertyInfoStore, $dataTypeLookup, $dataTypeFactory);
 }
 public function testPropertyInfoWriteThrough()
 {
     $p23 = new PropertyId('P23');
     $p42 = new PropertyId('P42');
     $info23 = array(PropertyInfoStore::KEY_DATA_TYPE => 'string');
     $info42 = array(PropertyInfoStore::KEY_DATA_TYPE => 'string', 'foo' => 'bar');
     $mock = new MockPropertyInfoStore();
     $cache = new HashBagOStuff();
     $mock->setPropertyInfo($p23, $info23);
     $store = new CachingPropertyInfoStore($mock, $cache);
     $this->assertEquals($info23, $store->getPropertyInfo($p23), "get from source");
     $this->assertEquals($info23, $store->getPropertyInfo($p23), "get cached");
     $store->setPropertyInfo($p42, $info42);
     $this->assertEquals($info42, $store->getPropertyInfo($p42), "cache updated");
     $this->assertEquals($info42, $mock->getPropertyInfo($p42), "source updated");
 }