public function testToHtml() { $fieldSet = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Fieldset', [], [], '', false); $form = $this->getMock('Magento\\Framework\\Data\\Form', [], [], '', false); $attributeModel = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], [], '', false); $entityType = $this->getMock('Magento\\Eav\\Model\\Entity\\Type', [], [], '', false); $formElement = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Text', ['setDisabled'], [], '', false); $directoryReadInterface = $this->getMock('\\Magento\\Framework\\Filesystem\\Directory\\ReadInterface'); $this->registry->expects($this->any())->method('registry')->with('entity_attribute')->willReturn($attributeModel); $this->formFactory->expects($this->any())->method('create')->willReturn($form); $form->expects($this->any())->method('addFieldset')->willReturn($fieldSet); $form->expects($this->any())->method('getElement')->willReturn($formElement); $fieldSet->expects($this->any())->method('addField')->willReturnSelf(); $attributeModel->expects($this->any())->method('getDefaultValue')->willReturn('default_value'); $attributeModel->expects($this->any())->method('setDisabled')->willReturnSelf(); $attributeModel->expects($this->any())->method('getId')->willReturn(1); $attributeModel->expects($this->any())->method('getEntityType')->willReturn($entityType); $attributeModel->expects($this->any())->method('getIsUserDefined')->willReturn(false); $attributeModel->expects($this->any())->method('getAttributeCode')->willReturn('attribute_code'); $this->localeDate->expects($this->any())->method('getDateFormat')->willReturn('mm/dd/yy'); $entityType->expects($this->any())->method('getEntityTypeCode')->willReturn('entity_type_code'); $this->eavData->expects($this->any())->method('getFrontendClasses')->willReturn([]); $formElement->expects($this->exactly(3))->method('setDisabled')->willReturnSelf(); $this->yesNo->expects($this->any())->method('toOptionArray')->willReturn(['yes', 'no']); $this->filesystem->expects($this->any())->method('getDirectoryRead')->willReturn($directoryReadInterface); $directoryReadInterface->expects($this->any())->method('getRelativePath')->willReturn('relative_path'); $this->block->setData(['action' => 'save']); $this->block->toHtml(); }
/** * 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; }
/** * {@inheritDoc} */ protected function setUp() { $this->entityFactoryMock = $this->getMockBuilder('Magento\\Framework\\Data\\Collection\\EntityFactory')->disableOriginalConstructor()->getMock(); $this->timezoneMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->getMock(); $this->factoryMock = $this->getMockBuilder('Magento\\Reports\\Model\\ResourceModel\\Report\\Collection\\Factory')->disableOriginalConstructor()->getMock(); $this->timezoneMock->expects($this->any())->method('formatDateTime')->will($this->returnCallback([$this, 'formatDateTime'])); $this->collection = new Collection($this->entityFactoryMock, $this->timezoneMock, $this->factoryMock); }
/** * @test */ public function testGetYearRange() { $testCurrentYear = 2123; $date = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\DateInterface')->getMock(); $date->expects($this->any())->method('__toString')->will($this->returnValue($testCurrentYear)); $this->localeDate->expects($this->any())->method('date')->with($this->equalTo('Y'))->will($this->returnValue($date)); $this->assertEquals((int) $testCurrentYear - 100 . ':' . $testCurrentYear, $this->block->getYearRange()); }
/** * 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; }
/** * {@inheritDoc} */ protected function setUp() { $this->localeDate = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->disableOriginalConstructor()->getMock(); $this->localeDate->expects($this->once())->method('date')->willReturnArgument(0); $this->contextMock = $this->getMockBuilder('Magento\\Backend\\Block\\Context')->disableOriginalConstructor()->getMock(); $this->contextMock->expects($this->once())->method('getLocaleDate')->willReturn($this->localeDate); $this->resolverMock = $this->getMockBuilder('Magento\\Framework\\Locale\\ResolverInterface')->getMock(); $this->dateTimeFormatter = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\DateTimeFormatterInterface'); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->date = $objectManager->getObject('Magento\\Reports\\Block\\Adminhtml\\Sales\\Grid\\Column\\Renderer\\Date', ['context' => $this->contextMock, 'localeResolver' => $this->resolverMock, 'dateTimeFormatter' => $this->dateTimeFormatter]); $this->globalStateLocaleBackup = \Locale::getDefault(); }
/** * @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 testGetRssData() { $ruleData = ['to_date' => '12/12/14', 'from_date' => '12/12/14', 'coupon_code' => '1234567', 'description' => 'Rule Description', 'name' => 'Rule Name']; $rssData = ['title' => 'Frontend Name - Discounts and Coupons', 'description' => 'Frontend Name - Discounts and Coupons', 'link' => 'http://rss.magento.com/discount', 'charset' => 'UTF-8', 'language' => 'en_US', 'entries' => ['title' => 'Rule Name', 'link' => 'http://rss.magento.com', 'description' => ['description' => 'Rule Description', 'start_date' => '12/12/14', 'end_date' => '12/12/14', 'coupon_code' => '1234567']]]; $rssUrl = 'http://rss.magento.com/discount'; $url = 'http://rss.magento.com'; $ruleModel = $this->getMock('Magento\\SalesRule\\Model\\Rule', ['__wakeup', 'getCouponCode', 'getToDate', 'getFromDate', 'getDescription', 'getName'], [], '', false); $this->storeModel->expects($this->once())->method('getWebsiteId')->will($this->returnValue(1)); $this->storeModel->expects($this->never())->method('getName'); $this->storeModel->expects($this->atLeastOnce())->method('getFrontendName')->willReturn('Frontend Name'); $this->requestInterface->expects($this->any())->method('getParam')->will($this->returnValue(1)); $this->urlBuilderInterface->expects($this->any())->method('getUrl')->will($this->returnValue($url)); $this->rssBuilderInterface->expects($this->any())->method('getUrl')->will($this->returnValue($rssUrl)); $this->scopeConfigInterface->expects($this->any())->method('getValue')->will($this->returnValue('en_US')); $ruleModel->expects($this->any())->method('getCouponCode')->will($this->returnValue($ruleData['coupon_code'])); $ruleModel->expects($this->any())->method('getToDate')->will($this->returnValue($ruleData['to_date'])); $ruleModel->expects($this->once())->method('getFromDate')->will($this->returnValue($ruleData['from_date'])); $ruleModel->expects($this->once())->method('getDescription')->will($this->returnValue($ruleData['description'])); $ruleModel->expects($this->once())->method('getName')->will($this->returnValue($ruleData['name'])); $this->rssModel->expects($this->any())->method('getDiscountCollection')->will($this->returnValue([$ruleModel])); $this->timezoneInterface->expects($this->any())->method('formatDate')->will($this->returnValue('12/12/14')); $data = $this->block->getRssData(); $this->assertEquals($rssData['title'], $data['title']); $this->assertEquals($rssData['description'], $data['description']); $this->assertEquals($rssData['link'], $data['link']); $this->assertEquals($rssData['charset'], $data['charset']); $this->assertEquals($rssData['language'], $data['language']); $this->assertEquals($rssData['entries']['title'], $data['entries'][0]['title']); $this->assertEquals($rssData['entries']['link'], $data['entries'][0]['link']); $this->assertContains($rssData['entries']['description']['description'], $data['entries'][0]['description']); $this->assertContains($rssData['entries']['description']['start_date'], $data['entries'][0]['description']); $this->assertContains($rssData['entries']['description']['end_date'], $data['entries'][0]['description']); $this->assertContains($rssData['entries']['description']['coupon_code'], $data['entries'][0]['description']); }
/** * @param string $result * @param string|null $lastLoginAt * @dataProvider getStoreLastLoginDateDataProvider * @return void */ public function testGetStoreLastLoginDate($result, $lastLoginAt) { $this->customerLog->expects($this->once())->method('getLastLoginAt')->willReturn($lastLoginAt); $this->localeDate->expects($this->any())->method('scopeDate')->will($this->returnValue($lastLoginAt)); $this->localeDate->expects($this->any())->method('formatDateTime')->willReturn($lastLoginAt); $this->assertEquals($result, $this->block->getStoreLastLoginDate()); }
public function testRefreshSpecialPrices() { $idsToProcess = [1, 2, 3]; $this->metadataPool->expects($this->atLeastOnce())->method('getMetadata')->willReturn($this->metadataMock); $this->metadataMock->expects($this->atLeastOnce())->method('getLinkField')->willReturn('row_id'); $this->metadataMock->expects($this->atLeastOnce())->method('getIdentifierField')->willReturn('entity_id'); $selectMock = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false); $selectMock->expects($this->any())->method('from')->will($this->returnSelf()); $selectMock->expects($this->any())->method('joinLeft')->will($this->returnSelf()); $selectMock->expects($this->any())->method('where')->will($this->returnSelf()); $connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface', [], [], '', false); $connectionMock->expects($this->any())->method('select')->will($this->returnValue($selectMock)); $connectionMock->expects($this->any())->method('fetchCol')->will($this->returnValue($idsToProcess)); $this->_resourceMock->expects($this->once())->method('getConnection')->will($this->returnValue($connectionMock)); $this->_resourceMock->expects($this->any())->method('getTableName')->will($this->returnValue('category')); $storeMock = $this->getMock('\\Magento\\Store\\Model\\Store', [], [], '', false); $storeMock->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->_storeManagerMock->expects($this->once())->method('getStores')->with(true)->will($this->returnValue([$storeMock])); $this->_localeDateMock->expects($this->once())->method('scopeTimeStamp')->with($storeMock)->will($this->returnValue(32000)); $indexerMock = $this->getMock('Magento\\Indexer\\Model\\Indexer', [], [], '', false); $indexerMock->expects($this->exactly(2))->method('reindexList'); $this->_priceProcessorMock->expects($this->exactly(2))->method('getIndexer')->will($this->returnValue($indexerMock)); $attributeMock = $this->getMockForAbstractClass('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', [], '', false, true, true, ['__wakeup', 'getAttributeId']); $attributeMock->expects($this->any())->method('getAttributeId')->will($this->returnValue(1)); $this->_eavConfigMock->expects($this->any())->method('getAttribute')->will($this->returnValue($attributeMock)); $this->_model->execute(); }
/** * Prepare parameters */ public function setUp() { $this->_objectManager = $this->getMockBuilder('Magento\\Framework\\App\\ObjectManager')->disableOriginalConstructor()->getMock(); $this->_cache = $this->getMock('Magento\\Framework\\App\\CacheInterface'); $this->_config = $this->getMockBuilder('Magento\\Cron\\Model\\Config')->disableOriginalConstructor()->getMock(); $this->_scopeConfig = $this->getMockBuilder('Magento\\Framework\\App\\Config\\ScopeConfigInterface')->disableOriginalConstructor()->getMock(); $this->_collection = $this->getMockBuilder('Magento\\Cron\\Model\\Resource\\Schedule\\Collection')->setMethods(['addFieldToFilter', 'load', '__wakeup'])->disableOriginalConstructor()->getMock(); $this->_collection->expects($this->any())->method('addFieldToFilter')->will($this->returnSelf()); $this->_collection->expects($this->any())->method('load')->will($this->returnSelf()); $this->_scheduleFactory = $this->getMockBuilder('Magento\\Cron\\Model\\ScheduleFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock(); $this->_request = $this->getMockBuilder('Magento\\Framework\\App\\Console\\Request')->disableOriginalConstructor()->getMock(); $this->_shell = $this->getMockBuilder('Magento\\Framework\\ShellInterface')->disableOriginalConstructor()->setMethods(['execute'])->getMock(); $this->timezone = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface'); $this->timezone->expects($this->any())->method('scopeTimeStamp')->will($this->returnValue(time())); $this->_observer = new \Magento\Cron\Model\Observer($this->_objectManager, $this->_scheduleFactory, $this->_cache, $this->_config, $this->_scopeConfig, $this->_request, $this->_shell, $this->timezone); }
public function setUp() { parent::setUp(); $this->jsonHelper = $this->getMock('\\Magento\\Framework\\Json\\Helper\\Data', [], [], '', false); $this->importExportData = $this->getMock('\\Magento\\ImportExport\\Helper\\Data', [], [], '', false); $this->resourceHelper = $this->getMock('\\Magento\\ImportExport\\Model\\ResourceModel\\Helper', [], [], '', false); $this->resource = $this->getMock('\\Magento\\Framework\\App\\ResourceConnection', ['getConnection'], [], '', false); $this->connection = $this->getMockForAbstractClass('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface', [], '', false); $this->resource->expects($this->any())->method('getConnection')->willReturn($this->connection); $this->dataSourceModel = $this->getMock('\\Magento\\ImportExport\\Model\\ResourceModel\\Import\\Data', [], [], '', false); $this->eavConfig = $this->getMock('\\Magento\\Eav\\Model\\Config', [], [], '', false); $entityType = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Type', [], [], '', false); $entityType->method('getEntityTypeId')->willReturn(''); $this->eavConfig->method('getEntityType')->willReturn($entityType); $this->resourceFactory = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Proxy\\Product\\ResourceModelFactory', ['create', 'getTable'], [], '', false); $this->resourceFactory->expects($this->any())->method('create')->willReturnSelf(); $this->resourceFactory->expects($this->any())->method('getTable')->willReturnSelf(); $this->catalogData = $this->getMock('\\Magento\\Catalog\\Helper\\Data', [], [], '', false); $this->storeResolver = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product\\StoreResolver', [], [], '', false); $this->importProduct = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product', [], [], '', false); $this->productModel = $this->getMock('\\Magento\\Catalog\\Model\\Product', [], [], '', false); $this->validator = $this->getMock('\\Magento\\AdvancedPricingImportExport\\Model\\Import\\AdvancedPricing\\Validator', ['isValid', 'getMessages'], [], '', false); $this->websiteValidator = $this->getMock('\\Magento\\AdvancedPricingImportExport\\Model\\Import\\AdvancedPricing\\Validator\\Website', [], [], '', false); $this->tierPriceValidator = $this->getMock('\\Magento\\AdvancedPricingImportExport\\Model\\Import\\AdvancedPricing\\Validator\\TierPrice', [], [], '', false); $this->stringObject = $this->getMock('\\Magento\\Framework\\Stdlib\\StringUtils', [], [], '', false); $this->errorAggregator = $this->getErrorAggregatorObject(); $this->dateTime = $this->getMock('\\Magento\\Framework\\Stdlib\\DateTime\\DateTime', ['date', 'format'], [], '', false); $this->dateTime->expects($this->any())->method('date')->willReturnSelf(); $this->advancedPricing = $this->getAdvancedPricingMock(['retrieveOldSkus', 'validateRow', 'addRowError', 'saveProductPrices', 'getCustomerGroupId', 'getWebSiteId', 'deleteProductTierPrices', 'getBehavior', 'saveAndReplaceAdvancedPrices', 'processCountExistingPrices', 'processCountNewPrices']); $this->advancedPricing->expects($this->any())->method('retrieveOldSkus')->willReturn([]); }
public function testGetStoreLastLoginDate() { $date = date('Y-m-d H:i:s'); $time = strtotime($date); $this->localeDate->expects($this->once())->method('scopeDate')->will($this->returnValue($date)); $this->localeDate->expects($this->once())->method('formatDate')->will($this->returnValue($date)); $this->customerLog->expects($this->any())->method('getLoginAtTimestamp')->will($this->returnValue($time)); $this->assertEquals($date, $this->block->getStoreLastLoginDate()); }
/** * @dataProvider getCcExpDateDataProvider */ public function testGetCcExpDate($ccExpMonth, $ccExpYear) { $paymentInfo = $this->getMock('Magento\\Payment\\Model\\Info', ['getCcExpMonth', 'getCcExpYear'], [], '', false); $paymentInfo->expects($this->any())->method('getCcExpMonth')->will($this->returnValue($ccExpMonth)); $paymentInfo->expects($this->any())->method('getCcExpYear')->will($this->returnValue($ccExpYear)); $this->model->setData('info', $paymentInfo); $this->localeDate->expects($this->exactly(2))->method('getConfigTimezone')->willReturn('America/Los_Angeles'); $this->assertEquals($ccExpYear, $this->model->getCcExpDate()->format('Y')); $this->assertEquals($ccExpMonth, $this->model->getCcExpDate()->format('m')); }
/** * @test * @return void * @covers \Magento\Theme\Model\Design::loadChange * @covers \Magento\Theme\Model\Design::__construct * @covers \Magento\Theme\Model\Design::_construct */ public function testLoadChangeFromCache() { $storeId = 1; $localDate = '2\\28\\2000'; $date = '28-02-2000'; $cacheId = 'design_change_' . md5($storeId . $date); $this->localeDate->expects($this->once())->method('scopeTimeStamp')->with($storeId)->willReturn($localDate); $this->dateTime->expects($this->once())->method('formatDate')->with($localDate, false)->willReturn($date); $this->cacheManager->expects($this->once())->method('load')->with($cacheId)->willReturn(serialize(['test' => 'data'])); $this->assertInstanceOf(get_class($this->model), $this->model->loadChange($storeId)); }
/** * @param $regularPrice * @param $specialPrice * @param $isScopeDateInInterval * @param $value * @param $percent * @dataProvider getValueDataProvider */ public function testGetValue($regularPrice, $specialPrice, $isScopeDateInInterval, $value, $percent) { $specialFromDate = 'some date from'; $specialToDate = 'some date to'; $this->saleable->expects($this->once())->method('getSpecialPrice')->will($this->returnValue($specialPrice)); $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $this->saleable->expects($this->once())->method('getStore')->will($this->returnValue($store)); $this->saleable->expects($this->once())->method('getSpecialFromDate')->will($this->returnValue($specialFromDate)); $this->saleable->expects($this->once())->method('getSpecialToDate')->will($this->returnValue($specialToDate)); $this->localeDate->expects($this->once())->method('isScopeDateInInterval')->with($store, $specialFromDate, $specialToDate)->will($this->returnValue($isScopeDateInInterval)); if ($isScopeDateInInterval) { $price = $this->getMock('Magento\\Framework\\Pricing\\Price\\PriceInterface'); $this->priceInfo->expects($this->once())->method('getPrice')->with(\Magento\Catalog\Pricing\Price\RegularPrice::PRICE_CODE)->will($this->returnValue($price)); $price->expects($this->once())->method('getValue')->will($this->returnValue($regularPrice)); } $this->assertEquals($value, $this->model->getValue()); //check that the second call will get data from cache the same as in first call $this->assertEquals($value, $this->model->getValue()); $this->assertEquals($percent, $this->model->getDiscountPercent()); }
/** * @covers \Magento\Cms\Helper\Page::renderPageExtended * @param integer|null $pageId * @param integer|null $internalPageId * @param integer $pageLoadResultIndex * @param string $customPageLayout * @param string $handle * @param string $customLayoutUpdateXml * @param string $layoutUpdate * @param boolean $expectedResult * * @dataProvider renderPageExtendedDataProvider * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testRenderPageExtended($pageId, $internalPageId, $pageLoadResultIndex, $customPageLayout, $handle, $customLayoutUpdateXml, $layoutUpdate, $expectedResult) { $storeId = 321; $customThemeFrom = 'customThemeFrom'; $customThemeTo = 'customThemeTo'; $isScopeDateInInterval = true; $customTheme = 'customTheme'; $pageLayout = 'pageLayout'; $pageIdentifier = 111; $layoutUpdateXml = 'layoutUpdateXml'; $contentHeading = 'contentHeading'; $escapedContentHeading = 'escapedContentHeading'; $defaultGroup = 'defaultGroup'; $pageLoadResultCollection = [null, $this->pageMock]; $this->pageMock->expects($this->any())->method('getId')->willReturn($internalPageId); $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock); $this->storeMock->expects($this->any())->method('getId')->willReturn($storeId); $this->pageMock->expects($this->any())->method('setStoreId')->with($storeId)->willReturnSelf(); $this->pageMock->expects($this->any())->method('load')->with($pageId)->willReturn($pageLoadResultCollection[$pageLoadResultIndex]); $this->pageMock->expects($this->any())->method('getCustomThemeFrom')->willReturn($customThemeFrom); $this->pageMock->expects($this->any())->method('getCustomThemeTo')->willReturn($customThemeTo); $this->localeDateMock->expects($this->any())->method('isScopeDateInInterval')->with(null, $customThemeFrom, $customThemeTo)->willReturn($isScopeDateInInterval); $this->pageMock->expects($this->any())->method('getCustomTheme')->willReturn($customTheme); $this->designMock->expects($this->any())->method('setDesignTheme')->with($customTheme)->willReturnSelf(); $this->pageMock->expects($this->any())->method('getPageLayout')->willReturn($pageLayout); $this->pageMock->expects($this->any())->method('getCustomPageLayout')->willReturn($customPageLayout); $this->resultPageMock->expects($this->any())->method('getConfig')->willReturn($this->pageConfigMock); $this->pageConfigMock->expects($this->any())->method('setPageLayout')->with($handle)->willReturnSelf(); $this->viewMock->expects($this->any())->method('getPage')->willReturn($this->resultPageMock); $this->resultPageMock->expects($this->any())->method('initLayout')->willReturnSelf(); $this->resultPageMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock); $this->layoutMock->expects($this->any())->method('getUpdate')->willReturn($this->layoutProcessorMock); $this->layoutProcessorMock->expects($this->any())->method('addHandle')->with('cms_page_view')->willReturnSelf(); $this->pageMock->expects($this->any())->method('getIdentifier')->willReturn($pageIdentifier); $this->viewMock->expects($this->any())->method('addPageLayoutHandles')->with(['id' => $pageIdentifier])->willReturn(true); $this->eventManagerMock->expects($this->any())->method('dispatch')->with('cms_page_render', ['page' => $this->pageMock, 'controller_action' => $this->actionMock]); $this->viewMock->expects($this->any())->method('loadLayoutUpdates')->willReturnSelf(); $this->pageMock->expects($this->any())->method('getCustomLayoutUpdateXml')->willReturn($customLayoutUpdateXml); $this->pageMock->expects($this->any())->method('getLayoutUpdateXml')->willReturn($layoutUpdateXml); $this->layoutProcessorMock->expects($this->any())->method('addUpdate')->with($layoutUpdate)->willReturnSelf(); $this->viewMock->expects($this->any())->method('generateLayoutXml')->willReturnSelf(); $this->viewMock->expects($this->any())->method('generateLayoutBlocks')->willReturnSelf(); $this->layoutMock->expects($this->any())->method('getBlock')->with('page_content_heading')->willReturn($this->blockMock); $this->pageMock->expects($this->any())->method('getContentHeading')->willReturn($contentHeading); $this->escaperMock->expects($this->any())->method('escapeHtml')->with($contentHeading)->willReturn($escapedContentHeading); $this->blockMock->expects($this->any())->method('setContentHeading')->with($escapedContentHeading)->willReturnSelf(); $this->layoutMock->expects($this->any())->method('getMessagesBlock')->willReturn($this->messagesBlockMock); $this->messageManagerMock->expects($this->any())->method('getDefaultGroup')->willReturn($defaultGroup); $this->messagesBlockMock->expects($this->any())->method('addStorageType')->with($defaultGroup); $this->messageManagerMock->expects($this->any())->method('getMessages')->with(true)->willReturn($this->messageCollectionMock); $this->messagesBlockMock->expects($this->any())->method('addMessages')->with($this->messageCollectionMock)->willReturnSelf(); $this->viewMock->expects($this->any())->method('renderLayout')->willReturnSelf(); $this->assertEquals($expectedResult, $this->object->renderPageExtended($this->actionMock, $pageId)); }
/** * Prepare parameters */ protected function setUp() { $this->_objectManager = $this->getMockBuilder('Magento\\Framework\\App\\ObjectManager')->disableOriginalConstructor()->getMock(); $this->_cache = $this->getMock('Magento\\Framework\\App\\CacheInterface'); $this->_config = $this->getMockBuilder('Magento\\Cron\\Model\\Config')->disableOriginalConstructor()->getMock(); $this->_scopeConfig = $this->getMockBuilder('Magento\\Framework\\App\\Config\\ScopeConfigInterface')->disableOriginalConstructor()->getMock(); $this->_collection = $this->getMockBuilder('Magento\\Cron\\Model\\ResourceModel\\Schedule\\Collection')->setMethods(['addFieldToFilter', 'load', '__wakeup'])->disableOriginalConstructor()->getMock(); $this->_collection->expects($this->any())->method('addFieldToFilter')->will($this->returnSelf()); $this->_collection->expects($this->any())->method('load')->will($this->returnSelf()); $this->_scheduleFactory = $this->getMockBuilder('Magento\\Cron\\Model\\ScheduleFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock(); $this->_request = $this->getMockBuilder('Magento\\Framework\\App\\Console\\Request')->disableOriginalConstructor()->getMock(); $this->_shell = $this->getMockBuilder('Magento\\Framework\\ShellInterface')->disableOriginalConstructor()->setMethods(['execute'])->getMock(); $this->observer = $this->getMock('Magento\\Framework\\Event\\Observer', [], [], '', false); $this->timezone = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface'); $this->timezone->expects($this->any())->method('scopeTimeStamp')->will($this->returnValue(time())); $phpExecutableFinder = $this->getMock('Symfony\\Component\\Process\\PhpExecutableFinder', [], [], '', false); $phpExecutableFinder->expects($this->any())->method('find')->willReturn('php'); $phpExecutableFinderFactory = $this->getMock('Magento\\Framework\\Process\\PhpExecutableFinderFactory', [], [], '', false); $phpExecutableFinderFactory->expects($this->any())->method('create')->willReturn($phpExecutableFinder); $this->_observer = new ProcessCronQueueObserver($this->_objectManager, $this->_scheduleFactory, $this->_cache, $this->_config, $this->_scopeConfig, $this->_request, $this->_shell, $this->timezone, $phpExecutableFinderFactory); }
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 testRefreshSpecialPrices() { $idsToProcess = array(1, 2, 3); $selectMock = $this->getMock('Magento\\Framework\\DB\\Select', array(), array(), '', false); $selectMock->expects($this->any())->method('from')->will($this->returnSelf()); $selectMock->expects($this->any())->method('where')->will($this->returnSelf()); $connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface', array(), array(), '', false); $connectionMock->expects($this->any())->method('select')->will($this->returnValue($selectMock)); $connectionMock->expects($this->any())->method('fetchCol')->with($selectMock, array('entity_id'))->will($this->returnValue($idsToProcess)); $this->_resourceMock->expects($this->once())->method('getConnection')->with('write')->will($this->returnValue($connectionMock)); $storeMock = $this->getMock('\\Magento\\Store\\Model\\Store', array(), array(), '', false); $storeMock->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->_storeManagerMock->expects($this->once())->method('getStores')->with(true)->will($this->returnValue(array($storeMock))); $this->_localeDateMock->expects($this->once())->method('scopeTimeStamp')->with($storeMock)->will($this->returnValue(32000)); $indexerMock = $this->getMock('Magento\\Indexer\\Model\\Indexer', array(), array(), '', false); $indexerMock->expects($this->exactly(2))->method('reindexList'); $this->_priceProcessorMock->expects($this->exactly(2))->method('getIndexer')->will($this->returnValue($indexerMock)); $attributeMock = $this->getMockForAbstractClass('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', array(), '', false, true, true, array('__wakeup', 'getAttributeId')); $attributeMock->expects($this->any())->method('getAttributeId')->will($this->returnValue(1)); $this->_eavConfigMock->expects($this->any())->method('getAttribute')->will($this->returnValue($attributeMock)); $this->_model->refreshSpecialPrices(); }
/** * @dataProvider getCcExpDateDataProvider */ public function testGetCcExpDate($ccExpMonth, $ccExpYear) { $paymentInfo = $this->getMock('Magento\\Payment\\Model\\Info', ['getCcExpMonth', 'getCcExpYear'], [], '', false); $paymentInfo->expects($this->any())->method('getCcExpMonth')->will($this->returnValue($ccExpMonth)); $paymentInfo->expects($this->any())->method('getCcExpYear')->will($this->returnValue($ccExpYear)); $this->model->setData('info', $paymentInfo); $date = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface', ['setYear', 'getYear', 'setMonth', 'getMonth', 'getDefaultTimezonePath', 'getDefaultTimezone', 'getDateFormat', 'getDateFormatWithLongYear', 'getTimeFormat', 'getDateTimeFormat', 'date', 'scopeDate', 'utcDate', 'scopeTimeStamp', 'formatDate', 'formatTime', 'getConfigTimezone', 'isScopeDateInInterval'], [], '', false); $date->expects($this->any())->method('getYear')->willReturn($ccExpYear); $date->expects($this->any())->method('getMonth')->willReturn($ccExpMonth); $this->localeDate->expects($this->any())->method('date')->will($this->returnValue($date)); $this->assertEquals($ccExpYear, $this->model->getCcExpDate()->getYear()); $this->assertEquals($ccExpMonth, $this->model->getCcExpDate()->getMonth()); }
public function testGetProductsCollection() { /** @var \DateTime|\PHPUnit_Framework_MockObject_MockObject $dateObject */ $dateObject = $this->getMock('DateTime'); $dateObject->expects($this->any())->method('setTime')->will($this->returnSelf()); $dateObject->expects($this->any())->method('format')->will($this->returnValue(date(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT))); $this->timezone->expects($this->exactly(2))->method('date')->will($this->returnValue($dateObject)); /** @var \Magento\Catalog\Model\Resource\Product\Collection $productCollection */ $productCollection = $this->getMock('Magento\\Catalog\\Model\\Resource\\Product\\Collection', [], [], '', false); $this->product->expects($this->once())->method('getResourceCollection')->will($this->returnValue($productCollection)); $storeId = 1; $productCollection->expects($this->once())->method('setStoreId')->with($storeId); $productCollection->expects($this->once())->method('addStoreFilter')->will($this->returnSelf()); $productCollection->expects($this->any())->method('addAttributeToFilter')->will($this->returnSelf()); $productCollection->expects($this->any())->method('addAttributeToSelect')->will($this->returnSelf()); $productCollection->expects($this->once())->method('addAttributeToSort')->will($this->returnSelf()); $productCollection->expects($this->once())->method('applyFrontendPriceLimitations')->will($this->returnSelf()); $visibleIds = [1, 3]; $this->visibility->expects($this->once())->method('getVisibleInCatalogIds')->will($this->returnValue($visibleIds)); $productCollection->expects($this->once())->method('setVisibility')->with($visibleIds)->will($this->returnSelf()); $products = $this->newProducts->getProductsCollection($storeId); $this->assertEquals($productCollection, $products); }
public function testGetData() { $this->dateTime->expects($this->once())->method('formatDate')->will($this->returnValue(date('Y-m-d H:i:s'))); $this->rssUrlBuilderInterface->expects($this->once())->method('getUrl')->with(['_secure' => true, '_nosecret' => true, 'type' => 'new_order'])->will($this->returnValue('http://magento.com/backend/rss/feed/index/type/new_order')); $this->timezoneInterface->expects($this->once())->method('formatDate')->will($this->returnValue('2014-09-10 17:39:50')); $order = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->setMethods(['__sleep', '__wakeup', 'getResourceCollection', 'getIncrementId', 'getId', 'getCreatedAt'])->disableOriginalConstructor()->getMock(); $order->expects($this->once())->method('getId')->will($this->returnValue(1)); $order->expects($this->once())->method('getIncrementId')->will($this->returnValue('100000001')); $order->expects($this->once())->method('getCreatedAt')->will($this->returnValue(time())); $collection = $this->getMockBuilder('\\Magento\\Sales\\Model\\ResourceModel\\Order\\Collection')->setMethods(['addAttributeToFilter', 'addAttributeToSort', 'getIterator'])->disableOriginalConstructor()->getMock(); $collection->expects($this->once())->method('addAttributeToFilter')->will($this->returnSelf()); $collection->expects($this->once())->method('addAttributeToSort')->will($this->returnSelf()); $collection->expects($this->once())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$order]))); $order->expects($this->once())->method('getResourceCollection')->will($this->returnValue($collection)); $this->orderFactory->expects($this->once())->method('create')->will($this->returnValue($order)); $this->eventManager->expects($this->once())->method('dispatch')->will($this->returnSelf()); $block = $this->getMock('Magento\\Sales\\Block\\Adminhtml\\Order\\Details', ['setOrder', 'toHtml'], [], '', false); $block->expects($this->once())->method('setOrder')->with($order)->will($this->returnSelf()); $block->expects($this->once())->method('toHtml')->will($this->returnValue('Order Description')); $this->layout->expects($this->once())->method('getBlockSingleton')->will($this->returnValue($block)); $this->urlBuiler->expects($this->once())->method('getUrl')->will($this->returnValue('http://magento.com/sales/order/view/order_id/1')); $this->assertEquals($this->feedData, $this->model->getRssData()); }
/** * Test get Value */ public function testGetValue() { $coreStoreId = 1; $coreWebsiteId = 1; $productId = 1; $customerGroupId = 1; $dateTime = time(); $expectedValue = 55.12; $this->coreStoreMock->expects($this->once())->method('getId')->will($this->returnValue($coreStoreId)); $this->coreStoreMock->expects($this->once())->method('getWebsiteId')->will($this->returnValue($coreWebsiteId)); $this->dataTimeMock->expects($this->once())->method('scopeTimeStamp')->with($this->equalTo($coreStoreId))->will($this->returnValue($dateTime)); $this->customerSessionMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue($customerGroupId)); $this->catalogRuleResourceMock->expects($this->once())->method('getRulePrice')->will($this->returnValue($expectedValue)); $this->saleableItemMock->expects($this->any())->method('getId')->will($this->returnValue($productId)); $this->assertEquals($expectedValue, $this->object->getValue()); }
/** * @covers \Magento\Cms\Helper\Page::prepareResultPage * @param integer|null $pageId * @param integer|null $internalPageId * @param integer $pageLoadResultIndex * @param string $customPageLayout * @param string $handle * @param string $customLayoutUpdateXml * @param string $layoutUpdate * @param boolean $expectedResult * * @dataProvider renderPageExtendedDataProvider * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testPrepareResultPage($pageId, $internalPageId, $pageLoadResultIndex, $customPageLayout, $handle, $customLayoutUpdateXml, $layoutUpdate, $expectedResult) { $storeId = 321; $customThemeFrom = 'customThemeFrom'; $customThemeTo = 'customThemeTo'; $isScopeDateInInterval = true; $customTheme = 'customTheme'; $pageLayout = 'pageLayout'; $pageIdentifier = 111; $layoutUpdateXml = 'layoutUpdateXml'; $contentHeading = 'contentHeading'; $escapedContentHeading = 'escapedContentHeading'; $pageLoadResultCollection = [null, $this->pageMock]; $this->pageMock->expects($this->any())->method('getId')->willReturn($internalPageId); $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock); $this->storeMock->expects($this->any())->method('getId')->willReturn($storeId); $this->pageMock->expects($this->any())->method('setStoreId')->with($storeId)->willReturnSelf(); $this->pageMock->expects($this->any())->method('load')->with($pageId)->willReturn($pageLoadResultCollection[$pageLoadResultIndex]); $this->pageMock->expects($this->any())->method('getCustomThemeFrom')->willReturn($customThemeFrom); $this->pageMock->expects($this->any())->method('getCustomThemeTo')->willReturn($customThemeTo); $this->localeDateMock->expects($this->any())->method('isScopeDateInInterval')->with(null, $customThemeFrom, $customThemeTo)->willReturn($isScopeDateInInterval); $this->pageMock->expects($this->any())->method('getCustomTheme')->willReturn($customTheme); $this->designMock->expects($this->any())->method('setDesignTheme')->with($customTheme)->willReturnSelf(); $this->pageMock->expects($this->any())->method('getPageLayout')->willReturn($pageLayout); $this->pageMock->expects($this->any())->method('getCustomPageLayout')->willReturn($customPageLayout); $this->resultPageFactory->expects($this->any())->method('create')->will($this->returnValue($this->resultPageMock)); $this->resultPageMock->expects($this->any())->method('getConfig')->willReturn($this->pageConfigMock); $this->pageConfigMock->expects($this->any())->method('setPageLayout')->with($handle)->willReturnSelf(); $this->resultPageMock->expects($this->any())->method('initLayout')->willReturnSelf(); $this->resultPageMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock); $this->layoutMock->expects($this->any())->method('getUpdate')->willReturn($this->layoutProcessorMock); $this->layoutProcessorMock->expects($this->any())->method('addHandle')->with('cms_page_view')->willReturnSelf(); $this->pageMock->expects($this->any())->method('getIdentifier')->willReturn($pageIdentifier); $this->eventManagerMock->expects($this->any())->method('dispatch')->with('cms_page_render', ['page' => $this->pageMock, 'controller_action' => $this->actionMock]); $this->pageMock->expects($this->any())->method('getCustomLayoutUpdateXml')->willReturn($customLayoutUpdateXml); $this->pageMock->expects($this->any())->method('getLayoutUpdateXml')->willReturn($layoutUpdateXml); $this->layoutProcessorMock->expects($this->any())->method('addUpdate')->with($layoutUpdate)->willReturnSelf(); $this->layoutMock->expects($this->any())->method('getBlock')->with('page_content_heading')->willReturn($this->blockMock); $this->pageMock->expects($this->any())->method('getContentHeading')->willReturn($contentHeading); $this->escaperMock->expects($this->any())->method('escapeHtml')->with($contentHeading)->willReturn($escapedContentHeading); $this->blockMock->expects($this->any())->method('setContentHeading')->with($escapedContentHeading)->willReturnSelf(); if ($expectedResult) { $expectedResult = $this->resultPageMock; } $this->assertSame($expectedResult, $this->object->prepareResultPage($this->actionMock, $pageId)); }
public function testGetRssData() { $this->rssUrlBuilder->expects($this->once())->method('getUrl')->with(['type' => 'special_products', 'store_id' => 1])->will($this->returnValue('http://magento.com/rss/feed/index/type/special_products/store_id/1')); $item = $this->getItemMock(); $this->rssModel->expects($this->once())->method('getProductsCollection')->will($this->returnValue([$item])); $this->msrpHelper->expects($this->once())->method('canApplyMsrp')->will($this->returnValue(false)); $this->localeDate->expects($this->once())->method('formatDateTime')->will($this->returnValue(date('Y-m-d'))); $this->priceCurrency->expects($this->any())->method('convertAndFormat')->will($this->returnArgument(0)); $this->imageHelper->expects($this->once())->method('init')->with($item, 'rss_thumbnail')->will($this->returnSelf()); $this->imageHelper->expects($this->once())->method('getUrl')->will($this->returnValue('image_link')); $this->outputHelper->expects($this->once())->method('productAttribute')->will($this->returnValue('')); $data = ['title' => 'Store 1 - Special Products', 'description' => 'Store 1 - Special Products', 'link' => 'http://magento.com/rss/feed/index/type/special_products/store_id/1', 'charset' => 'UTF-8', 'language' => 'en_US', 'entries' => [['title' => 'Product Name', 'link' => 'http://magento.com/product-name.html']]]; $rssData = $this->block->getRssData(); $description = $rssData['entries'][0]['description']; unset($rssData['entries'][0]['description']); $this->assertEquals($data, $rssData); $this->assertContains('<a href="http://magento.com/product-name.html"><', $description); $this->assertContains(sprintf('<p>Price: Special Price: 10<br />Special Expires On: %s</p>', date('Y-m-d')), $description); $this->assertContains('<img src="image_link" alt="" border="0" align="left" height="75" width="75" />', $description); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @return void */ protected function setUp() { $this->zendDbMock = $this->getMockBuilder('Zend_Db_Statement_Interface')->getMock(); $this->zendDbMock->expects($this->any())->method('fetchColumn')->willReturn([]); $this->selectMock = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->setMethods(['from', 'where', 'joinInner', 'joinLeft', 'having', 'useStraightJoin', 'insertFromSelect', '__toString'])->getMock(); $this->selectMock->expects($this->any())->method('from')->willReturnSelf(); $this->selectMock->expects($this->any())->method('where')->willReturnSelf(); $this->selectMock->expects($this->any())->method('joinInner')->willReturnSelf(); $this->selectMock->expects($this->any())->method('joinLeft')->willReturnSelf(); $this->selectMock->expects($this->any())->method('having')->willReturnSelf(); $this->selectMock->expects($this->any())->method('useStraightJoin')->willReturnSelf(); $this->selectMock->expects($this->any())->method('insertFromSelect')->willReturnSelf(); $this->selectMock->expects($this->any())->method('__toString')->willReturn('string'); $this->connectionMock = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->getMock(); $this->connectionMock->expects($this->any())->method('select')->willReturn($this->selectMock); $this->connectionMock->expects($this->any())->method('query')->willReturn($this->zendDbMock); $this->resourceMock = $this->getMockBuilder('Magento\\Framework\\App\\Resource')->disableOriginalConstructor()->getMock(); $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock); $this->resourceMock->expects($this->any())->method('getTableName')->will($this->returnCallback(function ($arg) { return $arg; })); $this->contextMock = $this->getMockBuilder('Magento\\Framework\\Model\\Resource\\Db\\Context')->disableOriginalConstructor()->getMock(); $this->contextMock->expects($this->any())->method('getResources')->willReturn($this->resourceMock); $this->loggerMock = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->getMock(); $dateTime = $this->getMockBuilder('DateTime')->getMock(); $this->timezoneMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->getMock(); $this->timezoneMock->expects($this->any())->method('scopeDate')->willReturn($dateTime); $this->dateTimeMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime')->getMock(); $this->flagMock = $this->getMockBuilder('Magento\\Reports\\Model\\Flag')->disableOriginalConstructor()->setMethods(['setReportFlagCode', 'unsetData', 'loadSelf', 'setFlagData', 'setLastUpdate', 'save'])->getMock(); $this->flagFactoryMock = $this->getMockBuilder('Magento\\Reports\\Model\\FlagFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->flagFactoryMock->expects($this->any())->method('create')->willReturn($this->flagMock); $this->validatorMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\Timezone\\Validator')->disableOriginalConstructor()->getMock(); $this->backendMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\AbstractBackend')->disableOriginalConstructor()->getMock(); $this->attributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute')->disableOriginalConstructor()->getMock(); $this->attributeMock->expects($this->any())->method('getBackend')->willReturn($this->backendMock); $this->productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Resource\\Product')->disableOriginalConstructor()->getMock(); $this->productMock->expects($this->any())->method('getAttribute')->willReturn($this->attributeMock); $this->helperMock = $this->getMockBuilder('Magento\\Reports\\Model\\Resource\\Helper')->disableOriginalConstructor()->getMock(); $this->viewed = new Viewed($this->contextMock, $this->loggerMock, $this->timezoneMock, $this->flagFactoryMock, $this->dateTimeMock, $this->validatorMock, $this->productMock, $this->helperMock); }
/** * Prepare the timezone mock to expect calls and return formatted date and time * * @return none */ private function setupTimezoneMock() { $this->timezoneMock->expects($this->at(0))->method('formatDateTime')->with($this->isInstanceOf('\\DateTime'), \IntlDateFormatter::MEDIUM, \IntlDateFormatter::NONE, null, null, null)->willReturn(self::FORMATTED_DATE); $this->timezoneMock->expects($this->at(1))->method('formatDateTime')->with($this->isInstanceOf('\\DateTime'), \IntlDateFormatter::NONE, \IntlDateFormatter::MEDIUM, null, null, null)->willReturn(self::FORMATTED_TIME); }
/** * @param string $timeString * @dataProvider dataProviderTime */ public function testFormatDateTime($timeString) { $time = new \DateTime($timeString); $this->localeDate->expects($this->any())->method('formatDateTime')->with($time, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::MEDIUM)->willReturn($time); $this->assertEquals($time, $this->block->formatDateTime($timeString)); }