public function testRenderPrice() { $this->_appConfig->expects($this->once())->method('getValue')->will($this->returnValue('USD')); $currency = $this->getMock('Zend_Currency', array(), array(), '', false); $currency->expects($this->once())->method('toCurrency')->with('100.0000')->will($this->returnValue('$100.00')); $this->_locale->expects($this->once())->method('getCurrency')->with('USD')->will($this->returnValue($currency)); $this->assertEquals('$100.00', $this->_block->renderPrice(100)); }
public function testGetCurrencySymbol() { $currencySymbol = '$'; $currencyMock = $this->getMockBuilder('\\Magento\\Framework\\Currency')->disableOriginalConstructor()->getMock(); $currencyMock->expects($this->once())->method('getSymbol')->willReturn($currencySymbol); $this->localeCurrencyMock->expects($this->once())->method('getCurrency')->with($this->currencyCode)->willReturn($currencyMock); $this->assertEquals($currencySymbol, $this->currency->getCurrencySymbol()); }
/** * @dataProvider getOutputFormatDataProvider * @param $withCurrency * @param $noCurrency * @param $expected */ public function testGetOutputFormat($withCurrency, $noCurrency, $expected) { $currencyMock = $this->getMockBuilder('\\Magento\\Framework\\Currency')->disableOriginalConstructor()->getMock(); $currencyMock->expects($this->at(0))->method('toCurrency')->willReturn($withCurrency); $currencyMock->expects($this->at(1))->method('toCurrency')->willReturn($noCurrency); $this->localeCurrencyMock->expects($this->atLeastOnce())->method('getCurrency')->with($this->currencyCode)->willReturn($currencyMock); $this->assertEquals($expected, $this->currency->getOutputFormat()); }
public function testPrepareDataSource() { $fieldName = 'special_field'; $baseCurrencyCode = 'USD'; $currencySymbol = '$'; $dataSource = ['data' => ['items' => [['id' => '1', $fieldName => 3], ['id' => '2'], ['id' => '3', $fieldName => 4.55]]]]; $result = ['data' => ['items' => [['id' => '1', $fieldName => '3.00$', 'price_number' => '3.00', 'price_currency' => $currencySymbol], ['id' => '2'], ['id' => '3', $fieldName => '4.55$', 'price_number' => '4.55', 'price_currency' => $currencySymbol]]]]; $this->contextMock->expects($this->any())->method('getFilterParam')->with('store_id', Store::DEFAULT_STORE_ID)->willReturn(Store::DEFAULT_STORE_ID); $this->storeManagerMock->expects($this->any())->method('getStore')->with(Store::DEFAULT_STORE_ID)->willReturn($this->storeMock); $this->storeMock->expects($this->any())->method('getBaseCurrencyCode')->willReturn($baseCurrencyCode); $this->localeCurrencyMock->expects($this->any())->method('getCurrency')->with($baseCurrencyCode)->willReturn($this->currencyMock); $this->currencyMock->expects($this->any())->method('toCurrency')->willReturnMap([['3.000000', ['display' => false], '3.00'], ['4.550000', ['display' => false], '4.55'], ['3.000000', [], '3.00$'], ['4.550000', [], '4.55$']]); $this->storeMock->expects($this->any())->method('getBaseCurrency')->willReturn($this->currencyModelMock); $this->currencyModelMock->expects($this->any())->method('getCurrencySymbol')->willReturn($currencySymbol); $this->priceColumn->setData('name', $fieldName); $this->assertSame($result, $this->priceColumn->prepareDataSource($dataSource)); }
/** * {@inheritdoc} */ protected function createModel() { $this->currencyMock = $this->getMockBuilder(CurrencyInterface::class)->setMethods(['getCurrency', 'toCurrency'])->getMockForAbstractClass(); $this->currencyMock->expects($this->any())->method('getCurrency')->willReturn($this->currencyMock); $this->imageHelperMock = $this->getMockBuilder(ImageHelper::class)->setMethods(['init', 'getUrl'])->disableOriginalConstructor()->getMock(); $this->imageHelperMock->expects($this->any())->method('init')->willReturn($this->imageHelperMock); $this->attributeSetRepositoryMock = $this->getMockBuilder(AttributeSetRepositoryInterface::class)->setMethods(['get'])->getMockForAbstractClass(); $attributeSetMock = $this->getMockBuilder(AttributeSetInterface::class)->setMethods(['getAttributeSetName'])->getMockForAbstractClass(); $this->attributeSetRepositoryMock->expects($this->any())->method('get')->willReturn($attributeSetMock); return $this->objectManager->getObject(Grouped::class, ['locator' => $this->locatorMock, 'productLinkRepository' => $this->linkRepositoryMock, 'productRepository' => $this->productRepositoryMock, 'localeCurrency' => $this->currencyMock, 'imageHelper' => $this->imageHelperMock, 'attributeSetRepository' => $this->attributeSetRepositoryMock]); }