/** * @covers \Magento\Framework\App\Helper\AbstractHelper::isModuleEnabled * @covers \Magento\Framework\App\Helper\AbstractHelper::isModuleOutputEnabled * @param string|null $moduleName * @param string $requestedName * @param bool $result * @dataProvider isModuleEnabledDataProvider */ public function testIsModuleEnabled($moduleName, $requestedName, $result) { $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo($requestedName))->will($this->returnValue($result)); $this->moduleManagerMock->expects($this->once())->method('isOutputEnabled')->with($this->equalTo($requestedName))->will($this->returnValue($result)); $this->assertSame($result, $this->helper->isModuleEnabled($moduleName)); $this->assertSame($result, $this->helper->isModuleOutputEnabled($moduleName)); }
public function testAroundDispatchCached() { $this->_cacheMock->expects($this->once())->method('load')->with('db_is_up_to_date')->will($this->returnValue(true)); $this->moduleManager->expects($this->never())->method('isDbSchemaUpToDate'); $this->moduleManager->expects($this->never())->method('isDbDataUpToDate'); $this->assertEquals('Expected', $this->_model->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock)); }
/** * afterUpdateMview with disabled PageCache module */ public function testAfterUpdateMviewPageCacheDisabled() { $this->moduleManager->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(false)); $this->eventManagerMock->expects($this->never())->method('dispatch'); $actualResult = $this->plugin->afterUpdateMview($this->subjectMock); $this->assertNull($actualResult); }
/** * Test method afterGenerateXml with disabled module PageCache */ public function testAfterGenerateXmlPageCacheDisabled() { $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false); $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(false)); $this->requestMock->expects($this->never())->method('isAjax')->will($this->returnValue(false)); $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult); $this->assertEquals($expectedResult, $actualResult); }
public function testConvertWithDisabledModules() { $testDom = $this->filePath . 'import.xml'; $dom = new \DOMDocument(); $dom->load($testDom); $notExpectedArray = (include $this->filePath . 'import.php'); $this->moduleManager->expects($this->any())->method('isOutputEnabled')->willReturn(false); $this->assertNotEquals($notExpectedArray, $this->model->convert($dom)); }
/** * @dataProvider dataAddSwatch */ public function testAddSwatchAttributeType($exp) { $this->moduleManagerMock->expects($this->once())->method('isOutputEnabled')->willReturn($exp['isOutputEnabled']); $eventMock = $this->getMock('\\Magento\\Framework\\Event', ['getResponse'], [], '', false); $this->eventObserverMock->expects($this->exactly($exp['methods_count']))->method('getEvent')->willReturn($eventMock); $response = $this->getMock('\\Magento\\Framework\\DataObject', ['getTypes'], [], '', false); $eventMock->expects($this->exactly($exp['methods_count']))->method('getResponse')->willReturn($response); $response->expects($this->exactly($exp['methods_count']))->method('getTypes')->willReturn($exp['outputArray']); $this->observerMock->execute($this->eventObserverMock); }
/** * @dataProvider dataAddFields */ public function testAddFields($expected) { $this->moduleManagerMock->expects($this->once())->method('isOutputEnabled')->willReturn($expected['isOutputEnabled']); $this->eventObserverMock->expects($this->exactly($expected['methods_count']))->method('getForm')->willReturn($this->formMock); $element = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\AbstractElement', [], [], '', false); $this->formMock->expects($this->exactly($expected['methods_count']))->method('getElement')->with('base_fieldset')->willReturn($element); $element->expects($this->exactly($expected['addField_count']))->method('addField'); $this->yesNoMock->expects($this->exactly($expected['yesno_count']))->method('toOptionArray'); $this->observerMock->execute($this->eventObserverMock); }
/** * Test method afterGenerateXml */ public function testAfterGenerateXml() { $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', array(), array(), '', false); $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(true)); $this->cacheConfigMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true)); $this->requestMock->expects($this->once($this->once()))->method('isAjax')->will($this->returnValue(false)); $this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(true)); $this->checkoutSessionMock->expects($this->once())->method('clearStorage')->will($this->returnValue($expectedResult)); $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult); $this->assertEquals($expectedResult, $actualResult); }
/** * @param array $requestResult * @param bool $moduleManagerResult * @param bool $cacheConfigResult * @param bool $layoutResult * @param bool $can Depersonalize * @dataProvider checkIfDepersonalizeDataProvider */ public function testCheckIfDepersonalize(array $requestResult, $moduleManagerResult, $cacheConfigResult, $layoutResult, $canDepersonalize) { $this->requestMock->expects($this->any())->method('isAjax')->willReturn($requestResult['ajax']); $this->requestMock->expects($this->any())->method('isGet')->willReturn($requestResult['get']); $this->requestMock->expects($this->any())->method('isHead')->willReturn($requestResult['head']); $this->moduleManagerMock->expects($this->any())->method('isEnabled')->with('Magento_PageCache')->willReturn($moduleManagerResult); $this->cacheConfigMock->expects($this->any())->method('isEnabled')->willReturn($cacheConfigResult); $layoutMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface', [], '', false); $layoutMock->expects($this->any())->method('isCacheable')->willReturn($layoutResult); $object = new DepersonalizeChecker($this->requestMock, $this->moduleManagerMock, $this->cacheConfigMock); $this->assertEquals($canDepersonalize, $object->checkIfDepersonalize($layoutMock)); }
public function testToOptionArray() { $customerGroups = [['label' => __('ALL GROUPS'), 'value' => 32000], ['label' => __('NOT LOGGED IN'), 'value' => 0]]; $this->moduleManagerMock->expects($this->any())->method('isEnabled')->willReturn(true); $this->searchCriteriaBuilderMock->expects($this->any())->method('create')->willReturn($this->searchCriteriaMock); $this->groupRepositoryMock->expects($this->any())->method('getList')->with($this->searchCriteriaMock)->willReturn($this->searchResultMock); $this->groupRepositoryMock->expects($this->any())->method('getList')->with($this->searchCriteriaMock)->willReturn($this->searchResultMock); $groupTest = $this->getMockBuilder('\\Magento\\Customer\\Api\\Data\\GroupInterface')->disableOriginalConstructor()->setMethods(['getCode', 'getId'])->getMockForAbstractClass(); $groupTest->expects($this->any())->method('getCode')->willReturn(__('NOT LOGGED IN')); $groupTest->expects($this->any())->method('getId')->willReturn(0); $groups = [$groupTest]; $this->searchResultMock->expects($this->any())->method('getItems')->willReturn($groups); $this->assertEquals($customerGroups, $this->model->toOptionArray()); }
/** * Tests modules data returns array and saving in DB * * @dataProvider itemDataProvider * @return void */ public function testGetModuleDataRefreshOrStatement($data) { $moduleCollectionMock = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\ResourceModel\\Module\\Collection')->disableOriginalConstructor()->getMock(); /** @var \Magento\NewRelicReporting\Model\Module|\PHPUnit_Framework_MockObject_MockObject $itemMock */ $itemMock = $this->getMock('Magento\\NewRelicReporting\\Model\\Module', ['getName', 'getData', 'setData', 'getState', 'save'], [], '', false); $modulesMockArray = ['Module_Name1' => ['name' => 'Module_Name1', 'setup_version' => '2.0.0', 'sequence' => []]]; $itemMock->setData($data); $testChangesMockArray = ['entity_id' => '3', 'name' => 'Name', 'active' => 'false', 'state' => 'enabled', 'setup_version' => '2.0.0', 'some_param' => 'some_value', 'updated_at' => '2015-09-02 18:38:17']; $itemMockArray = [$itemMock]; $enabledModulesMockArray = ['Module_Name2']; $allModulesMockArray = ['Module_Name1', 'Module_Name2']; $this->moduleCollectionFactoryMock->expects($this->any())->method('create')->willReturn($moduleCollectionMock); $this->moduleFactoryMock->expects($this->any())->method('create')->willReturn($itemMock); $itemMock->expects($this->any())->method('setData')->willReturnSelf(); $itemMock->expects($this->any())->method('save')->willReturnSelf(); $itemMock->expects($this->any())->method('getState')->willReturn($data['state']); $itemMock->expects($this->any())->method('getName')->willReturn($data['name']); $moduleCollectionMock->expects($this->any())->method('getItems')->willReturn($itemMockArray); $itemMock->expects($this->any())->method('getData')->willReturn($testChangesMockArray); $this->fullModuleListMock->expects($this->once())->method('getAll')->willReturn($modulesMockArray); $this->fullModuleListMock->expects($this->any())->method('getNames')->willReturn($allModulesMockArray); $this->moduleListMock->expects($this->any())->method('getNames')->willReturn($enabledModulesMockArray); $this->moduleManagerMock->expects($this->any())->method('isOutputEnabled')->will($this->returnValue(true)); $this->assertInternalType('array', $this->model->getModuleData()); }
/** * test get customer method, method returns customer from service */ public function testGetCustomerLoadCustomerFromService() { $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(false)); $this->customerSessionMock->expects($this->once())->method('getId')->will($this->returnValue($this->customerId)); $this->customerRepositoryMock->expects($this->once())->method('getById')->with($this->equalTo($this->customerId))->will($this->returnValue($this->customerDataMock)); $this->assertEquals($this->customerDataMock, $this->currentCustomer->getCustomer()); }
/** * Run test afterGenerateXml method * * @param bool $result * * @dataProvider dataProviderAfterGenerateXml */ public function testAfterGenerateXml($result) { /** @var \Magento\Framework\View\LayoutInterface|\PHPUnit_Framework_MockObject_MockObject $subjectMock */ $subjectMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface', [], '', false, true, true, ['isCacheable']); /** @var \Magento\Framework\View\LayoutInterface|\PHPUnit_Framework_MockObject_MockObject $resultMock */ $resultMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface', [], '', false, true, true, []); $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with('Magento_PageCache')->willReturn($result); $this->cacheConfigMock->expects($this->any())->method('isEnabled')->willReturn($result); $this->requestMock->expects($this->any())->method('isAjax')->willReturn(!$result); $subjectMock->expects($this->any())->method('isCacheable')->willReturn($result); if ($result) { $this->persistentSessionMock->expects($this->once())->method('setCustomerId')->with(null); } else { $this->persistentSessionMock->expects($this->never())->method('setCustomerId')->with(null); } $this->assertEquals($resultMock, $this->plugin->afterGenerateXml($subjectMock, $resultMock)); }
/** * @param array $schemaValueMap * @param array $dataValueMap * * @dataProvider aroundDispatchExceptionDataProvider * @expectedException \Magento\Framework\Module\Exception * @expectedExceptionMessage Looks like database is outdated. Please, use setup tool to perform update */ public function testAroundDispatchException(array $schemaValueMap, array $dataValueMap) { $this->_cacheMock->expects($this->once())->method('load')->with('db_is_up_to_date')->will($this->returnValue(false)); $this->_cacheMock->expects($this->never())->method('save'); $this->moduleManager->expects($this->any())->method('isDbSchemaUpToDate')->will($this->returnValueMap($schemaValueMap)); $this->moduleManager->expects($this->any())->method('isDbDataUpToDate')->will($this->returnValueMap($dataValueMap)); $this->_model->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock); }
public function testAfterAddressSave() { $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with('Magento_PageCache')->willReturn(true); $this->cacheConfigMock->expects($this->once())->method('isEnabled')->willReturn(true); $this->taxHelperMock->expects($this->any())->method('isCatalogPriceDisplayAffectedByTax')->willReturn(true); $address = $this->objectManager->getObject('Magento\\Customer\\Model\\Address'); $address->setIsDefaultShipping(true); $address->setIsDefaultBilling(true); $address->setIsPrimaryBilling(true); $address->setIsPrimaryShipping(true); $address->setCountryId(1); $address->setData('postcode', 11111); $this->customerSessionMock->expects($this->once())->method('setDefaultTaxBillingAddress')->with(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]); $this->customerSessionMock->expects($this->once())->method('setDefaultTaxShippingAddress')->with(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]); $this->observerMock->expects($this->once())->method('getCustomerAddress')->willReturn($address); $this->session->afterAddressSave($this->observerMock); }
public function testAroundDispatch() { $this->moduleManagerMock->expects($this->any())->method('isEnabled')->with('Magento_PageCache')->willReturn(true); $this->cacheConfigMock->expects($this->any())->method('isEnabled')->willReturn(true); $this->taxHelperMock->expects($this->any())->method('isCatalogPriceDisplayAffectedByTax')->willReturn(true); $this->customerSessionMock->expects($this->once())->method('getDefaultTaxBillingAddress')->willReturn(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]); $this->customerSessionMock->expects($this->once())->method('getDefaultTaxShippingAddress')->willReturn(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]); $this->customerSessionMock->expects($this->once())->method('getCustomerTaxClassId')->willReturn(1); $this->taxCalculationMock->expects($this->once())->method('getTaxRates')->with(['country_id' => 1, 'region_id' => null, 'postcode' => 11111], ['country_id' => 1, 'region_id' => null, 'postcode' => 11111], 1)->willReturn([]); $this->httpContextMock->expects($this->once())->method('setValue')->with('tax_rates', [], 0); $action = $this->objectManager->getObject('Magento\\Framework\\App\\Action\\Action'); $request = $this->getMock('\\Magento\\Framework\\App\\Request\\Http', ['getActionName'], [], '', false); $expectedResult = 'expectedResult'; $proceed = function ($request) use($expectedResult) { return $expectedResult; }; $this->contextPlugin->aroundDispatch($action, $proceed, $request); }
public function testExecute() { $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with('Magento_PageCache')->willReturn(true); $this->cacheConfigMock->expects($this->once())->method('isEnabled')->willReturn(true); $this->weeeHelperMock->expects($this->any())->method('isEnabled')->willReturn(true); $customerMock = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\Customer')->disableOriginalConstructor()->getMock(); $this->observerMock->expects($this->once())->method('getData')->with('customer')->willReturn($customerMock); $address = $this->objectManager->getObject('Magento\\Customer\\Model\\Data\\Address'); $address->setIsDefaultShipping(true); $address->setIsDefaultBilling(true); $address->setCountryId(1); $address->setPostCode(11111); $addresses = [$address]; $customerMock->expects($this->once())->method('getAddresses')->willReturn($addresses); $this->customerSessionMock->expects($this->once())->method('setDefaultTaxBillingAddress')->with(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]); $this->customerSessionMock->expects($this->once())->method('setDefaultTaxShippingAddress')->with(['country_id' => 1, 'region_id' => null, 'postcode' => 11111]); $this->session->execute($this->observerMock); }
/** * Run test getStockOption method * * @param bool $moduleEnabled * @return void * * @dataProvider dataProviderModuleEnabled */ public function testGetStockOption($moduleEnabled) { $this->moduleManager->expects($this->once())->method('isEnabled')->with('Magento_CatalogInventory')->will($this->returnValue($moduleEnabled)); if ($moduleEnabled) { $this->stockMock->expects($this->once())->method('toOptionArray')->will($this->returnValue(['test-value', 'test-value'])); } $result = $this->inventory->getStockOption(); $this->assertEquals($moduleEnabled, !empty($result)); }
/** * Run test fromArray method * * @return void */ public function testFromArray() { $data = ['stock_item' => ['stock-item-data']]; $stockItemMock = $this->getMockForAbstractClass('Magento\\Framework\\Api\\AbstractSimpleObject', [], '', false, true, true, ['setProduct']); $this->moduleManager->expects($this->once())->method('isEnabled')->with('Magento_CatalogInventory')->will($this->returnValue(true)); $this->dataObjectHelperMock->expects($this->once())->method('populateWithArray')->with($stockItemMock, $data['stock_item'], '\\Magento\\CatalogInventory\\Api\\Data\\StockItemInterface')->will($this->returnSelf()); $this->stockItemFactoryMock->expects($this->once())->method('create')->will($this->returnValue($stockItemMock)); $stockItemMock->expects($this->once())->method('setProduct')->with($this->model); $this->assertEquals($this->model, $this->model->fromArray($data)); }
public function testLayoutIsNotCacheable() { $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->willReturn(true); $this->cacheConfigMock->expects($this->once())->method('isEnabled')->willReturn(true); $this->requestMock->expects($this->once($this->once()))->method('isAjax')->willReturn(false); $this->layoutMock->expects($this->once())->method('isCacheable')->willReturn(false); $this->catalogSessionMock->expects($this->never())->method('clearStorage'); $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $this->resultLayout); $this->assertEquals($this->resultLayout, $actualResult); }
public function testUpdateDataNoUpdates() { $this->moduleManager->expects($this->once())->method('isDbSchemaUpToDate')->with('Test_Module', 'catalog_setup')->will($this->returnValue(true)); $this->moduleManager->expects($this->once())->method('isDbDataUpToDate')->with('Test_Module', 'catalog_setup')->will($this->returnValue(true)); $this->_factoryMock->expects($this->never())->method('create'); $this->_appStateMock->expects($this->at(0))->method('setUpdateMode')->with(true); $this->_appStateMock->expects($this->at(1))->method('setUpdateMode')->with(false); $this->_factoryMock->expects($this->never())->method('create'); $this->_model->updateScheme(); $this->_model->updateData(); }
/** * Test afterGenerateXml method with enabled module PageCache and request is Ajax and Layout is not cacheable */ public function testAfterGenerateXmlLayoutIsNotCacheable() { $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', array(), array(), '', false); $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(true)); $this->cacheConfigMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true)); $this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(false)); $this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(false)); $this->visitorMock->expects($this->never())->method('setSkipRequestLogging'); $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult); $this->assertSame($expectedResult, $actualResult); }
public function testAroundDispatchBasedOnShipping() { $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(true); $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with('Magento_PageCache')->willReturn(true); $this->cacheConfigMock->expects($this->once())->method('isEnabled')->willReturn(true); $this->weeeHelperMock->expects($this->once())->method('isEnabled')->willReturn(true); $this->taxHelperMock->expects($this->once())->method('getTaxBasedOn')->willReturn('shipping'); $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $storeMock->expects($this->once())->method('getWebsiteId')->willReturn(1); $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock); $this->scopeConfigMock->expects($this->at(0))->method('getValue')->with(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_COUNTRY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, null)->willReturn('US'); $this->scopeConfigMock->expects($this->at(1))->method('getValue')->with(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_REGION, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, null)->willReturn(0); $this->customerSessionMock->expects($this->once())->method('getDefaultTaxShippingAddress')->willReturn(['country_id' => 'US', 'region_id' => 1]); $this->weeeTaxMock->expects($this->once())->method('isWeeeInLocation')->with('US', 1, 1)->willReturn(true); $this->httpContextMock->expects($this->once())->method('setValue')->with('weee_tax_region', ['countryId' => 'US', 'regionId' => 1], 0); $action = $this->objectManager->getObject('Magento\\Framework\\App\\Test\\Unit\\Action\\Stub\\ActionStub'); $request = $this->getMock('\\Magento\\Framework\\App\\Request\\Http', ['getActionName'], [], '', false); $expectedResult = 'expectedResult'; $proceed = function ($request) use($expectedResult) { return $expectedResult; }; $this->contextPlugin->aroundDispatch($action, $proceed, $request); }
/** * @param bool $isModuleEnabled * @param bool $isWishlistActive * @param bool $result * @dataProvider dataProviderIsRssAllow */ public function testIsRssAllow($isModuleEnabled, $isWishlistActive, $result) { $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with('Magento_Rss')->willReturn($isModuleEnabled); $this->scopeConfigMock->expects($this->any())->method('isSetFlag')->with('rss/wishlist/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)->willReturn($isWishlistActive); $this->assertEquals($result, $this->model->isRssAllow()); }