public function testSetNotIntStoreId() { $this->_storeManagerInterface->expects($this->once())->method('getStore'); $store = $this->_model->setStoreId('test'); $storeId = $store->getStoreId(); $this->assertEquals(0, $storeId); }
/** * Test for getAllOptions method * * @param $cachedDataSrl * @param $cachedDataUnsrl * * @dataProvider testGetAllOptionsDataProvider */ public function testGetAllOptions($cachedDataSrl, $cachedDataUnsrl) { $this->storeMock->expects($this->once())->method('getCode')->will($this->returnValue('store_code')); $this->storeManagerMock->expects($this->once())->method('getStore')->will($this->returnValue($this->storeMock)); $this->cacheConfig->expects($this->once())->method('load')->with($this->equalTo('COUNTRYOFMANUFACTURE_SELECT_STORE_store_code'))->will($this->returnValue($cachedDataSrl)); $countryOfManufacture = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\Product\\Attribute\\Source\\Countryofmanufacture', ['storeManager' => $this->storeManagerMock, 'configCacheType' => $this->cacheConfig]); $this->assertEquals($cachedDataUnsrl, $countryOfManufacture->getAllOptions()); }
public function testConvertWithStoreCode() { $amount = 5.6; $storeCode = 2; $convertedAmount = 9.300000000000001; $currency = $this->getCurrentCurrencyMock(); $baseCurrency = $this->getBaseCurrencyMock($amount, $convertedAmount, $currency); $store = $this->getStoreMock($baseCurrency); $this->storeManager->expects($this->once())->method('getStore')->with($storeCode)->will($this->returnValue($store)); $this->assertEquals($convertedAmount, $this->priceCurrency->convert($amount, $storeCode, $currency)); }
/** * @param array $quoteDetailsData * @param array $taxDetailsData * @param string $calculateCallback Name of a function within this test class which will be executed to create * a tax details item. * @return void * @dataProvider calculateTaxProvider */ public function testCalculateTax($quoteDetailsData, $taxDetailsData, $calculateCallback = 'createTaxDetailsItem') { $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($storeMock)); $calculatorMock = $this->getMockBuilder('\\Magento\\Tax\\Model\\Calculation\\AbstractCalculator')->disableOriginalConstructor()->setMethods(['calculate'])->getMockForAbstractClass(); $this->calculatorFactory->expects($this->any())->method('create')->will($this->returnValue($calculatorMock)); $calculatorMock->expects($this->any())->method('calculate')->will($this->returnCallback([$this, $calculateCallback])); $quoteDetails = $this->quoteDetailsBuilder->populateWithArray($quoteDetailsData)->create(); $taxDetails = $this->taxCalculationService->calculateTax($quoteDetails); $this->assertEquals($taxDetailsData, $taxDetails->__toArray()); }
public function testBeforeSave() { $websiteId = 1; $object = $this->getMockBuilder('Magento\\Framework\\Object')->disableOriginalConstructor()->setMethods(array('hasData', 'setData'))->getMock(); $store = $this->getMockBuilder('Magento\\Framework\\Object')->setMethods(array('getWebsiteId'))->getMock(); $store->expects($this->once())->method('getWebsiteId')->will($this->returnValue($websiteId)); $this->storeManager->expects($this->once())->method('getStore')->will($this->returnValue($store)); $object->expects($this->once())->method('hasData')->with('website_id')->will($this->returnValue(false)); $object->expects($this->once())->method('setData')->with($this->logicalOr('website_id', $websiteId))->will($this->returnSelf()); /** @var \Magento\Framework\Object $object */ $this->assertInstanceOf('Magento\\Customer\\Model\\Customer\\Attribute\\Backend\\Website', $this->testable->beforeSave($object)); }
public function testGetCollection() { $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue(new \Magento\Framework\Object(array('id' => 42)))); $this->currentCustomer->expects($this->any())->method('getCustomerId')->will($this->returnValue(4242)); $this->collection->expects($this->any())->method('addStoreFilter')->with(42)->will($this->returnValue($this->collection)); $this->collection->expects($this->any())->method('addCustomerFilter')->with(4242)->will($this->returnValue($this->collection)); $this->collection->expects($this->any())->method('setDateOrder')->with()->will($this->returnValue($this->collection)); $this->collection->expects($this->any())->method('setPageSize')->with(5)->will($this->returnValue($this->collection)); $this->collection->expects($this->any())->method('load')->with()->will($this->returnValue($this->collection)); $this->collection->expects($this->any())->method('addReviewSummary')->with()->will($this->returnValue($this->collection)); $this->assertSame($this->collection, $this->object->getCollection()); }
protected function setUp() { $this->_storeManagerMock = $this->getMockBuilder('Magento\\Store\\Model\\StoreManager')->disableOriginalConstructor()->getMock(); $this->_storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $this->_areaListMock = $this->getMock('Magento\\Framework\\App\\AreaList', array(), array(), '', false); $this->_configScopeMock = $this->getMock('Magento\\Framework\\Config\\ScopeInterface'); $this->_storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($this->_storeMock)); $this->_requestMock = $this->getMockBuilder('Magento\\Webapi\\Controller\\Soap\\Request')->disableOriginalConstructor()->getMock(); $this->_domDocumentFactory = $this->getMockBuilder('Magento\\Framework\\DomDocument\\Factory')->disableOriginalConstructor()->getMock(); $this->_soapServerFactory = $this->getMockBuilder('Magento\\Webapi\\Model\\Soap\\Server\\Factory')->disableOriginalConstructor()->getMock(); $this->_typeProcessor = $this->getMock('Magento\\Webapi\\Model\\Config\\ClassReflector\\TypeProcessor', array(), array(), '', false); $this->_configMock = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface'); parent::setUp(); }
protected function setUp() { $this->entityFactoryMock = $this->getMock('Magento\\Core\\Model\\EntityFactory', [], [], '', false); $this->loggerMock = $this->getMock('Magento\\Framework\\Logger', [], [], '', false); $this->fetchStrategyMock = $this->getMock('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategyInterface'); $this->managerInterfaceMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface'); $this->configMock = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false); $this->resourceMock = $this->getMock('Magento\\Framework\\App\\Resource', [], [], '', false); $this->entityFactoryMock2 = $this->getMock('Magento\\Eav\\Model\\EntityFactory'); $this->helperMock = $this->getMock('Magento\\Catalog\\Model\\Resource\\Helper', [], [], '', false); $entity = $this->getMock('Magento\\Eav\\Model\\Entity\\AbstractEntity', [], [], '', false); $adapter = $this->getMockForAbstractClass('Zend_Db_Adapter_Abstract', [], '', false); $entity->expects($this->any())->method('getReadConnection')->will($this->returnValue($adapter)); $entity->expects($this->any())->method('getDefaultAttributes')->will($this->returnValue([])); $this->universalFactoryMock = $this->getMock('Magento\\Framework\\Validator\\UniversalFactory', [], [], '', false); $this->universalFactoryMock->expects($this->any())->method('create')->will($this->returnValue($entity)); $this->storeManagerMock = $this->getMockForAbstractClass('Magento\\Framework\\StoreManagerInterface'); $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnCallback(function ($store) { return is_object($store) ? $store : new \Magento\Framework\Object(array('id' => 42)); })); $this->catalogHelperMock = $this->getMock('Magento\\Catalog\\Helper\\Data', [], [], '', false); $this->stateMock = $this->getMock('Magento\\Catalog\\Model\\Indexer\\Product\\Flat\\State', [], [], '', false); $this->scopeConfigInterfaceMock = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface'); $this->optionFactoryMock = $this->getMock('Magento\\Catalog\\Model\\Product\\OptionFactory'); $this->urlMock = $this->getMock('Magento\\Catalog\\Model\\Resource\\Url', [], [], '', false); $this->timezoneInterfaceMock = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface'); $this->sessionMock = $this->getMock('Magento\\Customer\\Model\\Session', [], [], '', false); $this->dateTimeMock = $this->getMock('Magento\\Framework\\Stdlib\\DateTime'); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->collection = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\Resource\\Product\\Link\\Product\\Collection', ['entityFactory' => $this->entityFactoryMock, 'logger' => $this->loggerMock, 'fetchStrategy' => $this->fetchStrategyMock, 'eventManager' => $this->managerInterfaceMock, 'eavConfig' => $this->configMock, 'resource' => $this->resourceMock, 'eavEntityFactory' => $this->entityFactoryMock2, 'resourceHelper' => $this->helperMock, 'universalFactory' => $this->universalFactoryMock, 'storeManager' => $this->storeManagerMock, 'catalogData' => $this->catalogHelperMock, 'catalogProductFlatState' => $this->stateMock, 'scopeConfig' => $this->scopeConfigInterfaceMock, 'productOptionFactory' => $this->optionFactoryMock, 'catalogUrl' => $this->urlMock, 'localeDate' => $this->timezoneInterfaceMock, 'customerSession' => $this->sessionMock, 'dateTime' => $this->dateTimeMock]); }
public function testPrepareJsonAttributes() { $options = []; $attributeId = 1; $attributeCode = 'test_attribute'; $attributeLabel = 'Test'; $pricingValue = 100; $amount = 120; $modifiedValue = 140; $valueIndex = 2; $optionId = 1; $expected = ['priceOptions' => [$attributeId => ['id' => $attributeId, 'code' => $attributeCode, 'label' => $attributeLabel, 'options' => [0 => ['id' => $valueIndex, 'label' => $attributeLabel, 'price' => $modifiedValue, 'oldPrice' => $modifiedValue, 'inclTaxPrice' => $modifiedValue, 'exclTaxPrice' => $pricingValue, 'products' => []]]]], 'defaultValues' => [$attributeId => $optionId]]; $attributePrices = [['is_percent' => false, 'pricing_value' => $pricingValue, 'value_index' => $valueIndex, 'label' => $attributeLabel]]; $configurableAttributes = [$this->getAttributeMock($attributeId, $attributeCode, $attributeLabel, $attributePrices)]; $configuredValueMock = $this->getMockBuilder('Magento\\Framework\\Object')->disableOriginalConstructor()->getMock(); $configuredValueMock->expects($this->any())->method('getData')->will($this->returnValue($optionId)); $configurableProduct = $this->getMockBuilder('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable')->disableOriginalConstructor()->getMock(); $configurableProduct->expects($this->once())->method('getConfigurableAttributes')->with($this->equalTo($this->saleableItemMock))->will($this->returnValue($configurableAttributes)); $this->saleableItemMock->expects($this->once())->method('getTypeInstance')->will($this->returnValue($configurableProduct)); $this->saleableItemMock->expects($this->any())->method('setParentId'); $this->saleableItemMock->expects($this->any())->method('hasPreconfiguredValues')->will($this->returnValue(true)); $this->saleableItemMock->expects($this->any())->method('getPreconfiguredValues')->will($this->returnValue($configuredValueMock)); $this->priceModifier->expects($this->once())->method('modifyPrice')->with($this->equalTo($pricingValue), $this->equalTo($this->saleableItemMock))->will($this->returnValue($amount)); $this->calculatorMock->expects($this->any())->method('getAmount')->will($this->returnValue($this->getModifiedAmountMock($modifiedValue, $pricingValue))); $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $this->priceCurrency->expects($this->once())->method('convert')->with($this->equalTo($modifiedValue))->will($this->returnArgument(0)); $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock)); $result = $this->attribute->prepareAttributes($options); $this->assertEquals($expected, $result); }
protected function setUp() { $helper = new ObjectManager($this); $this->category = $this->getMockBuilder('Magento\\Catalog\\Model\\Category')->setMethods(['load', 'getId', '__wakeup'])->disableOriginalConstructor()->getMock(); $this->categoryFactory = $this->getMockBuilder('Magento\\Catalog\\Model\\CategoryFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock(); $this->categoryFactory->expects($this->any())->method('create')->will($this->returnValue($this->category)); $this->registry = $this->getMockBuilder('Magento\\Framework\\Registry')->setMethods(['registry'])->disableOriginalConstructor()->getMock(); $this->store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->setMethods(['getRootCategoryId', 'getFilters', '__wakeup'])->disableOriginalConstructor()->getMockForAbstractClass(); $this->storeManager = $this->getMockBuilder('Magento\\Framework\\StoreManagerInterface')->setMethods(['getStore'])->disableOriginalConstructor()->getMockForAbstractClass(); $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($this->store)); $this->stateKeyGenerator = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\Category\\StateKey')->setMethods(['toString'])->disableOriginalConstructor()->getMock(); $this->collectionFilter = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\Category\\CollectionFilter')->setMethods(['filter'])->disableOriginalConstructor()->getMock(); $this->collectionProvider = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\ItemCollectionProviderInterface')->disableOriginalConstructor()->getMockForAbstractClass(); $this->filter = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\Filter\\Item')->setMethods(['getFilter', 'getValueString'])->disableOriginalConstructor()->getMock(); $this->abstractFilter = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\Filter\\AbstractFilter')->setMethods(['getRequestVar'])->disableOriginalConstructor()->getMock(); $this->context = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\ContextInterface')->setMethods(['getStateKey', 'getCollectionFilter'])->disableOriginalConstructor()->getMockForAbstractClass(); $this->context->expects($this->any())->method('getStateKey')->will($this->returnValue($this->stateKeyGenerator)); $this->context->expects($this->any())->method('getCollectionFilter')->will($this->returnValue($this->collectionFilter)); $this->context->expects($this->any())->method('getCollectionProvider')->will($this->returnValue($this->collectionProvider)); $this->state = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\State')->disableOriginalConstructor()->getMock(); $this->stateFactory = $this->getMockBuilder('Magento\\Catalog\\Model\\Layer\\StateFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock(); $this->stateFactory->expects($this->any())->method('create')->will($this->returnValue($this->state)); $this->collection = $this->getMockBuilder('Magento\\Catalog\\Model\\Resource\\Product\\Collection')->disableOriginalConstructor()->getMock(); $this->model = $helper->getObject('Magento\\Catalog\\Model\\Layer', ['registry' => $this->registry, 'categoryFactory' => $this->categoryFactory, 'storeManager' => $this->storeManager, 'context' => $this->context, 'layerStateFactory' => $this->stateFactory]); }
public function setUp() { $this->request = $this->getMock('Magento\\Framework\\App\\RequestInterface'); $this->response = $this->getMock('Magento\\Framework\\App\\ResponseInterface'); $this->categoryHelper = $this->getMock('Magento\\Catalog\\Helper\\Category', [], [], '', false); $this->objectManager = $this->getMock('Magento\\Framework\\ObjectManager', [], [], '', false); $this->eventManager = $this->getMock('Magento\\Framework\\Event\\ManagerInterface'); $this->update = $this->getMock('Magento\\Framework\\View\\Layout\\ProcessorInterface'); $this->layout = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false); $this->layout->expects($this->any())->method('getUpdate')->will($this->returnValue($this->update)); $this->pageConfig = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config')->disableOriginalConstructor()->getMock(); $this->pageConfig->expects($this->any())->method('addBodyClass')->will($this->returnSelf()); $this->page = $this->getMockBuilder('Magento\\Framework\\View\\Page')->setMethods(['getConfig', 'initLayout'])->disableOriginalConstructor()->getMock(); $this->page->expects($this->any())->method('getConfig')->will($this->returnValue($this->pageConfig)); $this->view = $this->getMock('Magento\\Framework\\App\\ViewInterface'); $this->view->expects($this->any())->method('getLayout')->will($this->returnValue($this->layout)); $this->view->expects($this->any())->method('getPage')->will($this->returnValue($this->page)); $this->context = $this->getMock('Magento\\Backend\\App\\Action\\Context', [], [], '', false); $this->context->expects($this->any())->method('getRequest')->will($this->returnValue($this->request)); $this->context->expects($this->any())->method('getResponse')->will($this->returnValue($this->response)); $this->context->expects($this->any())->method('getObjectManager')->will($this->returnValue($this->objectManager)); $this->context->expects($this->any())->method('getEventManager')->will($this->returnValue($this->eventManager)); $this->context->expects($this->any())->method('getView')->will($this->returnValue($this->view)); $this->category = $this->getMock('Magento\\Catalog\\Model\\Category', [], [], '', false); $this->categoryFactory = $this->getMock('Magento\\Catalog\\Model\\CategoryFactory', ['create'], [], '', false); $this->store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false); $this->storeManager = $this->getMock('Magento\\Framework\\StoreManagerInterface'); $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($this->store)); $this->catalogDesign = $this->getMock('Magento\\Catalog\\Model\\Design', [], [], '', false); $this->layoutHelper = $this->getMock('Magento\\Theme\\Helper\\Layout', [], [], '', false); $this->action = (new ObjectManager($this))->getObject('Magento\\Catalog\\Controller\\Category\\View', ['context' => $this->context, 'catalogDesign' => $this->catalogDesign, 'categoryFactory' => $this->categoryFactory, 'storeManager' => $this->storeManager]); }
/** * @covers \Magento\Theme\Model\Config\Customization::isThemeAssignedToStore */ public function testIsThemeAssignedToDefaultStore() { $this->_storeManager->expects($this->once())->method('getStores')->will($this->returnValue(array($this->_getStore()))); $this->_designPackage->expects($this->once())->method('getConfigurationDesignTheme')->will($this->returnValue($this->_getAssignedTheme()->getId())); $this->themeProviderMock->expects($this->once())->method('getThemeCustomizations')->with(\Magento\Framework\App\Area::AREA_FRONTEND)->will($this->returnValue(array($this->_getAssignedTheme(), $this->_getUnassignedTheme()))); $themeAssigned = $this->_model->isThemeAssignedToStore($this->_getAssignedTheme()); $this->assertEquals(true, $themeAssigned); }
public function testAddReviewItemXmlCallback() { $row = ['entity_id' => 1, 'store_id' => 2, 'review_id' => 3, 'name' => 'Product Name', 'title' => 'Review Summary', 'detail' => 'Test of a review', 'nickname' => 'User Name']; $productUrl = 'http://product.url'; $reviewUrl = 'http://review.url'; $reviewModel = $this->getMock('Magento\\Review\\Model\\Review', [], [], '', false); $reviewModel->expects($this->once())->method('getProductUrl')->with($this->equalTo($row['entity_id']), $this->equalTo($row['store_id']))->will($this->returnValue($productUrl)); $this->urlInterfaceMock->expects($this->once())->method('getUrl')->with($this->equalTo('review/product/edit/'), $this->equalTo(array('id' => $row['review_id'], '_secure' => true, '_nosecret' => true)))->will($this->returnValue($reviewUrl)); $storeName = 'Store Name'; $this->storeManagerMock->expects($this->once())->method('getStore')->with($this->equalTo($row['store_id']))->will($this->returnSelf()); $this->storeManagerMock->expects($this->once())->method('getName')->will($this->returnValue($storeName)); $rssObj = $this->getMock('Magento\\Rss\\Model\\Rss', [], [], '', false); $description = '<p>' . __('Product: <a href="%1" target="_blank">%2</a> <br/>', $productUrl, $row['name']) . __('Summary of review: %1 <br/>', $row['title']) . __('Review: %1 <br/>', $row['detail']) . __('Store: %1 <br/>', $storeName) . __('Click <a href="%1">here</a> to view the review.', $reviewUrl) . '</p>'; $rssObj->expects($this->once())->method('_addEntry')->with($this->equalTo(['title' => __('Product: "%1" reviewed by: %2', $row['name'], $row['nickname']), 'link' => 'test', 'description' => $description]))->will($this->returnSelf()); $args = ['row' => $row, 'reviewModel' => $reviewModel, 'rssObj' => $rssObj]; $this->assertNull($this->review->addReviewItemXmlCallback($args)); }
protected function setUp() { $this->_consumerFactory = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Consumer\\Factory')->disableOriginalConstructor()->getMock(); $this->_consumerMock = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Consumer')->disableOriginalConstructor()->getMock(); $this->_consumerFactory->expects($this->any())->method('create')->will($this->returnValue($this->_consumerMock)); $this->_tokenFactory = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Token\\Factory')->disableOriginalConstructor()->getMock(); $this->_tokenMock = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Token')->disableOriginalConstructor()->getMock(); $this->_tokenFactory->expects($this->any())->method('create')->will($this->returnValue($this->_tokenMock)); $this->_storeManagerMock = $this->getMockBuilder('Magento\\Framework\\StoreManagerInterface')->disableOriginalConstructor()->getMockForAbstractClass(); $this->_storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $this->_storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($this->_storeMock)); $this->_dataHelper = $this->getMockBuilder('Magento\\Integration\\Helper\\Oauth\\Data')->disableOriginalConstructor()->getMock(); $oauthHelperMock = $this->getMockBuilder('Magento\\Framework\\Oauth\\Helper\\Oauth')->disableOriginalConstructor()->getMock(); $tokenProviderMock = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Token\\Provider')->disableOriginalConstructor()->getMock(); $this->_httpClientMock = $this->getMockBuilder('Magento\\Framework\\HTTP\\ZendClient')->disableOriginalConstructor()->getMock(); $this->_loggerMock = $this->getMockBuilder('Magento\\Framework\\Logger')->disableOriginalConstructor()->setMethods(array('logException'))->getMock(); $this->_oauthService = new \Magento\Integration\Service\V1\Oauth($this->_storeManagerMock, $this->_consumerFactory, $this->_tokenFactory, $this->_dataHelper, $this->_httpClientMock, $this->_loggerMock, $oauthHelperMock, $tokenProviderMock); }
/** * @param int|null $storeId * @param bool $result * @dataProvider isAvailableOnStoreDataProvider */ public function testIsAvailableOnStore($storeId, $result) { $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false); if ($storeId) { $store->expects($this->once())->method('getId')->will($this->returnValue($storeId)); $this->storeManagerMock->expects($this->once())->method('getStore')->with($this->equalTo($store))->will($this->returnValue($store)); } $this->assertSame($result, $this->review->isAvailableOnStore($store)); }
protected function setUp() { $this->_soapConfigMock = $this->getMockBuilder('Magento\\Webapi\\Model\\Soap\\Config')->disableOriginalConstructor()->getMock(); $_wsdlMock = $this->getMockBuilder('Magento\\Webapi\\Model\\Soap\\Wsdl')->disableOriginalConstructor()->setMethods(array('addSchemaTypeSection', 'addService', 'addPortType', 'addBinding', 'addSoapBinding', 'addElement', 'addComplexType', 'addMessage', 'addPortOperation', 'addBindingOperation', 'addSoapOperation', 'toXML'))->getMock(); $this->_wsdlFactoryMock = $this->getMockBuilder('Magento\\Webapi\\Model\\Soap\\Wsdl\\Factory')->setMethods(array('create'))->disableOriginalConstructor()->getMock(); $this->_wsdlFactoryMock->expects($this->any())->method('create')->will($this->returnValue($_wsdlMock)); $this->_cacheMock = $this->getMockBuilder('Magento\\Webapi\\Model\\Cache\\Type')->disableOriginalConstructor()->getMock(); $this->_cacheMock->expects($this->any())->method('load')->will($this->returnValue(false)); $this->_cacheMock->expects($this->any())->method('save')->will($this->returnValue(true)); $this->_typeProcessor = $this->getMock('Magento\\Webapi\\Model\\Config\\ClassReflector\\TypeProcessor', array(), array(), '', false); $this->storeManagerMock = $this->getMockBuilder('Magento\\Framework\\StoreManagerInterface')->setMethods(['getStore'])->disableOriginalConstructor()->getMockForAbstractClass(); $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->setMethods(['getCode', '__wakeup'])->disableOriginalConstructor()->getMock(); $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock)); $storeMock->expects($this->any())->method('getCode')->will($this->returnValue('store_code')); $helper = new \Magento\TestFramework\Helper\ObjectManager($this); $this->_wsdlGenerator = $helper->getObject('Magento\\Webapi\\Model\\Soap\\Wsdl\\Generator', ['apiConfig' => $this->_soapConfigMock, 'wsdlFactory' => $this->_wsdlFactoryMock, 'cache' => $this->_cacheMock, 'typeProcessor' => $this->_typeProcessor, 'storeManagerMock' => $this->storeManagerMock]); parent::setUp(); }
/** * Initialize store manager mock with expected store IDs * * @param array $storeIds */ protected function _setStoreManagerExpectedStores(array $storeIds) { $stores = array(); foreach ($storeIds as $storeId) { $store = $this->getMock('Magento\\Store\\Model\\Store', array('getId', '__sleep', '__wakeup'), array(), '', false); $store->expects($this->once())->method('getId')->will($this->returnValue($storeId)); $stores[] = $store; } $this->_storeManagerMock->expects($this->once())->method('getStores')->will($this->returnValue($stores)); }
protected function setUp() { $this->_storeManagerMock = $this->getMockBuilder('Magento\\Store\\Model\\StoreManager')->disableOriginalConstructor()->getMock(); $this->_storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $this->_storeMock->expects($this->any())->method('getBaseUrl')->will($this->returnValue('http://magento.com/')); $this->_storeMock->expects($this->any())->method('getCode')->will($this->returnValue('storeCode')); $this->_storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($this->_storeMock)); $areaListMock = $this->getMock('Magento\\Framework\\App\\AreaList', array(), array(), '', false); $configScopeMock = $this->getMock('Magento\\Framework\\Config\\ScopeInterface'); $areaListMock->expects($this->any())->method('getFrontName')->will($this->returnValue('soap')); $this->_requestMock = $this->getMockBuilder('Magento\\Webapi\\Controller\\Soap\\Request')->disableOriginalConstructor()->getMock(); $this->_domDocumentFactory = $this->getMockBuilder('Magento\\Framework\\DomDocument\\Factory')->disableOriginalConstructor()->getMock(); $this->_soapServerFactory = $this->getMockBuilder('Magento\\Webapi\\Model\\Soap\\Server\\Factory')->disableOriginalConstructor()->getMock(); $this->_typeProcessor = $this->getMock('Magento\\Webapi\\Model\\Config\\ClassReflector\\TypeProcessor', array(), array(), '', false); $this->_scopeConfig = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface'); /** Init SUT. */ $this->_soapServer = new \Magento\Webapi\Model\Soap\Server($areaListMock, $configScopeMock, $this->_requestMock, $this->_domDocumentFactory, $this->_storeManagerMock, $this->_soapServerFactory, $this->_typeProcessor, $this->_scopeConfig); parent::setUp(); }
public function setUp() { $this->registry = $this->getMock('Magento\\Framework\\Registry'); $this->sessionManagerInterface = $this->getMock('Magento\\Framework\\Session\\SessionManagerInterface'); $this->storeManagerInterface = $this->getMock('Magento\\Framework\\StoreManagerInterface'); $this->header = $this->getMock('Magento\\Framework\\HTTP\\Header', [], [], '', false); $this->remoteAddress = $this->getMock('Magento\\Framework\\HTTP\\PhpEnvironment\\RemoteAddress', [], [], '', false); $this->serverAddress = $this->getMock('Magento\\Framework\\HTTP\\PhpEnvironment\\ServerAddress', [], [], '', false); $this->dateTime = $this->getMock('Magento\\Framework\\Stdlib\\DateTime'); $store = $this->getMock('\\Magento\\Store\\Model\\Store', [], [], '', false, false); $this->storeManagerInterface->expects($this->any())->method('getStore')->will($this->returnValue($store)); $this->dateTime->expects($this->any())->method('now')->will($this->returnValue(time())); $resource = $this->getMockBuilder('Magento\\Customer\\Model\\Resource\\Visitor')->setMethods(['beginTransaction', '__sleep', '__wakeup', 'getIdFieldName', 'save', 'addCommitCallback', 'commit'])->disableOriginalConstructor()->getMock(); $resource->expects($this->any())->method('getIdFieldName')->will($this->returnValue('visitor_id')); $resource->expects($this->any())->method('addCommitCallback')->will($this->returnSelf()); $objectManagerHelper = new ObjectManagerHelper($this); $arguments = $objectManagerHelper->getConstructArguments('Magento\\Log\\Model\\Visitor', ['registry' => $this->registry, 'session' => $this->sessionManagerInterface, 'storeManager' => $this->storeManagerInterface, 'httpHeader' => $this->header, 'remoteAddress' => $this->remoteAddress, 'serverAddress' => $this->serverAddress, 'dateTime' => $this->dateTime, 'resource' => $resource]); $this->visitor = $objectManagerHelper->getObject('Magento\\Log\\Model\\Visitor', $arguments); }
/** * @param int $storeId * @param int $managerStoreId * @param int $expected * @dataProvider getStoreIdDataProvider */ public function testGetStoreId($storeId, $managerStoreId, $expected) { if ($storeId) { $this->setDataArrayValue('store_id', $storeId); } else { $storeManager = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false); $storeManager->expects($this->once())->method('getId')->will($this->returnValue($managerStoreId)); $this->storeManager->expects($this->once())->method('getStore')->will($this->returnValue($storeManager)); } $this->assertSame($expected, $this->item->getStoreId()); }
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 dataProviderCallbackValidateProduct * @param bool $validate */ public function testCallbackValidateProduct($validate) { $args['product'] = $this->productModel; $args['attributes'] = array(); $args['idx'] = 0; $args['row'] = array('entity_id' => '1', 'entity_type_id' => '4', 'attribute_set_id' => '4', 'type_id' => 'simple', 'sku' => 'Product', 'has_options' => '0', 'required_options' => '0', 'created_at' => '2014-06-25 13:14:30', 'updated_at' => '2014-06-25 14:37:15'); $this->storeManager->expects($this->any())->method('getWebsites')->with(true)->will($this->returnValue(array($this->websiteModel, $this->websiteModel))); $this->websiteModel->expects($this->at(0))->method('getId')->will($this->returnValue('1')); $this->websiteModel->expects($this->at(2))->method('getId')->will($this->returnValue('2')); $this->websiteModel->expects($this->any())->method('getDefaultStore')->will($this->returnValue($this->storeModel)); $this->storeModel->expects($this->at(0))->method('getId')->will($this->returnValue('1')); $this->storeModel->expects($this->at(1))->method('getId')->will($this->returnValue('2')); $this->combineFactory->expects($this->any())->method('create')->will($this->returnValue($this->condition)); $this->condition->expects($this->any())->method('validate')->will($this->returnValue($validate)); $this->condition->expects($this->any())->method('setRule')->will($this->returnSelf()); $this->productModel->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->rule->callbackValidateProduct($args); $matchingProducts = $this->rule->getMatchingProductIds(); foreach ($matchingProducts['1'] as $matchingRules) { $this->assertEquals($validate, $matchingRules); } }
public function testGetConfigCanShowConfig() { $result = array('key1' => 'value1', 'key2' => 'value2'); $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $store->expects($this->any())->method('getWebsiteId')->will($this->returnValue('1')); $this->scopeConfig->expects($this->once())->method('getValue')->with('customer/address', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store)->will($this->returnValue($result)); $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store)); $this->assertNull($this->helper->getConfig('unavailable_key')); $this->assertFalse($this->helper->canShowConfig('unavailable_key')); $this->assertEquals($result['key1'], $this->helper->getConfig('key1')); $this->assertEquals($result['key2'], $this->helper->getConfig('key2')); $this->assertTrue($this->helper->canShowConfig('key1')); $this->assertTrue($this->helper->canShowConfig('key2')); }
protected function setUp() { $this->entityFactoryMock = $this->getMock('Magento\\Core\\Model\\EntityFactory', array(), array(), '', false); $this->loggerMock = $this->getMock('Magento\\Framework\\Logger', array(), array(), '', false); $this->fetchStrategyMock = $this->getMock('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategyInterface'); $this->eventManagerMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface'); $this->eavConfigMock = $this->getMock('Magento\\Eav\\Model\\Config', array(), array(), '', false); $this->entityTypeMock = $this->getMock('Magento\\Eav\\Model\\Entity\\Type', array('__wakeup'), array(), '', false); $this->entityTypeMock->setAdditionalAttributeTable('some_extra_table'); $this->eavConfigMock->expects($this->any())->method('getEntityType')->will($this->returnValue($this->entityTypeMock)); $this->storeManagerMock = $this->getMock('Magento\\Framework\\StoreManagerInterface'); $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnSelf()); $adapter = $this->getMockForAbstractClass('Zend_Db_Adapter_Abstract', array(), '', false); $this->selectMock = $this->getMock('Zend_Db_Select', null, array($adapter)); $this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', array('select', 'describeTable', 'quoteIdentifier', '_connect', '_quote'), array(), '', false); $this->resourceMock = $this->getMockForAbstractClass('Magento\\Framework\\Model\\Resource\\Db\\AbstractDb', array(), '', false, true, true, array('__wakeup', 'getReadConnection', 'getMainTable', 'getTable')); $this->connectionMock->expects($this->any())->method('select')->will($this->returnValue($this->selectMock)); $this->connectionMock->expects($this->any())->method('quoteIdentifier')->will($this->returnArgument(0)); $this->connectionMock->expects($this->any())->method('describeTable')->will($this->returnvalueMap(array(array('some_main_table', null, array('col1' => array(), 'col2' => array())), array('some_extra_table', null, array('col2' => array(), 'col3' => array())), array(null, null, array('col2' => array(), 'col3' => array(), 'col4' => array()))))); $this->connectionMock->expects($this->any())->method('_quote')->will($this->returnArgument(0)); $this->resourceMock->expects($this->any())->method('getReadConnection')->will($this->returnValue($this->connectionMock)); $this->resourceMock->expects($this->any())->method('getMainTable')->will($this->returnValue('some_main_table')); $this->resourceMock->expects($this->any())->method('getTable')->will($this->returnValue('some_extra_table')); }
public function testSetWatermark() { $website = $this->getMockBuilder('\\Magento\\Store\\Model\\Website')->disableOriginalConstructor()->setMethods(array('getId', '__sleep', '__wakeup'))->getMock(); $website->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->storeManager->expects($this->any())->method('getWebsite')->will($this->returnValue($website)); $this->mediaDirectory->expects($this->at(3))->method('isExist')->with('catalog/product/watermark//somefile.png')->will($this->returnValue(true)); $absolutePath = dirname(dirname(__DIR__)) . '/_files/catalog/product/watermark/somefile.png'; $this->mediaDirectory->expects($this->any())->method('getAbsolutePath')->with('catalog/product/watermark//somefile.png')->will($this->returnValue($absolutePath)); $imageProcessor = $this->getMockBuilder('Magento\\Framework\\Image')->disableOriginalConstructor()->setMethods(array('keepAspectRatio', 'keepFrame', 'keepTransparency', 'constrainOnly', 'backgroundColor', 'quality', 'setWatermarkPosition', 'setWatermarkImageOpacity', 'setWatermarkWidth', 'setWatermarkHeight', 'watermark'))->getMock(); $imageProcessor->expects($this->once())->method('setWatermarkPosition')->with('center')->will($this->returnValue(true)); $imageProcessor->expects($this->once())->method('setWatermarkImageOpacity')->with(50)->will($this->returnValue(true)); $imageProcessor->expects($this->once())->method('setWatermarkWidth')->with(100)->will($this->returnValue(true)); $imageProcessor->expects($this->once())->method('setWatermarkHeight')->with(100)->will($this->returnValue(true)); $this->image->setImageProcessor($imageProcessor); $result = $this->image->setWatermark('/somefile.png', 'center', array('width' => 100, 'height' => 100), 100, 100, 50); $this->assertSame($this->image, $result); }
/** * @dataProvider saveBillingDataProvider * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.ExcessiveParameterList) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function testSaveBilling($data, $customerAddressId, $quoteCustomerId, $addressCustomerId, $isAddress, $validateDataResult, $validateResult, $checkoutMethod, $customerPassword, $confirmPassword, $validationResultMessages, $isEmailAvailable, $isVirtual, $getStepDataResult, $expected) { $passwordHash = 'password hash'; $this->requestMock->expects($this->any())->method('isAjax')->will($this->returnValue(false)); $customerValidationResultMock = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\CustomerValidationResults', [], [], '', false); $customerValidationResultMock->expects($this->any())->method('isValid')->will($this->returnValue(empty($validationResultMessages))); $customerValidationResultMock->expects($this->any())->method('getMessages')->will($this->returnValue($validationResultMessages)); $this->customerAccountServiceMock->expects($this->any())->method('getPasswordHash')->with($customerPassword)->will($this->returnValue($passwordHash)); $this->customerAccountServiceMock->expects($this->any())->method('validateCustomerData')->will($this->returnValue($customerValidationResultMock)); $this->customerAccountServiceMock->expects($this->any())->method('isEmailAvailable')->will($this->returnValue($isEmailAvailable)); /** @var \Magento\Sales\Model\Quote|\PHPUnit_Framework_MockObject_MockObject $quoteMock */ $quoteMock = $this->getMock('Magento\\Sales\\Model\\Quote', ['getCustomerId', '__wakeup', 'getBillingAddress', 'setPasswordHash', 'getCheckoutMethod', 'isVirtual', 'getShippingAddress', 'getCustomerData', 'collectTotals', 'save'], [], '', false); $shippingAddressMock = $this->getMock('Magento\\Sales\\Model\\Quote\\Address', ['setSameAsBilling', '__wakeup', 'unserialize'], [], '', false); $shippingAddressMock->expects($this->any())->method('setSameAsBilling')->with((int) $data['use_for_shipping']); $quoteMock->expects($this->any())->method('setPasswordHash')->with($passwordHash); $quoteMock->expects($this->any())->method('getCheckoutMethod')->will($this->returnValue($checkoutMethod)); $quoteMock->expects($this->any())->method('isVirtual')->will($this->returnValue($isVirtual)); $quoteMock->expects($this->any())->method('getShippingAddress')->will($this->returnValue($shippingAddressMock)); $addressMock = $this->getMock('Magento\\Sales\\Model\\Quote\\Address', ['setSaveInAddressBook', 'getData', 'setEmail', '__wakeup', 'importCustomerAddressData', 'validate'], [], '', false); $addressMock->expects($this->any())->method('importCustomerAddressData')->will($this->returnSelf()); $addressMock->expects($this->atLeastOnce())->method('validate')->will($this->returnValue($validateResult)); $addressMock->expects($this->any())->method('getData')->will($this->returnValue([])); $quoteMock->expects($this->any())->method('getBillingAddress')->will($this->returnValue($addressMock)); $quoteMock->expects($this->any())->method('getCustomerId')->will($this->returnValue($quoteCustomerId)); $formMock = $this->getMock('Magento\\Customer\\Model\\Metadata\\Form', [], [], '', false); $formMock->expects($this->atLeastOnce())->method('validateData')->will($this->returnValue($validateDataResult)); $this->requestMock->expects($this->any())->method('getParam')->will($this->returnValueMap([['customer_password', $customerPassword], ['confirm_password', $confirmPassword]])); $formMock->expects($this->any())->method('prepareRequest')->will($this->returnValue($this->requestMock)); $this->customerFormFactoryMock->expects($this->any())->method('create')->will($this->returnValue($formMock)); $customerDataMock = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\Customer', [], [], '', false); $customerDataMock->expects($this->any())->method('__toArray')->will($this->returnValue([])); $this->customerBuilderMock->expects($this->any())->method('create')->will($this->returnValue($customerDataMock)); $quoteMock->expects($this->atLeastOnce())->method('getCustomerData')->will($this->returnValue($customerDataMock)); $this->checkoutSessionMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock)); $this->checkoutSessionMock->expects($this->any())->method('getStepData')->will($this->returnValue((int) $data['use_for_shipping'] === 1 ? true : $getStepDataResult)); $this->checkoutSessionMock->expects($this->any())->method('setStepData')->will($this->returnSelf()); $customerAddressMock = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\Address', [], [], '', false); $customerAddressMock->expects($this->any())->method('getCustomerId')->will($this->returnValue($addressCustomerId)); $this->customerAddressServiceMock->expects($this->any())->method('getAddress')->will($isAddress ? $this->returnValue($customerAddressMock) : $this->throwException(new \Exception())); $this->customerBuilderMock->expects($checkoutMethod === Onepage::METHOD_REGISTER ? $this->never() : $this->once())->method('populate'); $this->customerBuilderMock->expects($checkoutMethod === Onepage::METHOD_REGISTER ? $this->never() : $this->once())->method('setGroupId'); $websiteMock = $this->getMock('Magento\\Store\\Model\\Website', [], [], '', false); $this->storeManagerMock->expects($this->any())->method('getWebsite')->will($this->returnValue($websiteMock)); $this->assertEquals($expected, $this->onepage->saveBilling($data, $customerAddressId)); }
/** * @param string $expected * @param bool $dataObjectIsOrder * @param bool $isCurrencyDifferent * @param bool $magentoDataObjectHasOrder * @param bool $strong * @param string $separator * @dataProvider displayPricesDataProvider */ public function testDisplayPriceAttribute($expected, $dataObjectIsOrder, $isCurrencyDifferent = true, $magentoDataObjectHasOrder = true, $strong = false, $separator = '<br/>') { $this->orderMock->expects($this->any())->method('isCurrencyDifferent')->will($this->returnValue($isCurrencyDifferent)); $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock)); $this->priceCurrency->expects($this->any())->method('format')->will($this->returnValue('storeFormattedPrice')); $dataObject = $this->orderMock; if (!$dataObjectIsOrder) { $returnRes = false; if ($magentoDataObjectHasOrder) { $returnRes = $this->orderMock; } $this->magentoObjectMock->expects($this->once())->method('getOrder')->will($this->returnValue($returnRes)); $this->magentoObjectMock->expects($this->any())->method('getData')->will($this->returnValue('data')); $dataObject = $this->magentoObjectMock; } $this->assertEquals($expected, $this->adminHelper->displayPriceAttribute($dataObject, 'code', $strong, $separator)); }
public function testExecuteValidPost() { $post = ['name' => 'Name', 'comment' => 'Comment', 'email' => '*****@*****.**', 'hideit' => null]; $this->_request->expects($this->any())->method('getPost')->will($this->returnValue($post)); $store = $this->getMock('\\Magento\\Store\\Model\\Store', ['getId', '__sleep', '__wakeup'], [], '', false); $store->expects($this->once())->method('getId')->will($this->returnValue(1)); $this->_storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store)); $transport = $this->getMock('\\Magento\\Framework\\Mail\\TransportInterface', [], [], '', false); $this->_transportBuilder->expects($this->once())->method('setTemplateIdentifier')->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('setTemplateOptions')->with(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => 1])->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('setTemplateVars')->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('setFrom')->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('addTo')->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('setReplyTo')->with($post['email'])->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('getTransport')->will($this->returnValue($transport)); $transport->expects($this->once())->method('sendMessage'); $this->_inlineTranslation->expects($this->once())->method('resume'); $this->_inlineTranslation->expects($this->once())->method('suspend'); $this->_controller->execute(); }
public function testSendPasswordResetConfirmationEmail() { $storeId = 0; $email = '*****@*****.**'; $firstName = 'Foo'; $lastName = 'Bar'; $this->_model->setEmail($email); $this->_model->setFirstname($firstName); $this->_model->setLastname($lastName); $this->_configMock->expects($this->at(0))->method('getValue')->with(\Magento\User\Model\User::XML_PATH_FORGOT_EMAIL_TEMPLATE)->will($this->returnValue('templateId')); $this->_configMock->expects($this->at(1))->method('getValue')->with(\Magento\User\Model\User::XML_PATH_FORGOT_EMAIL_IDENTITY)->will($this->returnValue('sender')); $this->_transportBuilderMock->expects($this->once())->method('setTemplateOptions')->will($this->returnSelf()); $this->_transportBuilderMock->expects($this->once())->method('setTemplateVars')->with(array('user' => $this->_model, 'store' => $this->_storetMock))->will($this->returnSelf()); $this->_transportBuilderMock->expects($this->once())->method('addTo')->with($this->equalTo($email), $this->equalTo($firstName . ' ' . $lastName))->will($this->returnSelf()); $this->_transportBuilderMock->expects($this->once())->method('setFrom')->with('sender')->will($this->returnSelf()); $this->_transportBuilderMock->expects($this->once())->method('setTemplateIdentifier')->with('templateId')->will($this->returnSelf()); $this->_transportBuilderMock->expects($this->once())->method('getTransport')->will($this->returnValue($this->_transportMock)); $this->_transportMock->expects($this->once())->method('sendMessage'); $this->_storeManagerMock->expects($this->once())->method('getStore')->with($storeId)->will($this->returnValue($this->_storetMock)); $this->assertInstanceOf('\\Magento\\User\\Model\\User', $this->_model->sendPasswordResetConfirmationEmail()); }
/** * @param int|\Magento\Wishlist\Model\Item|\PHPUnit_Framework_MockObject_MockObject $itemId * @param \Magento\Framework\Object $buyRequest * @param null|array|\Magento\Framework\Object $param * @throws \Magento\Framework\Model\Exception * * @dataProvider updateItemDataProvider */ public function testUpdateItem($itemId, $buyRequest, $param) { $storeId = 1; $productId = 1; $stores = [(new \Magento\Framework\Object())->setId($storeId)]; $newItem = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item')->disableOriginalConstructor()->getMock(); $newItem->expects($this->any())->method('setProductId')->will($this->returnSelf()); $newItem->expects($this->any())->method('setWishlistId')->will($this->returnSelf()); $newItem->expects($this->any())->method('setStoreId')->will($this->returnSelf()); $newItem->expects($this->any())->method('setOptions')->will($this->returnSelf()); $newItem->expects($this->any())->method('setProduct')->will($this->returnSelf()); $newItem->expects($this->any())->method('setQty')->will($this->returnSelf()); $newItem->expects($this->any())->method('getItem')->will($this->returnValue(2)); $this->itemFactory->expects($this->once())->method('create')->will($this->returnValue($newItem)); $this->storeManager->expects($this->any())->method('getStores')->will($this->returnValue($stores)); $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($stores[0])); $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock(); $product->expects($this->any())->method('getId')->will($this->returnValue($productId)); $instanceType = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Type\\AbstractType')->disableOriginalConstructor()->getMock(); $instanceType->expects($this->once())->method('processConfiguration')->will($this->returnValue($this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock())); $newProduct = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock(); $newProduct->expects($this->any())->method('setStoreId')->with($storeId)->will($this->returnSelf()); $newProduct->expects($this->once())->method('load')->with($productId)->will($this->returnSelf()); $newProduct->expects($this->once())->method('getTypeInstance')->will($this->returnValue($instanceType)); $item = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item')->disableOriginalConstructor()->getMock(); $item->expects($this->once())->method('getProduct')->will($this->returnValue($product)); $items = $this->getMockBuilder('Magento\\Wishlist\\Model\\Resource\\Item\\Collection')->disableOriginalConstructor()->getMock(); $items->expects($this->once())->method('addWishlistFilter')->will($this->returnSelf()); $items->expects($this->once())->method('addStoreFilter')->will($this->returnSelf()); $items->expects($this->once())->method('setVisibilityFilter')->will($this->returnSelf()); $items->expects($this->once())->method('getItemById')->will($this->returnValue($item)); $items->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$item]))); $this->itemsFactory->expects($this->any())->method('create')->will($this->returnValue($items)); $this->productFactory->expects($this->once())->method('create')->will($this->returnValue($newProduct)); $this->assertInstanceOf('Magento\\Wishlist\\Model\\Wishlist', $this->wishlist->updateItem($itemId, $buyRequest, $param)); }