/** * @dataProvider conversionDataProvider */ public function testFetchConversionData($thousands, $decimal, $correspondsTo, $unitIds, $unitFactors, $mainUnit, $prefixalUnitPreference) { $cachedPropertyValuesPrefetcher = $this->getMockBuilder('\\SMW\\CachedPropertyValuesPrefetcher')->disableOriginalConstructor()->getMock(); $cachedPropertyValuesPrefetcher->expects($this->once())->method('getPropertyValues')->will($this->returnValue(array($this->dataItemFactory->newDIBlob($correspondsTo)))); $numberValue = new NumberValue(); $numberValue->setOption('separator.thousands', $thousands); $numberValue->setOption('separator.decimal', $decimal); $instance = new UnitConversionFetcher($numberValue, $cachedPropertyValuesPrefetcher); $instance->fetchConversionData($this->dataItemFactory->newDIProperty('Foo')); $this->assertEmpty($instance->getErrors()); $this->assertEquals($unitIds, $instance->getUnitIds()); $this->assertEquals($unitFactors, $instance->getUnitFactors()); $this->assertEquals($mainUnit, $instance->getMainUnit()); $this->assertEquals($prefixalUnitPreference, $instance->getPrefixalUnitPreference()); }
/** * 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(); }