示例#1
0
 public function testConstruct()
 {
     $frontendCache = $this->getMock('Magento\\Framework\\Cache\\FrontendInterface', [], [], '', false, false);
     $lowLevelFrontend = $this->getMock('Zend_Cache_Core', [], [], '', false, false);
     /** @var \Magento\Framework\App\CacheInterface|\PHPUnit_Framework_MockObject_MockObject $appCache */
     $appCache = $this->getMock('Magento\\Framework\\App\\CacheInterface', [], [], '', false, false);
     $frontendCache->expects($this->once())->method('getLowLevelFrontend')->willReturn($lowLevelFrontend);
     $appCache->expects($this->once())->method('getFrontend')->willReturn($frontendCache);
     // Create new currency object
     $currency = new Currency($appCache, null, 'en_US');
     $this->assertEquals($lowLevelFrontend, $currency->getCache());
     $this->assertEquals('USD', $currency->getShortName());
 }
示例#2
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));
 }
示例#3
0
 public function testModifyData()
 {
     $sourceData = ['1' => ['product' => [ProductAttributeInterface::CODE_PRICE => '19.99']]];
     $this->locatorMock->expects($this->any())->method('getProduct')->willReturn($this->productMock);
     $this->productMock->expects($this->any())->method('getId')->willReturn(1);
     $this->productMock->expects($this->once())->method('getAttributeSetId')->willReturn(4);
     $this->productMock->expects($this->once())->method('getData')->with(ProductAttributeInterface::CODE_PRICE)->willReturn('19.9900');
     $this->searchCriteriaBuilderMock->expects($this->any())->method('addFilter')->willReturnSelf();
     $this->searchCriteriaBuilderMock->expects($this->any())->method('create')->willReturn($this->searchCriteriaMock);
     $this->attributeGroupRepositoryMock->expects($this->any())->method('getList')->willReturn($this->searchCriteriaMock);
     $this->searchCriteriaMock->expects($this->once())->method('getItems')->willReturn([$this->attributeGroupMock]);
     $this->sortOrderBuilderMock->expects($this->once())->method('setField')->willReturnSelf();
     $this->sortOrderBuilderMock->expects($this->once())->method('setAscendingDirection')->willReturnSelf();
     $dataObjectMock = $this->getMock('\\Magento\\Framework\\Api\\AbstractSimpleObject', [], [], '', false);
     $this->sortOrderBuilderMock->expects($this->once())->method('create')->willReturn($dataObjectMock);
     $this->searchCriteriaBuilderMock->expects($this->any())->method('addFilter')->willReturnSelf();
     $this->searchCriteriaBuilderMock->expects($this->once())->method('addSortOrder')->willReturnSelf();
     $this->searchCriteriaBuilderMock->expects($this->any())->method('create')->willReturn($this->searchCriteriaMock);
     $this->attributeRepositoryMock->expects($this->once())->method('getList')->with($this->searchCriteriaMock)->willReturn($this->searchResultsMock);
     $this->eavAttributeMock->expects($this->any())->method('getAttributeGroupCode')->willReturn('product-details');
     $this->eavAttributeMock->expects($this->once())->method('getApplyTo')->willReturn([]);
     $this->eavAttributeMock->expects($this->once())->method('getFrontendInput')->willReturn('price');
     $this->eavAttributeMock->expects($this->any())->method('getAttributeCode')->willReturn(ProductAttributeInterface::CODE_PRICE);
     $this->searchResultsMock->expects($this->once())->method('getItems')->willReturn([$this->eavAttributeMock]);
     $this->storeMock->expects($this->once())->method('getBaseCurrencyCode')->willReturn('en_US');
     $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock);
     $this->currencyMock->expects($this->once())->method('toCurrency')->willReturn('19.99');
     $this->currencyLocaleMock->expects($this->once())->method('getCurrency')->willReturn($this->currencyMock);
     $this->assertEquals($sourceData, $this->eav->modifyData([]));
 }