/** * Test for addFieldsToResponse method * * @return void */ public function testAddFieldsToResponseSuccess() { $testData = $this->getAddFieldsToResponseSuccessTestData(); $observerMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock(); $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock(); $orderPaymentMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Payment')->disableOriginalConstructor()->getMock(); $instanceMock = $this->getMockBuilder('Magento\\Authorizenet\\Model\\Directpost')->disableOriginalConstructor()->getMock(); $requestToAuthorizenetMock = $this->getMockBuilder('Magento\\Authorizenet\\Model\\Directpost\\Request')->disableOriginalConstructor()->setMethods(['setControllerActionName', 'setIsSecure', 'getData'])->getMock(); $requestMock = $this->getMockBuilder('Magento\\Framework\\App\\RequestInterface')->disableOriginalConstructor()->setMethods(['getControllerName'])->getMockForAbstractClass(); $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $this->coreRegistryMock->expects($this->once())->method('registry')->with('directpost_order')->willReturn($orderMock); $orderMock->expects($this->once())->method('getId')->willReturn($testData['order.getId']); $orderMock->expects($this->once())->method('getPayment')->willReturn($orderPaymentMock); $orderPaymentMock->expects($this->once())->method('getMethod')->willReturn($testData['orderPayment.getMethod']); $this->paymentMock->expects($this->exactly(2))->method('getCode')->willReturn($testData['payment.getCode']); $observerMock->expects($this->atLeastOnce())->method('getData')->willReturnMap($testData['observer.getData']); $this->resultMock->expects($this->once())->method('getData')->willReturn($testData['result.getData']); $orderMock->expects($this->atLeastOnce())->method('getIncrementId')->willReturn($testData['order.getIncrementId']); $this->sessionMock->expects($this->once())->method('addCheckoutOrderIncrementId')->with($testData['session.addCheckoutOrderIncrementId']); $this->sessionMock->expects($this->once())->method('setLastOrderIncrementId')->with($testData['session.setLastOrderIncrementId']); $orderPaymentMock->expects($this->once())->method('getMethodInstance')->willReturn($instanceMock); $instanceMock->expects($this->once())->method('generateRequestFromOrder')->with($orderMock)->willReturn($requestToAuthorizenetMock); $this->actionMock->expects($this->once())->method('getRequest')->willReturn($requestMock); $requestMock->expects($this->once())->method('getControllerName')->willReturn($testData['request.getControllerName']); $requestToAuthorizenetMock->expects($this->once())->method('setControllerActionName')->with($testData['requestToAuthorizenet.setControllerActionName']); $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock); $storeMock->expects($this->once())->method('isCurrentlySecure')->willReturn($testData['store.isCurrentlySecure']); $requestToAuthorizenetMock->expects($this->once())->method('setIsSecure')->with($testData['requestToAuthorizenet.setIsSecure']); $requestToAuthorizenetMock->expects($this->once())->method('getData')->willReturn($testData['requestToAuthorizenet.getData']); $this->resultMock->expects($this->once())->method('setData')->with($testData['result.setData']); $this->addFieldsToResponseObserver->execute($observerMock); }
/** * @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->stockConfiguration->expects($this->once())->method('canSubtractQty')->will($this->returnValue($canReturnToStock)); if ($canReturnToStock) { $orderItem = $this->getMock('Magento\\Sales\\Model\\Order\\Item', ['getProductId', '__wakeup', 'getStore'], [], '', false); $store = $this->getMock('Magento\\Store\\Model\\Store', ['getWebsiteId'], [], '', false); $store->expects($this->once())->method('getWebsiteId')->will($this->returnValue(10)); $orderItem->expects($this->any())->method('getStore')->will($this->returnValue($store)); $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->any())->method('getOrderItem')->will($this->returnValue($orderItem)); $this->stockItemMock->expects($this->once())->method('getManageStock')->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 testGetStore() { $this->registryMock->expects($this->once())->method('registry')->with('current_store')->willReturn($this->storeMock); $this->assertInstanceOf(StoreInterface::class, $this->model->getStore()); // Lazy loading $this->assertInstanceOf(StoreInterface::class, $this->model->getStore()); }
/** * Test protected `_toHtml` method via public `toHtml` method. */ public function testToHtml() { $eventManager = $this->getMockBuilder('Magento\\Framework\\Event\\Manager')->disableOriginalConstructor()->setMethods(['dispatch'])->getMock(); $eventManager->expects($this->once())->method('dispatch')->will($this->returnValue(true)); $scopeConfig = $this->getMockBuilder('\\Magento\\Framework\\App\\Config')->setMethods(['getValue'])->disableOriginalConstructor()->getMock(); $scopeConfig->expects($this->once())->method('getValue')->withAnyParameters()->will($this->returnValue(false)); $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['setStoreId', 'load', 'getId', '__wakeup', '__sleep'])->getMock(); $product->expects($this->once())->method('setStoreId')->will($this->returnSelf()); $product->expects($this->once())->method('load')->will($this->returnSelf()); $product->expects($this->once())->method('getId')->will($this->returnValue(1)); $optionsBlock = $this->getMockBuilder('Magento\\Catalog\\Block\\Adminhtml\\Product\\Edit\\Tab\\Options\\Option')->setMethods(['setIgnoreCaching', 'setProduct', 'getOptionValues'])->disableOriginalConstructor()->getMock(); $optionsBlock->expects($this->once())->method('setIgnoreCaching')->with(true)->will($this->returnSelf()); $optionsBlock->expects($this->once())->method('setProduct')->with($product)->will($this->returnSelf()); $optionsBlock->expects($this->once())->method('getOptionValues')->will($this->returnValue([])); $layout = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Element\\Layout')->disableOriginalConstructor()->setMethods(['createBlock'])->getMock(); $layout->expects($this->once())->method('createBlock')->with('Magento\\Catalog\\Block\\Adminhtml\\Product\\Edit\\Tab\\Options\\Option')->will($this->returnValue($optionsBlock)); $request = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->setMethods(['getParam'])->disableOriginalConstructor()->getMock(); $request->expects($this->once())->method('getParam')->with('store')->will($this->returnValue(0)); $this->context->expects($this->once())->method('getEventManager')->will($this->returnValue($eventManager)); $this->context->expects($this->once())->method('getScopeConfig')->will($this->returnValue($scopeConfig)); $this->context->expects($this->once())->method('getLayout')->will($this->returnValue($layout)); $this->context->expects($this->once())->method('getRequest')->will($this->returnValue($request)); $this->registry->expects($this->once())->method('registry')->with('import_option_products')->will($this->returnValue([1])); $this->productFactory->expects($this->once())->method('create')->will($this->returnValue($product)); $this->block = $this->objectManagerHelper->getObject('Magento\\Catalog\\Block\\Adminhtml\\Product\\Options\\Ajax', ['context' => $this->context, 'jsonEncoder' => $this->encoderInterface, 'productFactory' => $this->productFactory, 'registry' => $this->registry]); $this->block->toHtml(); }
/** * @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 testToOptionArray() { $inputTypesSet = [['value' => 'text', 'label' => 'Text Field'], ['value' => 'textarea', 'label' => 'Text Area'], ['value' => 'date', 'label' => 'Date'], ['value' => 'boolean', 'label' => 'Yes/No'], ['value' => 'multiselect', 'label' => 'Multiple Select'], ['value' => 'select', 'label' => 'Dropdown'], ['value' => 'price', 'label' => 'Price'], ['value' => 'media_image', 'label' => 'Media Image']]; $this->registry->expects($this->once())->method('registry'); $this->registry->expects($this->once())->method('register'); $this->assertEquals($inputTypesSet, $this->inputtypeModel->toOptionArray()); }
public function testGetLinkData() { $expectingFileData = ['file' => ['file' => 'file/link.gif', 'name' => '<a href="final_url">link.gif</a>', 'size' => '1.1', 'status' => 'old'], 'sample_file' => ['file' => 'file/sample.gif', 'name' => '<a href="final_url">sample.gif</a>', 'size' => '1.1', 'status' => 'old']]; $this->productModel->expects($this->any())->method('getTypeId')->will($this->returnValue('downloadable')); $this->productModel->expects($this->any())->method('getTypeInstance')->will($this->returnValue($this->downloadableProductModel)); $this->productModel->expects($this->any())->method('getStoreId')->will($this->returnValue(0)); $this->downloadableProductModel->expects($this->any())->method('getLinks')->will($this->returnValue([$this->downloadableLinkModel])); $this->coreRegistry->expects($this->any())->method('registry')->will($this->returnValue($this->productModel)); $this->downloadableLinkModel->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->downloadableLinkModel->expects($this->any())->method('getTitle')->will($this->returnValue('Link Title')); $this->downloadableLinkModel->expects($this->any())->method('getPrice')->will($this->returnValue('10')); $this->downloadableLinkModel->expects($this->any())->method('getNumberOfDownloads')->will($this->returnValue('6')); $this->downloadableLinkModel->expects($this->any())->method('getLinkUrl')->will($this->returnValue(null)); $this->downloadableLinkModel->expects($this->any())->method('getLinkType')->will($this->returnValue('file')); $this->downloadableLinkModel->expects($this->any())->method('getSampleFile')->will($this->returnValue('file/sample.gif')); $this->downloadableLinkModel->expects($this->any())->method('getSampleType')->will($this->returnValue('file')); $this->downloadableLinkModel->expects($this->any())->method('getSortOrder')->will($this->returnValue(0)); $this->downloadableLinkModel->expects($this->any())->method('getLinkFile')->will($this->returnValue('file/link.gif')); $this->downloadableLinkModel->expects($this->any())->method('getStoreTitle')->will($this->returnValue('Store Title')); $this->escaper->expects($this->any())->method('escapeHtml')->will($this->returnValue('Link Title')); $this->fileHelper->expects($this->any())->method('getFilePath')->will($this->returnValue('/file/path/link.gif')); $this->fileHelper->expects($this->any())->method('ensureFileInFilesystem')->will($this->returnValue(true)); $this->fileHelper->expects($this->any())->method('getFileSize')->will($this->returnValue('1.1')); $this->urlBuilder->expects($this->any())->method('getUrl')->will($this->returnValue('final_url')); $linkData = $this->block->getLinkData(); foreach ($linkData as $link) { $fileSave = $link->getFileSave(0); $sampleFileSave = $link->getSampleFileSave(0); $this->assertEquals($expectingFileData['file'], $fileSave); $this->assertEquals($expectingFileData['sample_file'], $sampleFileSave); } }
public function testToHtml() { $fieldSet = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Fieldset', [], [], '', false); $form = $this->getMock('Magento\\Framework\\Data\\Form', [], [], '', false); $attributeModel = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], [], '', false); $entityType = $this->getMock('Magento\\Eav\\Model\\Entity\\Type', [], [], '', false); $formElement = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Text', ['setDisabled'], [], '', false); $directoryReadInterface = $this->getMock('\\Magento\\Framework\\Filesystem\\Directory\\ReadInterface'); $this->registry->expects($this->any())->method('registry')->with('entity_attribute')->willReturn($attributeModel); $this->formFactory->expects($this->any())->method('create')->willReturn($form); $form->expects($this->any())->method('addFieldset')->willReturn($fieldSet); $form->expects($this->any())->method('getElement')->willReturn($formElement); $fieldSet->expects($this->any())->method('addField')->willReturnSelf(); $attributeModel->expects($this->any())->method('getDefaultValue')->willReturn('default_value'); $attributeModel->expects($this->any())->method('setDisabled')->willReturnSelf(); $attributeModel->expects($this->any())->method('getId')->willReturn(1); $attributeModel->expects($this->any())->method('getEntityType')->willReturn($entityType); $attributeModel->expects($this->any())->method('getIsUserDefined')->willReturn(false); $attributeModel->expects($this->any())->method('getAttributeCode')->willReturn('attribute_code'); $this->localeDate->expects($this->any())->method('getDateFormat')->willReturn('mm/dd/yy'); $entityType->expects($this->any())->method('getEntityTypeCode')->willReturn('entity_type_code'); $this->eavData->expects($this->any())->method('getFrontendClasses')->willReturn([]); $formElement->expects($this->exactly(3))->method('setDisabled')->willReturnSelf(); $this->yesNo->expects($this->any())->method('toOptionArray')->willReturn(['yes', 'no']); $this->filesystem->expects($this->any())->method('getDirectoryRead')->willReturn($directoryReadInterface); $directoryReadInterface->expects($this->any())->method('getRelativePath')->willReturn('relative_path'); $this->block->setData(['action' => 'save']); $this->block->toHtml(); }
protected function setUp() { $this->registryMock = $this->getMockBuilder(Registry::class)->disableOriginalConstructor()->getMock(); $this->productMock = $this->getMockBuilder(ProductInterface::class)->setMethods(['isReadonly', 'isDuplicable'])->getMockForAbstractClass(); $this->registryMock->expects(static::any())->method('registry')->with('current_product')->willReturn($this->productMock); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->saveButton = $this->objectManagerHelper->getObject(SaveButton::class, ['registry' => $this->registryMock]); }
/** * @param array $result * @param bool $expectedValue * @dataProvider getButtonDataProvider */ public function testGetButtonData($result, $expectedValue) { $this->registryMock->expects($this->any())->method('registry')->willReturn(1); $this->customerRegistryMock->expects($this->once())->method('retrieve')->willReturn($this->customerModelMock); $this->customerModelMock->expects($this->once())->method('isCustomerLocked')->willReturn($expectedValue); $this->urlBuilderMock->expects($this->any())->method('getUrl')->willReturn('http://website.com/'); $this->assertEquals($result, $this->block->getButtonData()); }
public function testGetCurrentCategoryKey() { $categoryKey = 101; $category = $this->getMock('Magento\\Catalog\\Model\\Category', [], [], '', false); $category->expects($this->any())->method('getPath')->willReturn($categoryKey); $this->registry->expects($this->any())->method('registry')->with('current_category')->willReturn($category); $this->assertEquals($categoryKey, $this->block->getCurrentCategoryKey()); }
protected function setUp() { $this->objectManager = new ObjectManager($this); $this->registryMock = $this->getMockBuilder('Magento\\Framework\\Registry')->setMethods(['registry'])->getMock(); $this->productMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->getMockForAbstractClass(); $this->registryMock->expects($this->once())->method('registry')->with('current_product')->willReturn($this->productMock); $this->model = $this->objectManager->getObject('Magento\\Catalog\\Model\\Locator\\RegistryLocator', ['registry' => $this->registryMock]); }
public function testGetIdentities() { $productTags = ['catalog_product_1']; $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false); $product->expects($this->once())->method('getIdentities')->will($this->returnValue($productTags)); $this->registry->expects($this->once())->method('registry')->with('current_product')->will($this->returnValue($product)); $this->assertEquals($productTags, $this->block->getIdentities()); }
public function testGetIdentities() { $categoryTags = array('catalog_category_1'); $category = $this->getMock('Magento\\Catalog\\Model\\Category', array(), array(), '', false); $category->expects($this->once())->method('getIdentities')->will($this->returnValue($categoryTags)); $this->registry->expects($this->once())->method('registry')->with('current_category')->will($this->returnValue($category)); $this->assertEquals($categoryTags, $this->block->getIdentities()); }
/** * @covers \Magento\Cms\Block\Adminhtml\Block\Edit::getHeaderText * @param integer|null $modelBlockId * * @dataProvider getHeaderTextDataProvider */ public function testGetHeaderText($modelBlockId) { $title = 'some title'; $escapedTitle = 'escaped title'; $this->registryMock->expects($this->atLeastOnce())->method('registry')->with('cms_block')->willReturn($this->modelBlockMock); $this->modelBlockMock->expects($this->atLeastOnce())->method('getId')->willReturn($modelBlockId); $this->modelBlockMock->expects($this->any())->method('getTitle')->willReturn($title); $this->escaperMock->expects($this->any())->method('escapeHtml')->with($title)->willReturn($escapedTitle); $this->assertInstanceOf('Magento\\Framework\\Phrase', $this->this->getHeaderText()); }
public function testToOptionArray() { $collection = $this->getMock('Magento\\Email\\Model\\Resource\\Template\\Collection', [], [], '', false); $collection->expects($this->once())->method('toOptionArray')->will($this->returnValue([['value' => 'template_one', 'label' => 'Template One'], ['value' => 'template_two', 'label' => 'Template Two']])); $this->_coreRegistry->expects($this->once())->method('registry')->with('config_system_email_template')->will($this->returnValue($collection)); $this->_emailConfig->expects($this->once())->method('getTemplateLabel')->with('template_new')->will($this->returnValue('Template New')); $expectedResult = [['value' => 'template_new', 'label' => 'Template New (Default)'], ['value' => 'template_one', 'label' => 'Template One'], ['value' => 'template_two', 'label' => 'Template Two']]; $this->_model->setPath('template/new'); $this->assertEquals($expectedResult, $this->_model->toOptionArray()); }
/** * @covers \Magento\Cms\Block\Adminhtml\Block\Edit::getHeaderText * @param integer|null $modelBlockId * * @dataProvider getHeaderTextDataProvider */ public function testGetHeaderText($modelBlockId) { $title = 'some title'; $escapedTitle = 'escaped title'; $this->registryMock->expects($this->atLeastOnce())->method('registry')->with('cms_block')->willReturn($this->modelBlockMock); $this->modelBlockMock->expects($this->atLeastOnce())->method('getId')->willReturn($modelBlockId); $this->modelBlockMock->expects($this->any())->method('getTitle')->willReturn($title); $this->escaperMock->expects($this->any())->method('escapeHtml')->with($title)->willReturn($escapedTitle); $this->assertInternalType('string', $this->this->getHeaderText()); }
public function testSetTemplateNoProduct() { $this->_helper->expects($this->once())->method('isStockAlertAllowed')->will($this->returnValue(true)); $this->_helper->expects($this->never())->method('getSaveUrl'); $this->_registry->expects($this->any())->method('registry')->with('current_product')->will($this->returnValue(null)); $this->_block->setLayout($this->_layout); $this->_block->setTemplate('path/to/template.phtml'); $this->assertEquals('', $this->_block->getTemplate()); $this->assertNull($this->_block->getSignupUrl()); }
/** * Test getMediaEmptyGalleryDataJson() */ public function testGetMediaEmptyGalleryDataJson() { $mediaGalleryData = []; $this->coreRegistry->expects($this->any())->method('registry')->willReturn($this->productModelMock); $typeInstance = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Type\\AbstractType', [], [], '', false); $typeInstance->expects($this->any())->method('getStoreFilter')->willReturn('_cache_instance_store_filter'); $this->productModelMock->expects($this->any())->method('getTypeInstance')->willReturn($typeInstance); $this->productModelMock->expects($this->any())->method('getMediaGalleryImages')->willReturn($mediaGalleryData); $this->gallery->getMediaGalleryDataJson(); }
public function testPrepareLayoutSuccessOnFalseGetId() { $tab = 'tab'; $this->registryMock->expects($this->once())->method('registry')->willReturn($this->layoutInterfaceMock); $this->layoutInterfaceMock->expects($this->any())->method('createBlock')->willReturnSelf(); $this->layoutInterfaceMock->expects($this->once())->method('setRole')->willReturnSelf(); $this->layoutInterfaceMock->expects($this->once())->method('setActive')->willReturn($tab); $this->layoutInterfaceMock->expects($this->once())->method('getId')->willReturn(false); $this->assertInstanceOf('Magento\\Backend\\Block\\Widget\\Tabs', $this->invokeMethod($this->model, '_prepareLayout')); }
public function testExecuteWithException() { $objectMock = $this->getMockBuilder('Magento\\Framework\\DataObject')->disableOriginalConstructor()->getMock(); $this->transactionMock->expects($this->once())->method('getResponseObject')->willReturn($objectMock); $this->responseValidatorMock->expects($this->once())->method('validate')->with($objectMock)->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('Error'))); $this->coreRegistryMock->expects($this->once())->method('register')->with('transparent_form_params', $this->arrayHasKey('error')); $this->resultLayoutMock->expects($this->once())->method('addDefaultHandle')->willReturnSelf(); $this->resultLayoutMock->expects($this->once())->method('getLayout')->willReturn($this->getLayoutMock()); $this->assertInstanceOf('\\Magento\\Framework\\Controller\\ResultInterface', $this->object->executeInternal()); }
protected function setUp() { $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->authorizationMock = $this->getMock('\\Magento\\Framework\\Authorization', [], [], '', false); $this->coreRegistryMock = $this->getMock('Magento\\Framework\\Registry', [], [], '', false); $this->orderMock = $this->getMock('\\Magento\\Sales\\Model\\Order', [], [], '', false); $this->paymentMock = $this->getMock('\\Magento\\Sales\\Model\\Order\\Payment', [], [], '', false); $this->coreRegistryMock->expects($this->any())->method('registry')->with('current_order')->willReturn($this->orderMock); $this->orderMock->expects($this->any())->method('getPayment')->willReturn($this->paymentMock); $this->transactionsTab = $this->objectManager->getObject('Magento\\Sales\\Block\\Adminhtml\\Order\\View\\Tab\\Transactions', ['authorization' => $this->authorizationMock, 'registry' => $this->coreRegistryMock]); }
/** * @param bool $isAllowed * @dataProvider dataProviderBoolValues */ public function testIsEverythingAllowed($isAllowed) { $id = 10; $this->coreRegistryMock->expects($this->once())->method('registry')->with(\Magento\User\Controller\Adminhtml\User\Role\SaveRole::RESOURCE_ALL_FORM_DATA_SESSION_KEY)->willReturn(true); if ($isAllowed) { $this->rootResourceMock->expects($this->exactly(2))->method('getId')->willReturnOnConsecutiveCalls($id, $id); } else { $this->rootResourceMock->expects($this->exactly(2))->method('getId')->willReturnOnConsecutiveCalls(11, $id); } $this->assertEquals($isAllowed, $this->model->isEverythingAllowed()); }
/** * @param int $productId * @param int $qtyInc * @param bool $isSaleable * @param int|bool $result * @dataProvider getProductQtyIncrementsDataProvider */ public function testGetProductQtyIncrements($productId, $qtyInc, $isSaleable, $result) { $this->stockItemService->expects($this->once())->method('getQtyIncrements')->with($this->equalTo($productId))->will($this->returnValue($qtyInc)); $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false); $product->expects($this->once())->method('getId')->will($this->returnValue($productId)); $product->expects($this->once())->method('isSaleable')->will($this->returnValue($isSaleable)); $this->registryMock->expects($this->any())->method('registry')->with('current_product')->will($this->returnValue($product)); $this->assertSame($result, $this->block->getProductQtyIncrements()); // test lazy load $this->assertSame($result, $this->block->getProductQtyIncrements()); }
public function testGetPriceRangeWithRangeCalculation() { /** @var \Magento\Catalog\Model\Category|MockObject $category */ $category = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Category')->disableOriginalConstructor()->setMethods(['getFilterPriceRange'])->getMock(); $priceRange = 0; $category->expects($this->once())->method('getFilterPriceRange')->will($this->returnValue($priceRange)); $this->coreRegistry->expects($this->once())->method('registry')->with('current_category_filter')->will($this->returnValue($category)); $maxPrice = 8000; $this->productCollection->expects($this->once())->method('getMaxPrice')->will($this->returnValue($maxPrice)); $this->target->getPriceRange(); }
/** * @covers \Magento\Authorizenet\Controller\Directpost\Payment\Redirect::execute */ public function testExecute() { $url = 'http://test.com/redirect?=test'; $params = ['order_success' => $url]; $this->request->expects(static::once())->method('getParams')->willReturn($params); $this->coreRegistry->expects(static::once())->method('register')->with(Iframe::REGISTRY_KEY, []); $this->view->expects(static::once())->method('addPageLayoutHandles'); $this->view->expects(static::once())->method('loadLayout')->with(false)->willReturnSelf(); $this->view->expects(static::once())->method('renderLayout'); $this->controller->execute(); }
public function testGetIdentities() { $productTags = ['catalog_product_1']; $childProduct = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false); $childProduct->expects($this->once())->method('getIdentities')->will($this->returnValue($productTags)); $typeInstance = $this->getMock('Magento\\GroupedProduct\\Model\\Product\\Type\\Grouped', [], [], '', false); $typeInstance->expects($this->once())->method('getAssociatedProducts')->will($this->returnValue([$childProduct])); $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false); $product->expects($this->once())->method('getTypeInstance')->will($this->returnValue($typeInstance)); $this->registry->expects($this->any())->method('registry')->with('current_product')->will($this->returnValue($product)); $this->assertEquals($productTags, $this->block->getIdentities()); }
public function testAroundResultWithPluginDeveloperMode() { $this->registry->expects($this->once())->method('registry')->with('use_page_cache_plugin')->willReturn(true); $this->state->expects($this->once())->method('getMode')->willReturn(\Magento\Framework\App\State::MODE_DEVELOPER); $this->header->expects($this->any())->method('getFieldValue')->willReturnOnConsecutiveCalls('test', 'tag,tag2'); $this->response->expects($this->any())->method('setHeader')->withConsecutive(['X-Magento-Cache-Control', 'test'], ['X-Magento-Cache-Debug', 'MISS', true], ['X-Magento-Tags', 'tag,tag2,' . \Magento\PageCache\Model\Cache\Type::CACHE_TAG]); $this->response->expects($this->once())->method('clearHeader')->with('X-Magento-Tags'); $this->registry->expects($this->once())->method('registry')->with('use_page_cache_plugin')->will($this->returnValue(true)); $this->kernel->expects($this->once())->method('process')->with($this->response); $result = call_user_func($this->closure); $this->assertSame($result, $this->plugin->aroundRenderResult($this->subject, $this->closure, $this->response)); }
public function testToHtmlProductFromParentBlock() { $expectedValue = 'string'; $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false); $this->registry->expects($this->never())->method('registry'); $block = $this->getMock('Magento\\Framework\\Pricing\\Render', ['getProductItem', 'render'], [], '', false); $arguments = $this->object->getData(); $arguments['render_block'] = $this->object; $block->expects($this->any())->method('render')->with($this->equalTo('test_price_type_code'), $this->equalTo($product), $this->equalTo($arguments))->will($this->returnValue($expectedValue)); $block->expects($this->any())->method('getProductItem')->will($this->returnValue($product)); $this->layout->expects($this->once())->method('getParentName')->will($this->returnValue('parent_name')); $this->layout->expects($this->any())->method('getBlock')->will($this->returnValue($block)); $this->assertEquals($expectedValue, $this->object->toHtml()); }
public function testGetSampleData() { $expectingFileData = array('sample_file' => array('file' => 'file/sample.gif', 'name' => '<a href="final_url">sample.gif</a>', 'size' => '1.1', 'status' => 'old')); $this->productModel->expects($this->any())->method('getTypeId')->will($this->returnValue('downloadable')); $this->productModel->expects($this->any())->method('getTypeInstance')->will($this->returnValue($this->downloadableProductModel)); $this->productModel->expects($this->any())->method('getStoreId')->will($this->returnValue(0)); $this->downloadableProductModel->expects($this->any())->method('getSamples')->will($this->returnValue(array($this->downloadableSampleModel))); $this->coreRegistry->expects($this->any())->method('registry')->will($this->returnValue($this->productModel)); $this->downloadableSampleModel->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->downloadableSampleModel->expects($this->any())->method('getTitle')->will($this->returnValue('Sample Title')); $this->downloadableSampleModel->expects($this->any())->method('getSampleUrl')->will($this->returnValue(null)); $this->downloadableSampleModel->expects($this->any())->method('getSampleFile')->will($this->returnValue('file/sample.gif')); $this->downloadableSampleModel->expects($this->any())->method('getSampleType')->will($this->returnValue('file')); $this->downloadableSampleModel->expects($this->any())->method('getSortOrder')->will($this->returnValue(0)); $this->escaper->expects($this->any())->method('escapeHtml')->will($this->returnValue('Sample Title')); $this->fileHelper->expects($this->any())->method('getFilePath')->will($this->returnValue('/file/path/sample.gif')); $this->fileHelper->expects($this->any())->method('ensureFileInFilesystem')->will($this->returnValue(true)); $this->fileHelper->expects($this->any())->method('getFileSize')->will($this->returnValue('1.1')); $this->urlBuilder->expects($this->any())->method('getUrl')->will($this->returnValue('final_url')); $sampleData = $this->block->getSampleData(); foreach ($sampleData as $sample) { $fileSave = $sample->getFileSave(0); $this->assertEquals($expectingFileData['sample_file'], $fileSave); } }