/** * @dataProvider filterProvider */ public function testAddInStockFilterToCollection($configMock) { $collectionMock = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Product\\Link\\Product\\Collection')->disableOriginalConstructor()->getMock(); $collectionMock->expects($this->any())->method('joinField'); $this->scopeConfigMock->expects($this->any())->method('getValue')->willReturn($configMock); $this->assertNull($this->stock->addInStockFilterToCollection($collectionMock)); }
/** * @param $unsecureBaseUrl * @param $useSecureInAdmin * @param $secureBaseUrl * @param $expected * @dataProvider shouldBeSecureDataProvider */ public function testShouldBeSecure($unsecureBaseUrl, $useSecureInAdmin, $secureBaseUrl, $expected) { $coreConfigValueMap = [[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, 'default', null, $unsecureBaseUrl], [\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, 'default', null, $secureBaseUrl]]; $this->coreConfig->expects($this->any())->method('getValue')->will($this->returnValueMap($coreConfigValueMap)); $this->backendConfig->expects($this->any())->method('isSetFlag')->willReturn($useSecureInAdmin); $this->assertEquals($expected, $this->adminPathConfig->shouldBeSecure('')); }
/** * @param bool $canReturnToStock * @param bool $manageStock * @param bool $result * @dataProvider canReturnItemsToStockDataProvider */ public function testCanReturnItemsToStock($canReturnToStock, $manageStock, $result) { $productId = 7; $property = new \ReflectionProperty($this->items, '_canReturnToStock'); $property->setAccessible(true); $this->assertNull($property->getValue($this->items)); $this->scopeConfig->expects($this->once())->method('getValue')->with($this->equalTo(\Magento\CatalogInventory\Model\Stock\Item::XML_PATH_CAN_SUBTRACT), $this->equalTo(\Magento\Store\Model\ScopeInterface::SCOPE_STORE))->will($this->returnValue($canReturnToStock)); if ($canReturnToStock) { $orderItem = $this->getMock('Magento\\Sales\\Model\\Order\\Item', ['getProductId', '__wakeup'], [], '', false); $orderItem->expects($this->once())->method('getProductId')->will($this->returnValue($productId)); $creditMemoItem = $this->getMock('Magento\\Sales\\Model\\Order\\Creditmemo\\Item', ['setCanReturnToStock', 'getOrderItem', '__wakeup'], [], '', false); $creditMemo = $this->getMock('Magento\\Sales\\Model\\Order\\Creditmemo', [], [], '', false); $creditMemo->expects($this->once())->method('getAllItems')->will($this->returnValue([$creditMemoItem])); $creditMemoItem->expects($this->once())->method('getOrderItem')->will($this->returnValue($orderItem)); $this->stockItemMock->expects($this->once())->method('getManageStock')->with($this->equalTo($productId))->will($this->returnValue($manageStock)); $creditMemoItem->expects($this->once())->method('setCanReturnToStock')->with($this->equalTo($manageStock))->will($this->returnSelf()); $order = $this->getMock('Magento\\Sales\\Model\\Order', ['setCanReturnToStock', '__wakeup'], [], '', false); $order->expects($this->once())->method('setCanReturnToStock')->with($this->equalTo($manageStock))->will($this->returnSelf()); $creditMemo->expects($this->once())->method('getOrder')->will($this->returnValue($order)); $this->registryMock->expects($this->any())->method('registry')->with('current_creditmemo')->will($this->returnValue($creditMemo)); } $this->assertSame($result, $this->items->canReturnItemsToStock()); $this->assertSame($result, $property->getValue($this->items)); // lazy load test $this->assertSame($result, $this->items->canReturnItemsToStock()); }
public function testGetLinksTitleWithoutTitle() { $product = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['_wakeup', 'getLinksTitle'])->getMock(); $product->expects($this->once())->method('getLinksTitle')->willReturn(null); $this->scopeConfig->expects($this->once())->method('getValue')->with(\Magento\Downloadable\Model\Link::XML_PATH_LINKS_TITLE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)->willReturn('scope_config_value'); $this->assertEquals('scope_config_value', $this->helper->getLinksTitle($product)); }
/** * @param $url * @param $host * @dataProvider hostsDataProvider */ public function testIsHostBackend($url, $host, $expectedValue) { $backendUrl = $url; $_SERVER['HTTP_HOST'] = $host; $this->scopeConfigMock->expects($this->once())->method('getValue')->with(Store::XML_PATH_UNSECURE_BASE_URL, ScopeInterface::SCOPE_STORE)->willReturn($backendUrl); $this->assertEquals($this->model->isHostBackend(), $expectedValue); }
public function testAfterDelete() { $this->configMock->expects($this->any())->method('getValue')->willReturnMap([[Theme::XML_PATH_INVALID_CACHES, ScopeInterface::SCOPE_STORE, null, ['block_html' => 1, 'layout' => 1, 'translate' => 1]], [null, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, 'old_value']]); $this->cacheTypeListMock->expects($this->exactly(2))->method('invalidate'); $this->model->setValue('some_value'); $this->assertSame($this->model, $this->model->afterDelete()); }
public function testSubscribe() { $email = '*****@*****.**'; $this->resource->expects($this->any())->method('loadByEmail')->willReturn(['subscriber_status' => 3, 'subscriber_email' => $email, 'name' => 'subscriber_name']); $this->resource->expects($this->any())->method('getIdFieldName')->willReturn('id_field'); $this->scopeConfig->expects($this->any())->method('getValue')->willReturn(true); $this->customerSession->expects($this->any())->method('isLoggedIn')->willReturn(true); $customerDataModel = $this->getMock('\\Magento\\Customer\\Api\\Data\\CustomerInterface'); $this->customerSession->expects($this->any())->method('getCustomerDataObject')->willReturn($customerDataModel); $this->customerSession->expects($this->any())->method('getCustomerId')->willReturn(1); $customerDataModel->expects($this->any())->method('getEmail')->willReturn($email); $this->customerRepository->expects($this->any())->method('getById')->willReturn($customerDataModel); $customerDataModel->expects($this->any())->method('getStoreId')->willReturn(1); $customerDataModel->expects($this->any())->method('getId')->willReturn(1); $this->transportBuilder->expects($this->any())->method('setTemplateIdentifier')->willReturnSelf(); $this->transportBuilder->expects($this->any())->method('setTemplateOptions')->willReturnSelf(); $this->transportBuilder->expects($this->any())->method('setTemplateVars')->willReturnSelf(); $this->transportBuilder->expects($this->any())->method('setFrom')->willReturnSelf(); $this->transportBuilder->expects($this->any())->method('addTo')->willReturnSelf(); $storeModel = $this->getMock('\\Magento\\Store\\Model\\Store', ['getId'], [], '', false); $this->scopeConfig->expects($this->any())->method('getValue')->willReturn('*****@*****.**'); $this->storeManager->expects($this->any())->method('getStore')->willReturn($storeModel); $storeModel->expects($this->any())->method('getId')->willReturn(1); $transport = $this->getMock('\\Magento\\Framework\\Mail\\TransportInterface'); $this->transportBuilder->expects($this->any())->method('getTransport')->willReturn($transport); $transport->expects($this->any())->method('sendMessage')->willReturnSelf(); $inlineTranslation = $this->getMock('Magento\\Framework\\Translate\\Inline\\StateInterface'); $inlineTranslation->expects($this->any())->method('resume')->willReturnSelf(); $this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf(); $this->assertEquals(1, $this->subscriber->subscribe($email)); }
public function testAuthorize() { $paymentAction = 'some_action'; $this->scopeConfigMock->expects($this->any())->method('getValue')->with('payment/paymentmethod_directpost/payment_action', 'store', null)->willReturn($paymentAction); $this->paymentMock->expects($this->once())->method('setAdditionalInformation')->with('payment_type', $paymentAction); $this->directpost->authorize($this->paymentMock, 10); }
/** * @return void */ public function testExecute() { $customerId = 7; $captchaValue = 'some-value'; $email = '*****@*****.**'; $redirectUrl = 'http://magento.com/customer/account/edit/'; $captcha = $this->getMock('Magento\\Captcha\\Model\\DefaultModel', [], [], '', false); $captcha->expects($this->once())->method('isRequired')->willReturn(true); $captcha->expects($this->once())->method('isCorrect')->with($captchaValue)->willReturn(false); $this->helperMock->expects($this->once())->method('getCaptcha')->with(\Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID)->willReturn($captcha); $response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false); $request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false); $request->expects($this->any())->method('getPost')->with(\Magento\Captcha\Helper\Data::INPUT_NAME_FIELD_VALUE, null)->willReturn([\Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID => $captchaValue]); $controller = $this->getMock('Magento\\Framework\\App\\Action\\Action', [], [], '', false); $controller->expects($this->any())->method('getRequest')->will($this->returnValue($request)); $controller->expects($this->any())->method('getResponse')->will($this->returnValue($response)); $this->captchaStringResolverMock->expects($this->once())->method('resolve')->with($request, \Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID)->willReturn($captchaValue); $customerDataMock = $this->getMock('\\Magento\\Customer\\Model\\Data\\Customer', [], [], '', false); $this->customerSessionMock->expects($this->once())->method('getCustomerId')->willReturn($customerId); $this->customerSessionMock->expects($this->atLeastOnce())->method('getCustomer')->willReturn($customerDataMock); $this->authenticationMock->expects($this->once())->method('processAuthenticationFailure')->with($customerId); $this->authenticationMock->expects($this->once())->method('isLocked')->with($customerId)->willReturn(true); $this->customerSessionMock->expects($this->once())->method('logout'); $this->customerSessionMock->expects($this->once())->method('start'); $this->scopeConfigMock->expects($this->once())->method('getValue')->with('contact/email/recipient_email')->willReturn($email); $message = __('The account is locked. Please wait and try again or contact %1.', $email); $this->messageManagerMock->expects($this->exactly(2))->method('addError')->withConsecutive([$message], [__('Incorrect CAPTCHA')]); $this->actionFlagMock->expects($this->once())->method('set')->with('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true); $this->redirectMock->expects($this->once())->method('redirect')->with($response, '*/*/edit')->willReturn($redirectUrl); $this->observer->execute(new \Magento\Framework\Event\Observer(['controller_action' => $controller])); }
/** * @param int $callNumber * @param string $oldValue * @dataProvider afterSaveDataProvider */ public function testAfterSave($callNumber, $oldValue) { $this->cacheTypeListMock->expects($this->exactly($callNumber))->method('invalidate'); $this->configMock->expects($this->any())->method('getValue')->willReturnMap([[Theme::XML_PATH_INVALID_CACHES, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, null, ['block_html' => 1, 'layout' => 1, 'translate' => 1]], [null, \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, $oldValue]]); $this->model->setValue('some_value'); $this->assertInstanceOf(get_class($this->model), $this->model->afterSave()); }
/** * @covers \Magento\Shipping\Model\Shipping\LabelGenerator * @param array $info * @dataProvider labelInfoDataProvider */ public function testAddTrackingNumbersToShipment(array $info) { $order = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock(); $order->expects(static::once())->method('getShippingMethod')->with(true)->willReturn($this->getShippingMethodMock()); /** * @var $shipmentMock \Magento\Sales\Model\Order\Shipment|\PHPUnit_Framework_MockObject_MockObject */ $shipmentMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Shipment')->disableOriginalConstructor()->getMock(); $shipmentMock->expects(static::once())->method('getOrder')->willReturn($order); $this->carrierFactory->expects(static::once())->method('create')->with(self::CARRIER_CODE)->willReturn($this->getCarrierMock()); $labelsMock = $this->getMockBuilder('\\Magento\\Shipping\\Model\\Shipping\\Labels')->disableOriginalConstructor()->getMock(); $labelsMock->expects(static::once())->method('requestToShipment')->with($shipmentMock)->willReturn($this->getResponseMock($info)); $this->labelsFactory->expects(static::once())->method('create')->willReturn($labelsMock); $this->filesystem->expects(static::once())->method('getDirectoryWrite')->willReturn($this->getMock('Magento\\Framework\\Filesystem\\Directory\\WriteInterface')); $this->scopeConfig->expects(static::once())->method('getValue')->with('carriers/' . self::CARRIER_CODE . '/title', ScopeInterface::SCOPE_STORE, null)->willReturn(self::CARRIER_TITLE); $this->labelsFactory->expects(static::once())->method('create')->willReturn($labelsMock); $trackMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Shipment\\Track')->setMethods(['setNumber', 'setCarrierCode', 'setTitle'])->disableOriginalConstructor()->getMock(); $i = 0; $trackingNumbers = is_array($info['tracking_number']) ? $info['tracking_number'] : [$info['tracking_number']]; foreach ($trackingNumbers as $trackingNumber) { $trackMock->expects(static::at($i++))->method('setNumber')->with($trackingNumber)->willReturnSelf(); $trackMock->expects(static::at($i++))->method('setCarrierCode')->with(self::CARRIER_CODE)->willReturnSelf(); $trackMock->expects(static::at($i++))->method('setTitle')->with(self::CARRIER_TITLE)->willReturnSelf(); } $this->trackFactory->expects(static::any())->method('create')->willReturn($trackMock); /** * @var $requestMock \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */ $requestMock = $this->getMock('Magento\\Framework\\App\\RequestInterface'); $this->labelGenerator->create($shipmentMock, $requestMock); }
public function testGetAssetMinificationAdapter() { $contentType = 'content type'; $adapter = 'adapter'; $this->scopeConfigMock->expects($this->once())->method('getValue')->with(sprintf(Config::XML_PATH_MINIFICATION_ADAPTER, $contentType), \Magento\Framework\Store\ScopeInterface::SCOPE_STORE)->willReturn($adapter); $this->assertSame($adapter, $this->model->getAssetMinificationAdapter($contentType)); }
public function testIsBillingAddressEnabled() { $isEnabled = 1; $prefix = 'payment/braintree_paypal/'; $this->scopeConfigMock->expects($this->once())->method('getValue')->with($prefix . PayPal::KEY_REQUIRE_BILLING_ADDRESS, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, null)->willReturn($isEnabled); $this->assertEquals(true, $this->model->isBillingAddressEnabled()); }
/** * @dataProvider afterGetStateActiveDataProvider */ public function testAfterGetStateActive($scopeConfigMockReturnValue, $result, $assertResult) { /** @var \Magento\Checkout\Block\Cart\Shipping $subjectMock */ $subjectMock = $this->getMockBuilder('Magento\\Checkout\\Block\\Cart\\Shipping')->disableOriginalConstructor()->getMock(); $this->scopeConfigMock->expects($result ? $this->never() : $this->once())->method('getValue')->willReturn($scopeConfigMockReturnValue); $this->assertEquals($assertResult, $this->model->afterGetStateActive($subjectMock, $result)); }
/** * Run test for process method */ public function testProcessAlternativeSource() { $chainMock = $this->getChainMock(); $this->scopeConfigMock->expects(self::once())->method('getValue')->with(WorkflowType::CONFIG_NAME_PATH)->willReturn('off'); $this->alternativeSourceMock->expects(self::once())->method('process')->with($chainMock); $this->frontendCompilationMock->expects(self::never())->method('process'); $this->preprocessorStrategy->process($chainMock); }
public function testGet() { $expectedResult = ['interval_division_limit' => 15, 'range_step' => 3.3, 'min_range_power' => 10, 'max_intervals_number' => 33]; $this->scopeConfig->expects($this->at(0))->method('getValue')->withConsecutive([Options::XML_PATH_INTERVAL_DIVISION_LIMIT, ScopeInterface::SCOPE_STORE])->willReturn($expectedResult['interval_division_limit']); $this->scopeConfig->expects($this->at(1))->method('getValue')->withConsecutive([Options::XML_PATH_RANGE_STEP, ScopeInterface::SCOPE_STORE])->willReturn($expectedResult['range_step']); $this->scopeConfig->expects($this->at(2))->method('getValue')->withConsecutive([Options::XML_PATH_RANGE_MAX_INTERVALS, ScopeInterface::SCOPE_STORE])->willReturn($expectedResult['max_intervals_number']); $this->options->get(); }
public function testGetNegative() { $engineMock = $this->getMock('Magento\\CatalogSearch\\Model\\Resource\\Fulltext\\Engine', array('test', '__wakeup'), array(), '', false); $engineMock->expects($this->never())->method('test'); $this->_scopeConfigMock->expects($this->once())->method('getValue')->with('catalog/search/engine')->will($this->returnValue('')); $this->_engineFactoryMock->expects($this->once())->method('create')->with('Magento\\CatalogSearch\\Model\\Resource\\Fulltext\\Engine')->will($this->returnValue($engineMock)); $this->assertEquals($engineMock, $this->_model->get()); }
/** * @param string $userAgent * @param bool $useConfig * @param bool|string $result * @param array $expressions * @dataProvider getThemeByRequestDataProvider */ public function testGetThemeByRequest($userAgent, $useConfig, $result, $expressions = []) { $this->requestMock->expects($this->once())->method('getServer')->with($this->equalTo('HTTP_USER_AGENT'))->will($this->returnValue($userAgent)); if ($useConfig) { $this->scopeConfigMock->expects($this->once())->method('getValue')->with($this->equalTo($this->exceptionConfigPath), $this->equalTo($this->scopeType))->will($this->returnValue(serialize($expressions))); } $this->assertSame($result, $this->designExceptions->getThemeByRequest($this->requestMock)); }
/** * @param bool $result * * @dataProvider dataProviderForTestIsAvailable */ public function testIsAvailable($result) { $storeId = 15; $this->quoteMock->expects($this->once())->method('getStoreId')->willReturn($storeId); $this->scopeConfigMock->expects($this->once())->method('getValue')->with('payment/' . Stub::STUB_CODE . '/active', ScopeInterface::SCOPE_STORE, $storeId)->willReturn($result); $this->eventManagerMock->expects($this->once())->method('dispatch')->with($this->equalTo('payment_method_is_active'), $this->countOf(3)); $this->assertEquals($result, $this->payment->isAvailable($this->quoteMock)); }
public function testProcess() { $configData = ['total_1' => 'sort_1', 'total_2' => 'sort_2', 'total_3' => 'sort_3']; $jsLayout = ['components' => ['block-totals' => ['children' => ['total_1' => ['value' => 'value_1', 'sortOrder' => 0], 'total_2' => ['value' => 'value_1', 'sortOrder' => 1], 'total_3' => ['value' => 'value_1', 'sortOrder' => 2]]]]]; $expected = ['components' => ['block-totals' => ['children' => ['total_1' => ['value' => 'value_1', 'sortOrder' => 'sort_1'], 'total_2' => ['value' => 'value_1', 'sortOrder' => 'sort_2'], 'total_3' => ['value' => 'value_1', 'sortOrder' => 'sort_3']]]]]; $this->scopeConfig->expects($this->once())->method('getValue')->with('sales/totals_sort')->willReturn($configData); $this->assertEquals($expected, $this->model->process($jsLayout)); }
/** * Test add stock status to collection with 'display out of stock' option enabled */ public function testAddStockStatusEnabledShow() { $this->_scopeConfigMock->expects($this->once())->method('isSetFlag')->with('cataloginventory/options/show_out_of_stock')->will($this->returnValue(false)); $collectionMock = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', [], [], '', false); $this->_stockHelperMock->expects($this->once())->method('addIsInStockFilterToCollection')->with($collectionMock); $subjectMock = $this->getMock('\\Magento\\Catalog\\Model\\Layer', [], [], '', false); $this->_model->beforePrepareProductCollection($subjectMock, $collectionMock); }
public function testGetAccountPassword() { $storeId = 1; $configPasswordKey = 'password'; $password = '******'; $this->scopeConfig->expects($this->once())->method('getValue')->with('google/googleshopping/' . $configPasswordKey, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)->will($this->returnValue($password)); $this->assertEquals($password, $this->model->getAccountPassword($storeId)); }
/** * @param mixed $sid * @param bool $useFrontedSid * @param bool $isOwnOriginUrl * @param mixed $testSid * @dataProvider dataProviderTestGetSid */ public function testGetSid($sid, $useFrontedSid, $isOwnOriginUrl, $testSid) { $this->scopeConfig->expects($this->any())->method('getValue')->with(\Magento\Framework\Session\SidResolver::XML_PATH_USE_FRONTEND_SID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)->will($this->returnValue($useFrontedSid)); $this->urlBuilder->expects($this->any())->method('isOwnOriginUrl')->will($this->returnValue($isOwnOriginUrl)); if ($testSid) { $this->request->getQuery()->set($this->model->getSessionIdQueryParam($this->session), $testSid); } $this->assertEquals($sid, $this->model->getSid($this->session)); }
public function testGetDefault() { $defaultTitle = 'default title'; $prefix = 'prefix'; $suffix = 'suffix'; $expected = 'prefix default title suffix'; $this->scopeConfigMock->expects($this->any())->method('getValue')->will($this->returnValueMap([['design/head/title_prefix', ScopeInterface::SCOPE_STORE, null, $prefix], ['design/head/title_suffix', ScopeInterface::SCOPE_STORE, null, $suffix], ['design/head/default_title', ScopeInterface::SCOPE_STORE, null, $defaultTitle]])); $this->assertEquals($expected, $this->title->getDefault()); }
/** * Test isSatisfiedBy method * * @param array $methodsInfo * @param bool $is3DSecureEnabled * @param bool $result * @dataProvider methodsDataProvider */ public function testIsSatisfiedBy($methodsInfo, $is3DSecureEnabled, $result) { $method = 'method-name'; $methodsInfo = [$method => $methodsInfo]; $this->paymentConfigMock->expects($this->once())->method('getMethodsInfo')->will($this->returnValue($methodsInfo)); $this->scopeConfigMock->expects($this->any())->method('isSetFlag')->will($this->returnValue($is3DSecureEnabled)); $configSpecification = $this->objectManager->getObject('Magento\\Multishipping\\Model\\Payment\\Method\\Specification\\Is3DSecure', ['paymentConfig' => $this->paymentConfigMock, 'scopeConfig' => $this->scopeConfigMock]); $this->assertEquals($result, $configSpecification->isSatisfiedBy($method), sprintf('Failed payment method test: "%s"', $method)); }
/** * @param $isAvailable * @param $isFlatEnabled * @param $isValid * @param $result * @dataProvider isAvailableDataProvider */ public function testIsAvailable($isAvailable, $isFlatEnabled, $isValid, $result) { $this->flatIndexerMock->expects($this->any())->method('load')->with('catalog_category_flat'); $this->flatIndexerMock->expects($this->any())->method('isValid')->will($this->returnValue($isValid)); $this->indexerRegistryMock->expects($this->any())->method('get')->with(\Magento\Catalog\Model\Indexer\Category\Flat\State::INDEXER_ID)->will($this->returnValue($this->flatIndexerMock)); $this->scopeConfigMock->expects($this->any())->method('isSetFlag')->with('catalog/frontend/flat_catalog_category')->will($this->returnValue($isFlatEnabled)); $this->model = new \Magento\Catalog\Model\Indexer\Category\Flat\State($this->scopeConfigMock, $this->indexerRegistryMock, $isAvailable); $this->assertEquals($result, $this->model->isAvailable()); }
/** * Test loadData * * @return void */ public function testLoadData() { $this->scopeTreeMock->expects($this->any())->method('get')->willReturn(['scope' => ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 'scope_id' => null, 'scopes' => [['scope' => ScopeInterface::SCOPE_WEBSITE, 'scope_id' => 1, 'scopes' => [['scope' => ScopeInterface::SCOPE_GROUP, 'scope_id' => 1, 'scopes' => [['scope' => ScopeInterface::SCOPE_STORE, 'scope_id' => 1, 'scopes' => []]]]]]]]); $this->metadataProviderMock->expects($this->any())->method('get')->willReturn(['first_field' => ['path' => 'first/field/path', 'use_in_grid' => 0], 'second_field' => ['path' => 'second/field/path', 'use_in_grid' => true], 'third_field' => ['path' => 'third/field/path']]); $this->appConfigMock->expects($this->any())->method('getValue')->willReturnMap([['second/field/path', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, 'DefaultValue'], ['second/field/path', ScopeInterface::SCOPE_WEBSITE, 1, 'WebsiteValue'], ['second/field/path', ScopeInterface::SCOPE_STORE, 1, 'WebsiteValue']]); $this->valueProcessor->expects($this->atLeastOnce())->method('process')->withConsecutive(['DefaultValue', 'default', null, ['path' => 'second/field/path', 'use_in_grid' => 1]], ['WebsiteValue', 'website', 1, ['path' => 'second/field/path', 'use_in_grid' => 1]], ['WebsiteValue', 'store', 1, ['path' => 'second/field/path', 'use_in_grid' => 1]])->willReturnOnConsecutiveCalls('DefaultValue', 'WebsiteValue', 'WebsiteValue'); $expectedResult = [new \Magento\Framework\DataObject(['store_website_id' => null, 'store_group_id' => null, 'store_id' => null, 'second_field' => 'DefaultValue']), new \Magento\Framework\DataObject(['store_website_id' => 1, 'store_group_id' => null, 'store_id' => null, 'second_field' => 'WebsiteValue']), new \Magento\Framework\DataObject(['store_website_id' => 1, 'store_group_id' => 1, 'store_id' => 1, 'second_field' => 'WebsiteValue'])]; $this->assertEquals($expectedResult, $this->collection->getItems()); }
/** * @param string $status * @param string|null $lastLoginAt * @param string|null $lastVisitAt * @param string|null $lastLogoutAt * @return void * @dataProvider getCurrentStatusDataProvider */ public function testGetCurrentStatus($status, $lastLoginAt, $lastVisitAt, $lastLogoutAt) { $this->scopeConfig->expects($this->any())->method('getValue')->with('customer/online_customers/online_minutes_interval', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)->willReturn(240); //TODO: it's value mocked because unit tests run data providers before all testsuite $this->customerLog->expects($this->any())->method('getLastLoginAt')->willReturn($lastLoginAt); $this->customerLog->expects($this->any())->method('getLastVisitAt')->willReturn($lastVisitAt); $this->customerLog->expects($this->any())->method('getLastLogoutAt')->willReturn($lastLogoutAt); $this->assertEquals($status, (string) $this->block->getCurrentStatus()); }
public function testGetUrlPathWithSuffixAndCategoryAnsStore() { $storeId = 1; $this->product->expects($this->once())->method('getData')->with('url_path')->will($this->returnValue('product-path')); $this->categoryUrlPathGenerator->expects($this->once())->method('getUrlPath')->will($this->returnValue('category-url-path')); $this->storeManager->expects($this->never())->method('getStore'); $this->scopeConfig->expects($this->once())->method('getValue')->with(ProductUrlPathGenerator::XML_PATH_PRODUCT_URL_SUFFIX, \Magento\Framework\Store\ScopeInterface::SCOPE_STORE, $storeId)->will($this->returnValue('.html')); $this->assertEquals('category-url-path/product-path.html', $this->productUrlPathGenerator->getUrlPathWithSuffix($this->product, $storeId, $this->category)); }
/** * @param bool $isActive * @dataProvider getActiveMethodsDataProvider */ public function testGetActiveMethods($isActive) { $abstractMethod = $this->getMockBuilder('Magento\\Payment\\Model\\Method\\AbstractMethod')->disableOriginalConstructor()->setMethods(['setId', 'setStore', 'getConfigData'])->getMock(); $this->scopeConfig->expects($this->once())->method('getValue')->with('payment', ScopeInterface::SCOPE_STORE, null)->will($this->returnValue($this->paymentMethodsList)); $this->paymentMethodFactory->expects($this->once())->method('create')->with($this->paymentMethodsList['active_method']['model'])->will($this->returnValue($abstractMethod)); $abstractMethod->expects($this->any())->method('setId')->with('active_method')->will($this->returnValue($abstractMethod)); $abstractMethod->expects($this->any())->method('setStore')->with(null); $abstractMethod->expects($this->any())->method('getConfigData')->with('active', $this->isNull())->will($this->returnValue($isActive)); $this->assertEquals($isActive ? ['active_method' => $abstractMethod] : [], $this->config->getActiveMethods()); }