public function testGetLocale() { $expected = 'locale'; $this->locale->expects($this->once())->method('getLocaleCode')->will($this->returnValue($expected)); $actual = $this->model->getLocale(); $this->assertSame($expected, $actual); }
/** * @param string $locale */ private function mockGridDateRendererBehaviorWithLocale($locale) { $this->resolverMock->expects($this->any())->method('getLocale')->willReturn($locale); $this->localeDate->expects($this->any())->method('getDateFormat')->willReturnCallback(function ($value) use($locale) { return (new \IntlDateFormatter($locale, $value, \IntlDateFormatter::NONE))->getPattern(); }); }
/** * Set up aggregate * * @return \DateTime */ protected function setupAggregate() { $this->localeResolverMock->expects($this->once())->method('emulate')->with(0); $this->localeResolverMock->expects($this->once())->method('revert'); $date = (new \DateTime())->sub(new \DateInterval('PT25H')); $this->localeDateMock->expects($this->once())->method('date')->will($this->returnValue($date)); return $date; }
/** * @dataProvider getConfigDataProvider */ public function testGetConfig($configData, $locale, $expectedResult) { foreach ($configData as $key => $value) { $this->configMock->expects($this->any())->method($key)->willReturn($value); } $this->localResolverMock->expects($this->any())->method('getLocale')->willReturn($locale); $this->assertEquals($expectedResult, $this->model->getConfig()); }
public function testUpdateAndGetTranslations() { $translations = ['phrase1' => 'translated1', 'phrase2' => 'translated2']; $this->eventManagerMock->expects($this->once())->method('dispatch'); $this->translateResourceMock->expects($this->once())->method('getTranslationArray')->willReturn($translations); $this->localeResolverMock->expects($this->once())->method('getLocale')->willReturn('en_US'); $this->fileManagerMock->expects($this->once())->method('updateTranslationFileContent'); $this->assertEquals($translations, $this->model->updateAndGetTranslations()); }
public function testUpdateQuoteItemWithZeroQty() { $itemId = 1; $itemQty = 0; $this->resolverMock->expects($this->never())->method('getLocale'); $this->cartMock->expects($this->once())->method('updateItems')->with([$itemId => ['qty' => $itemQty]])->willReturnSelf(); $this->cartMock->expects($this->once())->method('save')->willReturnSelf(); $this->assertEquals($this->sidebar, $this->sidebar->updateQuoteItem($itemId, $itemQty)); }
/** * @param int $qtyResult * @param int|null $expectedResult * @dataProvider processDataProvider */ public function testProcess($qtyResult, $expectedResult) { $qty = 10; $localCode = 'en_US'; $this->resolver->expects($this->once())->method('getLocale')->willReturn($localCode); $this->filter->expects($this->once())->method('setOptions')->with(['locale' => $localCode])->willReturnSelf(); $this->filter->expects($this->once())->method('filter')->with($qty)->willReturn($qtyResult); $this->assertEquals($expectedResult, $this->processor->process($qty)); }
/** * Set up aggregate * * @return \Magento\Framework\Stdlib\DateTime\DateInterface */ protected function setupAggregate() { $date = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\Date', ['emulate', 'revert'], [], '', false); $this->localeResolverMock->expects($this->once())->method('emulate')->with(0); $this->localeResolverMock->expects($this->once())->method('revert'); $dateMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\DateInterface')->disableOriginalConstructor()->getMock(); $dateMock->expects($this->once())->method('subHour')->with(25)->will($this->returnValue($date)); $this->localeDateMock->expects($this->once())->method('date')->will($this->returnValue($dateMock)); return $date; }
/** * Run test getConfig method * * @param array $config * @param array $expected * @dataProvider getConfigDataProvider */ public function testGetConfig($config, $expected) { $this->braintreeAdapter->expects(static::once())->method('generate')->willReturn(self::CLIENT_TOKEN); foreach ($config as $method => $value) { $this->config->expects(static::once())->method($method)->willReturn($value); } $this->payPalConfig->expects(static::once())->method('isActive')->willReturn(true); $this->payPalConfig->expects(static::once())->method('isAllowToEditShippingAddress')->willReturn(true); $this->payPalConfig->expects(static::once())->method('getMerchantName')->willReturn('Test'); $this->payPalConfig->expects(static::once())->method('getTitle')->willReturn('Payment Title'); $this->localeResolver->expects(static::once())->method('getLocale')->willReturn('en_US'); static::assertEquals($expected, $this->configProvider->getConfig()); }
/** * @param string $data * @param string $index * @param string $locale * @param string $period * @param string $result * @dataProvider datesDataProvider * @return void */ public function testRender($data, $index, $locale, $period, $result) { $this->resolverMock->expects($this->any())->method('getLocale')->will($this->returnValue($locale)); $this->localeDate->expects($this->any())->method('getDateFormat')->willReturnCallback(function ($value) use($locale) { return (new \IntlDateFormatter($locale, $value, \IntlDateFormatter::NONE))->getPattern(); }); $objectMock = $this->getMockBuilder('Magento\\Framework\\Object')->setMethods(['getData'])->getMock(); $objectMock->expects($this->once())->method('getData')->will($this->returnValue($data)); $columnMock = $this->getMockBuilder('Magento\\Backend\\Block\\Widget\\Grid\\Column')->disableOriginalConstructor()->setMethods(['getIndex', 'getPeriodType'])->getMock(); $columnMock->expects($this->once())->method('getIndex')->will($this->returnValue($index)); $columnMock->expects($this->atLeastOnce())->method('getPeriodType')->will($this->returnValue($period)); $this->date->setColumn($columnMock); $this->assertEquals($result, $this->date->render($objectMock)); }
public function testStop() { // Test data $initArea = 'initial area'; $initTheme = 'initial design theme'; $initLocale = 'initial locale code'; $initialStore = 1; $initTranslateInline = false; $this->inlineTranslationMock->expects($this->once())->method('isEnabled')->willReturn($initTranslateInline); $this->viewDesignMock->expects($this->once())->method('getArea')->willReturn($initArea); $this->viewDesignMock->expects($this->once())->method('getDesignTheme')->willReturn($initTheme); $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock); $this->storeMock->expects($this->once())->method('getStoreId')->willReturn($initialStore); $this->localeResolverMock->expects($this->once())->method('getLocale')->willReturn($initLocale); $this->model->storeCurrentEnvironmentInfo(); // Expectations $this->inlineTranslationMock->expects($this->once())->method('resume')->with($initTranslateInline); $this->viewDesignMock->expects($this->once())->method('setDesignTheme')->with($initTheme, $initArea); $this->storeManagerMock->expects($this->once())->method('setCurrentStore')->with($initialStore); $this->localeResolverMock->expects($this->once())->method('setLocale')->with($initLocale); $this->translateMock->expects($this->once())->method('setLocale')->with($initLocale); $this->translateMock->expects($this->once())->method('loadData')->with($initArea); // Test $this->model->stopEnvironmentEmulation(); }
/** * Prepare mocks for getCurrencySymbolsData * * @param int $websiteId * @param int $groupId * @param string $currencies */ protected function prepareMocksForGetCurrencySymbolsData($websiteId, $groupId, $currencies) { /** * @var \Magento\Store\Model\Website|\PHPUnit_Framework_MockObject_MockObject */ $websiteMock = $this->getMock('Magento\\Store\\Model\\Website', ['getId', 'getConfig'], [], '', false); /** * @var \Magento\Store\Model\Group|\PHPUnit_Framework_MockObject_MockObject */ $groupMock = $this->getMock('Magento\\Store\\Model\\Group', ['getId', 'getWebsiteId'], [], '', false); /** * @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject */ $storeMock = $this->getMock('Magento\\Store\\Model\\Store', ['getGroupId'], [], '', false); $this->systemStoreMock->expects($this->once())->method('getWebsiteCollection')->willReturn([$websiteMock]); $this->systemStoreMock->expects($this->once())->method('getGroupCollection')->willReturn([$groupMock]); $this->systemStoreMock->expects($this->once())->method('getStoreCollection')->willReturn([$storeMock]); $websiteMock->expects($this->any())->method('getId')->willReturn($websiteId); $groupMock->expects($this->any())->method('getWebsiteId')->willReturn($websiteId); $groupMock->expects($this->any())->method('getId')->willReturn($groupId); $storeMock->expects($this->any())->method('getGroupId')->willReturn($groupId); $this->scopeConfigMock->expects($this->any())->method('getValue')->willReturnMap([[CurrencySymbol::XML_PATH_CUSTOM_CURRENCY_SYMBOL, ScopeInterface::SCOPE_STORE, null, ''], [CurrencySymbol::XML_PATH_ALLOWED_CURRENCIES, ScopeInterface::SCOPE_STORE, $storeMock, $currencies], [CurrencySymbol::XML_PATH_ALLOWED_CURRENCIES, ScopeInterface::SCOPE_STORE, null, $currencies], [CurrencySymbol::XML_PATH_ALLOWED_CURRENCIES, ScopeInterface::SCOPE_STORE, $storeMock, $currencies]]); $websiteMock->expects($this->any())->method('getConfig')->with(CurrencySymbol::XML_PATH_ALLOWED_CURRENCIES)->willReturn($currencies); $this->localeResolverMock->expects($this->any())->method('getLocale')->willReturn('en'); }
/** * Declare calls expectation for setConfig() method */ protected function expectsSetConfig($themeId, $localeCode = 'en_US') { $this->locale->expects($this->any())->method('getLocaleCode')->will($this->returnValue($localeCode)); $scope = new \Magento\Framework\Object(['code' => 'frontendCode', 'id' => 1]); $scopeAdmin = new \Magento\Framework\Object(['code' => 'adminCode', 'id' => 0]); $this->scopeResolver->expects($this->any())->method('getScope')->will($this->returnValueMap([[null, $scope], ['admin', $scopeAdmin]])); $designTheme = new \Magento\Framework\Object(['id' => $themeId]); $this->viewDesign->expects($this->any())->method('getDesignTheme')->will($this->returnValue($designTheme)); }
protected function setUp() { $this->assetRepo = $this->getMock('Magento\\Framework\\View\\Asset\\Repository', [], [], '', false); $this->pageAssets = $this->getMock('Magento\\Framework\\View\\Asset\\GroupedCollection', [], [], '', false); $this->scopeConfig = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface', [], [], '', false); $this->favicon = $this->getMock('Magento\\Framework\\View\\Page\\FaviconInterface', [], [], '', false); $this->builder = $this->getMock('Magento\\Framework\\View\\Layout\\BuilderInterface', [], [], '', false); $this->asset = $this->getMock('Magento\\Framework\\View\\Asset\\File', [], [], '', false); $this->remoteAsset = $this->getMock('\\Magento\\Framework\\View\\Asset\\Remote', [], [], '', false); $this->title = $this->getMock('Magento\\Framework\\View\\Page\\Title', [], [], '', false); $this->localeMock = $this->getMockForAbstractClass('Magento\\Framework\\Locale\\ResolverInterface', [], '', false); $this->localeMock->expects($this->any())->method('getLocale')->willReturn(Resolver::DEFAULT_LOCALE); $this->model = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject('Magento\\Framework\\View\\Page\\Config', ['assetRepo' => $this->assetRepo, 'pageAssets' => $this->pageAssets, 'scopeConfig' => $this->scopeConfig, 'favicon' => $this->favicon, 'localeResolver' => $this->localeMock]); $this->areaResolverMock = $this->getMock('Magento\\Framework\\App\\State', [], [], '', false); $areaResolverReflection = (new \ReflectionClass(get_class($this->model)))->getProperty('areaResolver'); $areaResolverReflection->setAccessible(true); $areaResolverReflection->setValue($this->model, $this->areaResolverMock); }
/** * Test for toOptionArray (non-Japanese) * * @return void * @throws \Exception */ public function testToOptionArrayForEn() { $this->localeResolverMock->expects($this->any())->method('getLocale')->willReturn('en_US'); $items = [['name' => 'Hokkaido', 'default_name' => 'Hokkaido', 'region_id' => 1, 'country_id' => 1], ['name' => 'Aomori', 'default_name' => 'Aomori', 'region_id' => 2, 'country_id' => 1]]; foreach ($items as $itemData) { $this->collection->addItem(new DataObject($itemData)); } $expectedResult = [['label' => __('Please select a region, state or province.'), 'value' => null, 'title' => null], ['value' => 1, 'title' => 'Hokkaido', 'country_id' => 1, 'label' => 'Hokkaido'], ['value' => 2, 'title' => 'Aomori', 'country_id' => 1, 'label' => 'Aomori']]; $this->assertEquals($expectedResult, $this->collection->toOptionArray()); }
public function testGetHtmlSuccessfulTimestamp() { $uniqueHash = 'H@$H'; $id = 3; $format = 'mm/dd/yyyy'; $yesterday = new \DateTime(); $yesterday->add(\DateInterval::createFromDateString('yesterday')); $tomorrow = new \DateTime(); $tomorrow->add(\DateInterval::createFromDateString('tomorrow')); $value = ['locale' => 'en_US', 'from' => $yesterday->getTimestamp(), 'to' => $tomorrow->getTimestamp()]; $this->mathRandomMock->expects($this->any())->method('getUniqueHash')->willReturn($uniqueHash); $this->columnMock->expects($this->once())->method('getHtmlId')->willReturn($id); $this->localeDateMock->expects($this->any())->method('getDateFormat')->willReturn($format); $this->columnMock->expects($this->any())->method('getTimezone')->willReturn(false); $this->localeResolverMock->expects($this->any())->method('getLocale')->willReturn('en_US'); $this->model->setColumn($this->columnMock); $this->model->setValue($value); $output = $this->model->getHtml(); $this->assertContains('id="' . $uniqueHash . '_from" value="' . $yesterday->getTimestamp(), $output); $this->assertContains('id="' . $uniqueHash . '_to" value="' . $tomorrow->getTimestamp(), $output); }
public function testGetMonths() { $this->localeResolver->expects($this->once())->method('getLocale')->willReturn('en_US'); $this->assertEquals($this->expectedMonthList, $this->config->getMonths()); }
public function testGetLocale() { $locale = 'en_US'; $this->localeResolverMock->expects($this->once())->method('getLocale')->willReturn($locale); $this->assertEquals($locale, $this->block->getLocale()); }