public function testGetTreeHasLevelField() { $rootId = \Magento\Catalog\Model\Category::TREE_ROOT_ID; $storeGroups = []; $storeId = 1; $rootLevel = 2; $level = 3; $this->collection->expects($this->any())->method('addAttributeToSelect')->willReturnMap([['url_key', false, $this->collection], ['is_anchor', false, $this->collection]]); $this->childNode->expects($this->atLeastOnce())->method('getLevel')->willReturn($level); $this->rootNode->expects($this->atLeastOnce())->method('getLevel')->willReturn($rootLevel); $this->rootNode->expects($this->once())->method('hasChildren')->willReturn(true); $this->rootNode->expects($this->once())->method('getChildren')->willReturn([$this->childNode]); $this->categoryTree->expects($this->once())->method('load')->with(null, 3)->willReturnSelf(); $this->categoryTree->expects($this->atLeastOnce())->method('addCollectionData')->with($this->collection)->willReturnSelf(); $this->categoryTree->expects($this->once())->method('getNodeById')->with($rootId)->willReturn($this->rootNode); $this->store->expects($this->atLeastOnce())->method('getId')->willReturn($storeId); $this->storeManager->expects($this->once())->method('getGroups')->willReturn($storeGroups); $this->storeManager->expects($this->atLeastOnce())->method('getStore')->willReturn($this->store); $this->context->expects($this->once())->method('getStoreManager')->willReturn($this->storeManager); $this->context->expects($this->once())->method('getRequest')->willReturn($this->request); $this->context->expects($this->once())->method('getEscaper')->willReturn($this->escaper); $this->context->expects($this->once())->method('getEventManager')->willReturn($this->eventManager); /** @var \Magento\Widget\Block\Adminhtml\Widget\Catalog\Category\Chooser $chooser */ $chooser = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject('Magento\\Widget\\Block\\Adminhtml\\Widget\\Catalog\\Category\\Chooser', ['categoryTree' => $this->categoryTree, 'context' => $this->context]); $chooser->setData('category_collection', $this->collection); $result = $chooser->getTree(); $this->assertEquals($level, $result[0]['level']); }
public function testIsSingleStoreMode() { $storeManagerMock = $this->getMock('Magento\\Store\\Model\\StoreManager', ['isSingleStoreMode'], [], '', false); $storeManagerMock->expects($this->any())->method('isSingleStoreMode')->will($this->returnValue(true)); $this->contextMock->expects($this->any())->method('getStoreManager')->will($this->returnValue($storeManagerMock)); $this->block = $this->objectManagerHelper->getObject('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Sendemail', ['context' => $this->contextMock]); $this->assertTrue($this->block->isSingleStoreMode()); }
/** * Set up * * @return void */ protected function setUp() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->contextMock = $this->getMock('Magento\\Backend\\Block\\Template\\Context', ['getRequest'], [], '', false); $this->backordersMock = $this->getMock('Magento\\CatalogInventory\\Model\\Source\\Backorders', [], [], '', false); $this->stockConfigurationMock = $this->getMockForAbstractClass('Magento\\CatalogInventory\\Api\\StockConfigurationInterface', [], '', false); $this->requestMock = $this->getMockForAbstractClass('Magento\\Framework\\App\\RequestInterface', ['getParam'], '', false); $this->contextMock->expects($this->once())->method('getRequest')->will($this->returnValue($this->requestMock)); $this->inventory = $objectManager->getObject('Magento\\Catalog\\Block\\Adminhtml\\Product\\Edit\\Action\\Attribute\\Tab\\Inventory', ['context' => $this->contextMock, 'backorders' => $this->backordersMock, 'stockConfiguration' => $this->stockConfigurationMock]); }
protected function setUp() { $this->contextMock = $this->getMock('Magento\\Backend\\Block\\Template\\Context', [], [], '', false); $this->stockItemMock = $this->getMock('Magento\\CatalogInventory\\Service\\V1\\StockItemService', [], [], '', false); $this->registryMock = $this->getMock('Magento\\Framework\\Registry'); $this->scopeConfig = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface'); $this->contextMock->expects($this->once())->method('getScopeConfig')->will($this->returnValue($this->scopeConfig)); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->items = $this->objectManagerHelper->getObject('Magento\\Sales\\Block\\Adminhtml\\Order\\Creditmemo\\Create\\Items', ['context' => $this->contextMock, 'stockItemService' => $this->stockItemMock, 'registry' => $this->registryMock]); }
/** * Set up * * @return void */ protected function setUp() { $this->objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); $this->contextMock = $this->getMock('Magento\\Backend\\Block\\Template\\Context', [], [], '', false); $this->categoryTreeMock = $this->getMock('Magento\\Catalog\\Model\\Resource\\Category\\Tree', [], [], '', false); $this->registryMock = $this->getMock('Magento\\Framework\\Registry', [], [], '', false); $this->categoryFactoryMock = $this->getMock('Magento\\Catalog\\Model\\CategoryFactory', [], [], '', false); $this->jsonEncoderMock = $this->getMockForAbstractClass('Magento\\Framework\\Json\\EncoderInterface', [], '', false); $this->requestMock = $this->getMockForAbstractClass('Magento\\Framework\\App\\RequestInterface', [], '', false, true, true, ['getParam']); $this->contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->requestMock)); $this->form = $this->objectManager->getObject('Magento\\Catalog\\Block\\Adminhtml\\Category\\Edit\\Form', ['context' => $this->contextMock, 'categoryTree' => $this->categoryTreeMock, 'registry' => $this->registryMock, 'categoryFactory' => $this->categoryFactoryMock, 'jsonEncoder' => $this->jsonEncoderMock]); }
public function setUp() { $this->contextMock = $this->getMock('\\Magento\\Backend\\Block\\Template\\Context', [], [], '', false); $this->mathRandom = $this->getMock('\\Magento\\Framework\\Math\\Random', [], [], '', false); $this->urlBuilder = $this->getMock('\\Magento\\Framework\\UrlInterface', [], [], '', false); $this->contextMock->expects($this->any())->method('getMathRandom')->willReturn($this->mathRandom); $this->contextMock->expects($this->any())->method('getUrlBuilder')->willReturn($this->urlBuilder); $this->registryMock = $this->getMock('\\Magento\\Framework\\Registry', [], [], '', false); $this->formFactoryMock = $this->getMock('\\Magento\\Framework\\Data\\FormFactory', [], [], '', false); $this->jsonEncoderMock = $this->getMock('\\Magento\\Framework\\Json\\EncoderInterface', [], [], '', false); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->block = $objectManager->getObject('\\Magento\\ProductVideo\\Block\\Adminhtml\\Product\\Edit\\NewVideo', ['context' => $this->contextMock, 'registry' => $this->registryMock, 'formFactory' => $this->formFactoryMock, 'jsonEncoder' => $this->jsonEncoderMock]); }
protected function setUp() { $this->contextMock = $this->getMock('Magento\\Backend\\Block\\Template\\Context', [], [], '', false); $this->stockRegistry = $this->getMockBuilder('Magento\\CatalogInventory\\Model\\StockRegistry')->disableOriginalConstructor()->setMethods(['getStockItem', '__wakeup'])->getMock(); $this->stockItemMock = $this->getMock('Magento\\CatalogInventory\\Model\\Stock\\Item', ['getManageStock', '__wakeup'], [], '', false); $this->stockConfiguration = $this->getMock('Magento\\CatalogInventory\\Model\\Configuration', ['__wakeup', 'canSubtractQty'], [], '', false); $this->stockRegistry->expects($this->any())->method('getStockItem')->will($this->returnValue($this->stockItemMock)); $this->registryMock = $this->getMock('Magento\\Framework\\Registry'); $this->scopeConfig = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface'); $this->contextMock->expects($this->once())->method('getScopeConfig')->will($this->returnValue($this->scopeConfig)); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->items = $this->objectManagerHelper->getObject('Magento\\Sales\\Block\\Adminhtml\\Order\\Creditmemo\\Create\\Items', ['context' => $this->contextMock, 'stockRegistry' => $this->stockRegistry, 'stockConfiguration' => $this->stockConfiguration, 'registry' => $this->registryMock]); }
protected function setUp() { $this->eventManagerMock = $this->getMockBuilder(ManagerInterface::class)->disableOriginalConstructor()->getMock(); $this->contextMock = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); $this->resourcePageMock = $this->getMockBuilder(PageResource::class)->disableOriginalConstructor()->setMethods(['getIdFieldName', 'checkIdentifier'])->getMock(); $this->eventManagerMock = $this->getMockBuilder(ManagerInterface::class)->disableOriginalConstructor()->getMock(); $this->resourcesMock = $this->getMockBuilder(AbstractResource::class)->setMethods(['getIdFieldName', 'load', 'checkIdentifier'])->getMockForAbstractClass(); $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)->getMockForAbstractClass(); $this->contextMock->expects($this->any())->method('getEventDispatcher')->willReturn($this->eventManagerMock); $this->resourcePageMock->expects($this->any())->method('getResources')->willReturn($this->resourcesMock); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->model = $objectManager->getObject(Page::class, ['context' => $this->contextMock, 'resource' => $this->resourcesMock]); $objectManager->setBackwardCompatibleProperty($this->model, 'scopeConfig', $this->scopeConfigMock); }
/** * @param $customerData * @param $isSingleStoreMode * @param $canModifyCustomer * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ private function _setupStoreMode($customerData, $isSingleStoreMode, $canModifyCustomer) { $backendSessionMock = $this->getMock('\\Magento\\Backend\\Model\\Session', ['getCustomerData'], [], '', false); $backendSessionMock->expects($this->any())->method('getCustomerData')->will($this->returnValue([])); $layoutMock = $this->getMock('\\Magento\\Framework\\View\\Layout\\Element\\Layout', ['createBlock'], [], '', false); $layoutMock->expects($this->at(0))->method('createBlock')->with('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Group')->will($this->returnValue($this->objectManagerHelper->getObject('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Group'))); $layoutMock->expects($this->at(1))->method('createBlock')->with('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element')->will($this->returnValue($this->objectManagerHelper->getObject('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element'))); if (empty($customerData['id'])) { $layoutMock->expects($this->at(2))->method('createBlock')->with('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Sendemail')->will($this->returnValue($this->objectManagerHelper->getObject('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Sendemail'))); } $urlBuilderMock = $this->getMock('\\Magento\\Backend\\Model\\Url', ['getBaseUrl'], [], '', false); $urlBuilderMock->expects($this->once())->method('getBaseUrl')->will($this->returnValue('someUrl')); $storeManagerMock = $this->getMock('Magento\\Store\\Model\\StoreManager', [], [], '', false); $storeManagerMock->expects($this->any())->method('isSingleStoreMode')->will($this->returnValue($isSingleStoreMode)); $customerObject = $this->getMock('\\Magento\\Customer\\Api\\Data\\CustomerInterface'); if (!empty($customerData['id'])) { $customerObject->expects($this->any())->method('getId')->will($this->returnValue($customerData['id'])); } $fieldset = $this->getMockBuilder('\\Magento\\Framework\\Data\\Form\\Element\\Fieldset')->setMethods(['getForm', 'addField', 'removeField'])->disableOriginalConstructor()->getMock(); $accountForm = $this->getMockBuilder('Magento\\Framework\\Data\\Form')->setMethods(['create', 'addFieldset', 'getElement', 'setValues'])->disableOriginalConstructor()->getMock(); $accountForm->expects($this->any())->method('addFieldset')->with('base_fieldset')->will($this->returnValue($fieldset)); $accountForm->expects($this->any())->method('setValues')->will($this->returnValue($accountForm)); $fieldset->expects($this->any())->method('getForm')->will($this->returnValue($accountForm)); $formElement = $this->getMockBuilder('\\Magento\\Framework\\Data\\Form\\Element\\Select')->setMethods(['setRenderer', 'addClass', 'setDisabled'])->disableOriginalConstructor()->getMock(); $formElement->expects($this->any())->method('setRenderer')->will($this->returnValue(null)); $formElement->expects($this->any())->method('addClass')->will($this->returnValue(null)); $formElement->expects($this->any())->method('setDisabled')->will($this->returnValue(null)); $accountForm->expects($this->any())->method('getElement')->withAnyParameters()->will($this->returnValue($formElement)); $fieldset->expects($this->any())->method('addField')->will($this->returnValue($formElement)); $customerForm = $this->getMock('\\Magento\\Customer\\Model\\Metadata\\Form', ['getAttributes'], [], '', false); $customerForm->expects($this->any())->method('getAttributes')->will($this->returnValue([])); $this->contextMock->expects($this->any())->method('getBackendSession')->will($this->returnValue($backendSessionMock)); $this->contextMock->expects($this->any())->method('getLayout')->will($this->returnValue($layoutMock)); $this->contextMock->expects($this->any())->method('getUrlBuilder')->will($this->returnValue($urlBuilderMock)); $this->contextMock->expects($this->any())->method('getStoreManager')->will($this->returnValue($storeManagerMock)); $this->customerFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerObject)); $this->dataObjectHelperMock->expects($this->once())->method('populateWithArray'); $this->options->expects($this->any())->method('getNamePrefixOptions')->will($this->returnValue(['Pref1', 'Pref2'])); $this->options->expects($this->any())->method('getNameSuffixOptions')->will($this->returnValue(['Suf1', 'Suf2'])); $this->formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($accountForm)); $this->extensibleDataObjectConverterMock->expects($this->any())->method('toFlatArray')->will($this->returnValue($customerData)); $this->customerFormFactoryMock->expects($this->any())->method('create')->with('customer', 'adminhtml_customer', $this->extensibleDataObjectConverterMock->toFlatArray($customerObject, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface'))->will($this->returnValue($customerForm)); $this->accountManagementMock->expects($this->any())->method('isReadOnly')->withAnyParameters()->will($this->returnValue(!$canModifyCustomer)); $this->accountManagementMock->expects($this->any())->method('getConfirmationStatus')->withAnyParameters()->will($this->returnValue(AccountManagementInterface::ACCOUNT_CONFIRMED)); }
public function setUp() { $this->modelContext = $this->getMock('Magento\\Framework\\Model\\Context', [], [], '', false); $this->registry = $this->getMock('Magento\\Framework\\Registry', [], [], '', false); $this->extensionFactory = $this->getMock('Magento\\Framework\\Api\\ExtensionAttributesFactory', [], [], '', false); $this->customAttributeFactory = $this->getMock('Magento\\Framework\\Api\\AttributeValueFactory', [], [], '', false); $this->eavConfig = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false); $this->eavTypeFactory = $this->getMock('Magento\\Eav\\Model\\Entity\\TypeFactory', [], [], '', false); $this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManager', [], [], '', false); $this->resourceHelper = $this->getMock('Magento\\Eav\\Model\\ResourceModel\\Helper', [], [], '', false); $this->universalFactory = $this->getMock('Magento\\Framework\\Validator\\UniversalFactory', [], [], '', false); $this->optionDataFactory = $this->getMock('Magento\\Eav\\Api\\Data\\AttributeOptionInterfaceFactory', [], [], '', false); $this->dataObjectProcessor = $this->getMock('Magento\\Framework\\Reflection\\DataObjectProcessor', [], [], '', false); $this->dataObjectHelper = $this->getMock('Magento\\Framework\\Api\\DataObjectHelper', [], [], '', false); $this->localeDate = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\Timezone', [], [], '', false); $this->localeDate->expects($this->any())->method('getDateFormat')->will($this->returnValue('12-12-2012')); $this->reservedAttributeList = $this->getMock('Magento\\Catalog\\Model\\Product\\ReservedAttributeList', [], [], '', false); $this->localeResolver = $this->getMock('Magento\\Framework\\Locale\\Resolver', [], [], '', false); $this->resource = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product', [], [], '', false); $this->resourceCollection = $this->getMockForAbstractClass('Magento\\Framework\\Data\\Collection\\AbstractDb', [], '', false); $this->context = $this->getMock('Magento\\Backend\\Block\\Template\\Context', ['getFileSystem', 'getEscaper', 'getLocaleDate', 'getLayout'], [], '', false); $filesystem = $this->getMock('Magento\\Framework\\Filesystem', [], [], '', false); $this->context->expects($this->any())->method('getFileSystem')->will($this->returnValue($filesystem)); $escaper = $this->getMock('Magento\\Framework\\Escaper', ['escapeHtml'], [], '', false); $escaper->expects($this->any())->method('escapeHtml')->will($this->returnValue('')); $this->context->expects($this->any())->method('getEscaper')->will($this->returnValue($escaper)); $timeZone = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\TimeZone', [], [], '', false); $timeZone->expects($this->any())->method('getDateFormat')->will($this->returnValue('M/d/yy')); $this->context->expects($this->any())->method('getLocaleDate')->will($this->returnValue($timeZone)); $dateBlock = $this->getMock('Magento\\Framework\\View\\Element\\Html\\Date', ['setValue', 'getHtml', 'setId', 'getId'], [], '', false); $dateBlock->expects($this->any())->method('setValue')->will($this->returnSelf()); $dateBlock->expects($this->any())->method('getHtml')->will($this->returnValue('')); $dateBlock->expects($this->any())->method('setId')->will($this->returnSelf()); $dateBlock->expects($this->any())->method('getId')->will($this->returnValue(1)); $layout = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false); $layout->expects($this->any())->method('createBlock')->will($this->returnValue($dateBlock)); $this->context->expects($this->any())->method('getLayout')->will($this->returnValue($layout)); $this->backendHelper = $this->getMock('Magento\\Backend\\Helper\\Data', [], [], '', false); $this->importExportData = $this->getMock('Magento\\ImportExport\\Helper\\Data', [], [], '', false); $this->dateTimeFormatter = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\DateTimeFormatterInterface'); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->filter = $this->objectManagerHelper->getObject('Magento\\ImportExport\\Block\\Adminhtml\\Export\\Filter', ['context' => $this->context, 'backendHelper' => $this->backendHelper, 'importExportData' => $this->importExportData]); }
protected function initContext() { $this->request = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock(); $this->context = $this->getMockBuilder('Magento\\Backend\\Block\\Template\\Context')->disableOriginalConstructor()->getMock(); $this->context->expects($this->any())->method('getRequest')->willReturn($this->request); }