Exemplo n.º 1
0
 /**
  * @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());
 }
Exemplo n.º 2
0
 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());
 }
Exemplo n.º 3
0
 /**
  * Modify price precision for JPY
  *
  * @param Currency $subject          Currency Object
  * @param \Closure $proceed          Closure
  * @param float    $price            Price
  * @param int      $precision        Currency Precision
  * @param array    $options          Currency options array
  * @param bool     $includeContainer Include container flag
  * @param bool     $addBrackets      Add brackets flag
  *
  * @return mixed
  */
 public function aroundFormatPrecision(Currency $subject, \Closure $proceed, $price, $precision = 2, $options = [], $includeContainer = true, $addBrackets = false)
 {
     if ($subject->getCode() == 'JPY') {
         $precision = '0';
         if (isset($options['precision'])) {
             $options['precision'] = '0';
         }
     }
     return $proceed($price, $precision, $options, $includeContainer, $addBrackets);
 }
 /**
  * Test save action
  *
  * @magentoDbIsolation enabled
  */
 public function testSaveAction()
 {
     $currencyCode = 'USD';
     $currencyTo = 'USD';
     $rate = 1.0;
     $request = $this->getRequest();
     $request->setPostValue('rate', [$currencyCode => [$currencyTo => $rate]]);
     $this->dispatch('backend/admin/system_currency/saveRates');
     $this->assertSessionMessages($this->contains((string) __('All valid rates have been saved.')), \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS);
     $this->assertEquals($rate, $this->currencyRate->load($currencyCode)->getRate($currencyTo), 'Currency rate has not been saved');
 }
Exemplo n.º 5
0
 /**
  * @param array $attributes
  * @param array $values
  * @param string $currentCurrencyCode
  * @param string $baseCurrencyCode
  * @dataProvider addFiltersDataProvider
  */
 public function testAddFiltersVerifyAddConditionsToRegistry(array $attributes, array $values, $currentCurrencyCode = 'GBP', $baseCurrencyCode = 'USD')
 {
     $registry = new \Magento\Framework\Registry();
     $this->collection->expects($this->any())->method('addAttributeToSelect')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('setStore')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('addMinimalPrice')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('addTaxPercents')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('addStoreFilter')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('setVisibility')->will($this->returnSelf());
     $this->resource->expects($this->any())->method('prepareCondition')->will($this->returnValue(['like' => '%simple%']));
     $this->resource->expects($this->any())->method('getIdFieldName')->will($this->returnValue('entity_id'));
     $this->dataCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator($attributes)));
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $advancedFactory = $this->getMockBuilder('Magento\\CatalogSearch\\Model\\ResourceModel\\AdvancedFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $advancedFactory->expects($this->once())->method('create')->willReturn($this->resource);
     $productCollectionFactory = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Product\\CollectionFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $productCollectionFactory->expects($this->any())->method('create')->willReturn($this->collection);
     $this->store->expects($this->any())->method('getCurrentCurrencyCode')->willReturn($currentCurrencyCode);
     $this->store->expects($this->any())->method('getBaseCurrencyCode')->willReturn($baseCurrencyCode);
     $this->currency->expects($this->any())->method('getRate')->with($currentCurrencyCode)->willReturn(1.5);
     $currency = $this->getMockBuilder('Magento\\Directory\\Model\\Currency')->setMethods(['load', 'format'])->disableOriginalConstructor()->getMock();
     $currency->expects($this->any())->method('load')->willReturnSelf();
     $currency->expects($this->any())->method('format')->willReturnArgument(0);
     $currencyFactory = $this->getMockBuilder('Magento\\Directory\\Model\\CurrencyFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $currencyFactory->expects($this->any())->method('create')->willReturn($currency);
     /** @var \Magento\CatalogSearch\Model\Advanced $instance */
     $instance = $objectManager->getObject('Magento\\CatalogSearch\\Model\\Advanced', ['registry' => $registry, 'resourceProvider' => $this->resourceProvider, 'data' => ['attributes' => $this->dataCollection], 'advancedFactory' => $advancedFactory, 'productCollectionFactory' => $productCollectionFactory, 'storeManager' => $this->storeManager, 'currencyFactory' => $currencyFactory]);
     $instance->addFilters($values);
     $this->assertNotNull($registry->registry('advanced_search_conditions'));
 }
Exemplo n.º 6
0
 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));
 }
Exemplo n.º 7
0
 /**
  * Get rate for current row, 1 by default
  *
  * @param \Magento\Framework\Object $row
  * @return float|int
  */
 protected function _getRate($row)
 {
     if ($rate = $this->getColumn()->getRate()) {
         return floatval($rate);
     }
     if ($rate = $row->getData($this->getColumn()->getRateField())) {
         return floatval($rate);
     }
     return $this->_defaultBaseCurrency->getRate($this->_getCurrencyCode($row));
 }
Exemplo n.º 8
0
 /**
  * Test aroundDispatch
  */
 public function testAroundDispatch()
 {
     $this->storeManagerMock->expects($this->exactly(2))->method('getWebsite')->will($this->returnValue($this->websiteMock));
     $this->websiteMock->expects($this->exactly(2))->method('getDefaultStore')->will($this->returnValue($this->storeMock));
     $this->storeMock->expects($this->once())->method('getDefaultCurrency')->will($this->returnValue($this->currencyMock));
     $this->storeMock->expects($this->once())->method('getStoreCodeFromCookie')->will($this->returnValue('storeCookie'));
     $this->currencyMock->expects($this->once())->method('getCode')->will($this->returnValue('UAH'));
     $this->sessionMock->expects($this->once())->method('getCurrencyCode')->will($this->returnValue('UAH'));
     $this->httpRequestMock->expects($this->once())->method('getParam')->with($this->equalTo('___store'))->will($this->returnValue('default'));
     $this->httpContextMock->expects($this->atLeastOnce())->method('setValue')->will($this->returnValueMap([[\Magento\Core\Helper\Data::CONTEXT_CURRENCY, 'UAH', 'UAH', $this->httpContextMock], [\Magento\Core\Helper\Data::CONTEXT_STORE, 'default', 'default', $this->httpContextMock]]));
     $this->assertEquals('ExpectedValue', $this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock));
 }
Exemplo n.º 9
0
 /**
  * Get currency model instance. Will be used currency with which order placed
  *
  * @return Currency
  */
 public function getOrderCurrency()
 {
     if ($this->_orderCurrency === null) {
         $this->_orderCurrency = $this->_currencyFactory->create();
         $this->_orderCurrency->load($this->getOrderCurrencyCode());
     }
     return $this->_orderCurrency;
 }
Exemplo n.º 10
0
 /**
  * Get currency rate
  *
  * @param string $fromRate
  * @param string $toRate
  * @return float
  */
 protected function _getRate($fromRate, $toRate)
 {
     return $this->_currencyModel->load($fromRate)->getAnyRate($toRate);
 }
Exemplo n.º 11
0
 /**
  * @return string
  */
 public function getCurrencySymbol()
 {
     return $this->_currency->getCurrencySymbol();
 }