public function testFetchCachedConversionData()
 {
     $container = $this->getMockBuilder('\\Onoi\\BlobStore\\Container')->disableOriginalConstructor()->getMock();
     $container->expects($this->any())->method('has')->will($this->onConsecutiveCalls(false, true));
     $blobStore = $this->getMockBuilder('\\Onoi\\BlobStore\\BlobStore')->disableOriginalConstructor()->getMock();
     $blobStore->expects($this->exactly(2))->method('read')->will($this->returnValue($container));
     $blobStore->expects($this->once())->method('save');
     $cachedPropertyValuesPrefetcher = $this->getMockBuilder('\\SMW\\CachedPropertyValuesPrefetcher')->disableOriginalConstructor()->getMock();
     $cachedPropertyValuesPrefetcher->expects($this->atLeastOnce())->method('getBlobStore')->will($this->returnValue($blobStore));
     $cachedPropertyValuesPrefetcher->expects($this->once())->method('getPropertyValues')->will($this->returnValue(array($this->dataItemFactory->newDIBlob('Foo'))));
     $numberValue = new NumberValue();
     $instance = new UnitConversionFetcher($numberValue, $cachedPropertyValuesPrefetcher);
     $property = $this->dataItemFactory->newDIProperty('Foo');
     $instance->fetchCachedConversionData($property);
     // Cached
     $instance->fetchCachedConversionData($property);
 }
Ejemplo n.º 2
0
 /**
  * This method initializes $m_unitfactors, $m_unitids, and $m_mainunit.
  */
 protected function initConversionData()
 {
     if ($this->m_unitids !== false) {
         return;
         // do the below only once
     }
     $unitConversionFetcher = new UnitConversionFetcher($this);
     $unitConversionFetcher->fetchCachedConversionData($this->m_property);
     if ($unitConversionFetcher->getErrors() !== array()) {
         foreach ($unitConversionFetcher->getErrors() as $error) {
             $this->addErrorMsg($error, Message::TEXT, Message::USER_LANGUAGE);
         }
     }
     $this->m_unitids = $unitConversionFetcher->getUnitIds();
     $this->m_unitfactors = $unitConversionFetcher->getUnitFactors();
     $this->m_mainunit = $unitConversionFetcher->getMainUnit();
     $this->prefixalUnitPreference = $unitConversionFetcher->getPrefixalUnitPreference();
 }