/** * Testing \Magento\Framework\Validator\Entity\Properties::isValid with changed data and invoked setter */ public function testIsValidFailed() { $this->_object->expects($this->once())->method('hasDataChanges')->will($this->returnValue(true)); $this->_object->expects($this->once())->method('getData')->with('attr1')->will($this->returnValue(1)); $this->_object->expects($this->once())->method('getOrigData')->with('attr1')->will($this->returnValue(2)); $validator = new \Magento\Framework\Validator\Entity\Properties(); $validator->setReadOnlyProperties(['attr1']); $this->assertFalse($validator->isValid($this->_object)); }
public function testInitWithNonDecimalQty() { $quoteItemMock = $this->getMock('\\Magento\\Quote\\Model\\Quote\\Item', ['getStockId', 'getIsQtyDecimal', '__wakeup'], [], '', false); $this->productMock->expects($this->once())->method('getId')->will($this->returnSelf()); $this->productMock->expects($this->never())->method('setIsQtyDecimal'); $this->productMock->expects($this->once())->method('setCartQty')->will($this->returnSelf()); $this->configMock->expects($this->exactly(2))->method('getQty')->will($this->returnValue(10)); $this->configMock->expects($this->once())->method('setQty')->will($this->returnSelf()); $this->quoteMock->expects($this->once())->method('addProduct')->will($this->returnValue($quoteItemMock)); $this->assertInstanceOf('Magento\\Quote\\Model\\Quote\\Item', $this->model->init($this->quoteMock, $this->productMock, $this->configMock)); }
/** * @covers \Magento\Cms\Model\Observer::noCookies * @param string $pageUrl * @dataProvider noCookiesDataProvider */ public function testNoCookies($pageUrl) { $pageId = 1; $this->observerMock->expects($this->atLeastOnce())->method('getEvent')->willReturn($this->eventMock); $this->eventMock->expects($this->atLeastOnce())->method('getRedirect')->willReturn($this->objectMock); $this->scopeConfigMock->expects($this->atLeastOnce())->method('getValue')->with('web/default/cms_no_cookies', 'store')->willReturn($pageId); $this->cmsPageMock->expects($this->atLeastOnce())->method('getPageUrl')->with($pageId)->willReturn($pageUrl); $this->objectMock->expects($this->any())->method('setRedirectUrl')->with($pageUrl)->willReturnSelf(); $this->objectMock->expects($this->any())->method('setRedirect')->with(true)->willReturnSelf(); $this->objectMock->expects($this->any())->method('setPath')->with('cms/index/noCookies')->willReturnSelf(); $this->objectMock->expects($this->any())->method('setArguments')->with([])->willReturnSelf(); $this->assertEquals($this->this, $this->this->noCookies($this->observerMock)); }
protected function setUp() { $this->loggerMock = $this->getMock('Psr\\Log\\LoggerInterface'); $this->quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false); $this->orderMock = $this->getMock('Magento\\Sales\\Model\\Order', [], [], '', false); $this->paymentMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Payment', [], [], '', false); $this->orderSenderMock = $this->getMock('Magento\\Sales\\Model\\Order\\Email\\Sender\\OrderSender', [], [], '', false); $eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods(['getQuote', 'getOrder'])->getMock(); $this->observerMock = $this->getMock('Magento\\Framework\\Object', ['getEvent'], [], '', false); $this->observerMock->expects($this->any())->method('getEvent')->willReturn($eventMock); $eventMock->expects($this->once())->method('getQuote')->willReturn($this->quoteMock); $eventMock->expects($this->once())->method('getOrder')->willReturn($this->orderMock); $this->quoteMock->expects($this->once())->method('getPayment')->willReturn($this->paymentMock); $this->model = new \Magento\Quote\Model\Observer\Webapi\Submit($this->loggerMock, $this->orderSenderMock); }
public function testBeforeSave() { $regionId = '23'; $countryId = '67'; $this->object->expects($this->once())->method('getData')->with('region')->willReturn($regionId); $this->object->expects($this->once())->method('getCountryId')->willReturn($countryId); $this->regionFactory->expects($this->once())->method('create')->willReturn($this->region); $this->region->expects($this->once())->method('load')->with($regionId)->willReturnSelf(); $this->region->expects($this->atLeastOnce())->method('getId')->willReturn($regionId); $this->region->expects($this->once())->method('getCountryId')->willReturn($countryId); $this->object->expects($this->once())->method('setRegionId')->with($regionId)->willReturnSelf(); $this->region->expects($this->once())->method('getName')->willReturn('Region name'); $this->object->expects($this->once())->method('setRegion')->with('Region name'); $this->model->beforeSave($this->object); }
/** * 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->observer->addFieldsToResponse($observerMock); }
public function testAroundMap() { $attrSetId = 333; $expected = ['is_configurable' => 1]; /** @var \PHPUnit_Framework_MockObject_MockObject $attributeMapper */ $attributeMapper = $this->getMockBuilder('Magento\\Catalog\\Model\\Entity\\Product\\Attribute\\Group\\AttributeMapperInterface')->disableOriginalConstructor()->getMock(); /** @var \Magento\Eav\Model\Entity\Attribute|\PHPUnit_Framework_MockObject_MockObject $attribute */ $attribute = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute')->disableOriginalConstructor()->getMock(); $proceed = function (Attribute $attribute) { return []; }; $this->attributeFactory->expects($this->once())->method('create')->will($this->returnValue($this->attribute)); $this->attribute->expects($this->once())->method('getUsedAttributes')->with($this->equalTo($attrSetId))->will($this->returnValue([$attrSetId])); $attribute->expects($this->once())->method('getAttributeId')->will($this->returnValue($attrSetId)); $this->registry->expects($this->once())->method('registry')->with($this->equalTo('current_attribute_set'))->will($this->returnValue($this->magentoObject)); $this->magentoObject->expects($this->once())->method('getId')->will($this->returnValue($attrSetId)); $result = $this->model->aroundMap($attributeMapper, $proceed, $attribute); $this->assertEquals($expected, $result); }
/** * Test method * with resultCode = RESPONSE_CODE_APPROVED and Origresult != RESPONSE_CODE_FRAUDSERVICE_FILTER */ public function testAuthorize() { $this->initializationAuthorizeMock(); $this->buildRequestData(); $this->responseMock->expects($this->any())->method('getResultCode')->willReturn(Payflowpro::RESPONSE_CODE_APPROVED); $this->responseMock->expects($this->any())->method('getOrigresult')->willReturn(0); $this->gatewayMock->expects($this->once())->method('postRequest')->willReturn($this->responseMock); $this->responseValidator->expects($this->once())->method('validate')->with($this->responseMock); $this->responseMock->expects($this->once())->method('getPnref')->willReturn('test-pnref'); $this->paymentMock->expects($this->once())->method('setTransactionId')->with('test-pnref')->willReturnSelf(); $this->paymentMock->expects($this->once())->method('setIsTransactionClosed')->with(0); $this->assertSame($this->object, $this->object->authorize($this->paymentMock, 33)); }
/** * @param string $expected * @param bool $dataObjectIsOrder * @param bool $isCurrencyDifferent * @param bool $magentoDataObjectHasOrder * @param bool $strong * @param string $separator * @dataProvider displayPricesDataProvider */ public function testDisplayPriceAttribute($expected, $dataObjectIsOrder, $isCurrencyDifferent = true, $magentoDataObjectHasOrder = true, $strong = false, $separator = '<br/>') { $this->orderMock->expects($this->any())->method('isCurrencyDifferent')->will($this->returnValue($isCurrencyDifferent)); $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock)); $this->priceCurrency->expects($this->any())->method('format')->will($this->returnValue('storeFormattedPrice')); $dataObject = $this->orderMock; if (!$dataObjectIsOrder) { $returnRes = false; if ($magentoDataObjectHasOrder) { $returnRes = $this->orderMock; } $this->magentoObjectMock->expects($this->once())->method('getOrder')->will($this->returnValue($returnRes)); $this->magentoObjectMock->expects($this->any())->method('getData')->will($this->returnValue('data')); $dataObject = $this->magentoObjectMock; } $this->assertEquals($expected, $this->adminHelper->displayPriceAttribute($dataObject, 'code', $strong, $separator)); }
/** * @param \PHPUnit_Framework_MockObject_MockObject|DefaultType $group * @param \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option $option * @param \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Object $buyRequest * @param \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product */ protected function parentClass($group, $option, $buyRequest, $product) { $group->expects($this->once())->method('setOption')->willReturnSelf(); $group->expects($this->once())->method('setProduct')->willReturnSelf(); $group->expects($this->once())->method('setRequest')->willReturnSelf(); $group->expects($this->once())->method('setProcessMode')->willReturnSelf(); $group->expects($this->once())->method('validateUserValue')->willReturnSelf(); $group->expects($this->once())->method('prepareForCart')->willReturn('someString'); $option->expects($this->once())->method('getType'); $option->expects($this->once())->method('groupFactory')->willReturn($group); $option->expects($this->at(0))->method('getId')->willReturn(333); $buyRequest->expects($this->once())->method('getData'); $buyRequest->expects($this->once())->method('getOptions'); $buyRequest->expects($this->once())->method('getSuperProductConfig')->willReturn([]); $buyRequest->expects($this->any())->method('unsetData')->willReturnSelf(); $buyRequest->expects($this->any())->method('getQty'); $product->expects($this->once())->method('getOptions')->willReturn([$option]); $product->expects($this->once())->method('prepareCustomOptions'); $product->expects($this->any())->method('addCustomOption')->willReturnSelf(); $product->expects($this->any())->method('setCartQty')->willReturnSelf(); $product->expects($this->once())->method('setQty'); $this->catalogProduct->expects($this->once())->method('getSkipSaleableCheck')->willReturn(false); }
protected function setUp() { $this->object = $this->getMock('Magento\\Framework\\Object'); $this->object->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->objectRegistry = (new ObjectManager($this))->getObject('Magento\\CatalogUrlRewrite\\Model\\ObjectRegistry', ['entities' => [$this->object]]); }
/** * Test protected `getTranslatedString` method via public `getElementHtml` method */ public function testGetTranslatedString() { $this->configMock->expects($this->any())->method('getData')->withConsecutive(['enabled'])->willReturn(true); $html = $this->model->getElementHtml(); $this->assertRegExp('/.*"Insert Image...":"Insert Image...".*/i', $html); }