/** * @param string|null $configAddressType * @dataProvider restoreCustomerGroupIdDataProvider */ public function testExecute($configAddressType) { $quoteAddress = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', ['getQuote', 'setCustomerGroupId', 'getPrevQuoteCustomerGroupId', 'unsPrevQuoteCustomerGroupId', 'hasPrevQuoteCustomerGroupId'], [], '', false); $observer = $this->getMock('Magento\\Framework\\Event\\Observer', ['getQuoteAddress'], [], '', false); $observer->expects($this->once())->method('getQuoteAddress')->will($this->returnValue($quoteAddress)); $this->customerAddressHelperMock->expects($this->once())->method('getTaxCalculationAddressType')->will($this->returnValue($configAddressType)); $quoteAddress->expects($this->once())->method('hasPrevQuoteCustomerGroupId'); $id = $quoteAddress->expects($this->any())->method('getPrevQuoteCustomerGroupId'); $quoteAddress->expects($this->any())->method('setCustomerGroupId')->with($id); $quoteAddress->expects($this->any())->method('getQuote'); $quoteAddress->expects($this->any())->method('unsPrevQuoteCustomerGroupId'); $this->assertNull($this->quote->execute($observer)); }
/** * @param string $configAddressType * @param string|int $vatRequestId * @param string|int $vatRequestDate * @param string $orderHistoryComment * @dataProvider addVatRequestParamsOrderCommentDataProvider */ public function testAddVatRequestParamsOrderComment($configAddressType, $vatRequestId, $vatRequestDate, $orderHistoryComment) { $this->customerAddressHelperMock->expects($this->once())->method('getTaxCalculationAddressType')->will($this->returnValue($configAddressType)); $orderAddressMock = $this->getMock('Magento\\Sales\\Model\\Order\\Address', ['getVatRequestId', 'getVatRequestDate', '__wakeup'], [], '', false); $orderAddressMock->expects($this->any())->method('getVatRequestId')->will($this->returnValue($vatRequestId)); $orderAddressMock->expects($this->any())->method('getVatRequestDate')->will($this->returnValue($vatRequestDate)); $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->setMethods(['getShippingAddress', '__wakeup', 'addStatusHistoryComment', 'getBillingAddress'])->getMock(); $orderMock->expects($this->any())->method('getShippingAddress')->will($this->returnValue($orderAddressMock)); if ($orderHistoryComment === null) { $orderMock->expects($this->never())->method('addStatusHistoryComment'); } else { $orderMock->expects($this->once())->method('addStatusHistoryComment')->with($orderHistoryComment, false); } $observer = $this->getMock('Magento\\Framework\\Event\\Observer', ['getOrder'], [], '', false); $observer->expects($this->once())->method('getOrder')->will($this->returnValue($orderMock)); $this->assertNull($this->observer->execute($observer)); }
/** * @param string|null $configAddressType * @dataProvider restoreCustomerGroupIdDataProvider */ public function testExecute($configAddressType) { $eventMock = $this->getMock('\\Magento\\Framework\\Event', ['getShippingAssignment', 'getQuote'], [], '', false); $observer = $this->getMock('Magento\\Framework\\Event\\Observer', ['getEvent'], [], '', false); $observer->expects($this->exactly(2))->method('getEvent')->willReturn($eventMock); $shippingAssignmentMock = $this->getMock('\\Magento\\Quote\\Api\\Data\\ShippingAssignmentInterface'); $quoteMock = $this->getMock('\\Magento\\Quote\\Model\\Quote', [], [], '', false); $eventMock->expects($this->once())->method('getShippingAssignment')->willReturn($shippingAssignmentMock); $eventMock->expects($this->once())->method('getQuote')->willReturn($quoteMock); $shippingMock = $this->getMock('\\Magento\\Quote\\Api\\Data\\ShippingInterface'); $shippingAssignmentMock->expects($this->once())->method('getShipping')->willReturn($shippingMock); $quoteAddress = $this->getMock('\\Magento\\Quote\\Model\\Quote\\Address', ['getPrevQuoteCustomerGroupId', 'unsPrevQuoteCustomerGroupId', 'hasPrevQuoteCustomerGroupId'], [], '', false); $shippingMock->expects($this->once())->method('getAddress')->willReturn($quoteAddress); $this->customerAddressHelperMock->expects($this->once())->method('getTaxCalculationAddressType')->will($this->returnValue($configAddressType)); $quoteAddress->expects($this->once())->method('hasPrevQuoteCustomerGroupId'); $id = $quoteAddress->expects($this->any())->method('getPrevQuoteCustomerGroupId'); $quoteAddress->expects($this->any())->method('setCustomerGroupId')->with($id); $quoteAddress->expects($this->any())->method('getQuote'); $quoteAddress->expects($this->any())->method('unsPrevQuoteCustomerGroupId'); $this->quote->execute($observer); }
/** * @param $customerId * @param $key * @param $vatValidationEnabled * @param $addressType * @param $successMessage * * @dataProvider getSuccessMessageDataProvider */ public function testSuccessMessage($customerId, $key, $vatValidationEnabled, $addressType, $successMessage) { $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false)); $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['id', false, $customerId], ['key', false, $key]]); $this->customerRepositoryMock->expects($this->any())->method('getById')->with($customerId)->will($this->returnValue($this->customerDataMock)); $email = '*****@*****.**'; $this->customerDataMock->expects($this->once())->method('getEmail')->will($this->returnValue($email)); $this->customerAccountManagementMock->expects($this->once())->method('activate')->with($this->equalTo($email), $this->equalTo($key))->will($this->returnValue($this->customerDataMock)); $this->customerSessionMock->expects($this->any())->method('setCustomerDataAsLoggedIn')->with($this->equalTo($this->customerDataMock))->willReturnSelf(); $this->messageManagerMock->expects($this->any())->method('addSuccess')->with($this->stringContains($successMessage))->willReturnSelf(); $this->addressHelperMock->expects($this->once())->method('isVatValidationEnabled')->will($this->returnValue($vatValidationEnabled)); $this->addressHelperMock->expects($this->any())->method('getTaxCalculationAddressType')->will($this->returnValue($addressType)); $this->storeMock->expects($this->any())->method('getFrontendName')->will($this->returnValue('frontend')); $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($this->storeMock)); $this->model->execute(); }
/** * @param $customerId * @param $customerEmail * @param $password * @param $confirmationStatus * @param $vatValidationEnabled * @param $addressType * @param $successMessage * * @dataProvider getSuccessMessageDataProvider */ public function testSuccessMessage($customerId, $customerEmail, $password, $confirmationStatus, $vatValidationEnabled, $addressType, $successMessage) { $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false)); $this->registration->expects($this->once())->method('isAllowed')->will($this->returnValue(true)); $this->customerUrl->expects($this->once())->method('getEmailConfirmationUrl')->will($this->returnValue($customerEmail)); $this->customerSessionMock->expects($this->once())->method('regenerateId'); $this->customerMock->expects($this->any())->method('getId')->will($this->returnValue($customerId)); $this->customerMock->expects($this->any())->method('getEmail')->will($this->returnValue($customerEmail)); $this->customerExtractorMock->expects($this->any())->method('extract')->with($this->equalTo('customer_account_create'), $this->equalTo($this->requestMock))->will($this->returnValue($this->customerMock)); $this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue(true)); $this->requestMock->expects($this->any())->method('getPost')->will($this->returnValue(false)); $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['password', null, $password], ['password_confirmation', null, $password], ['is_subscribed', false, true]]); $this->customerMock->expects($this->once())->method('setAddresses')->with($this->equalTo([]))->will($this->returnSelf()); $this->accountManagement->expects($this->once())->method('createAccount')->with($this->equalTo($this->customerDetailsMock), $this->equalTo($password), '')->will($this->returnValue($this->customerMock)); $this->accountManagement->expects($this->once())->method('getConfirmationStatus')->with($this->equalTo($customerId))->will($this->returnValue($confirmationStatus)); $this->subscriberMock->expects($this->once())->method('subscribeCustomerById')->with($this->equalTo($customerId)); $this->messageManagerMock->expects($this->any())->method('addSuccess')->with($this->stringContains($successMessage))->will($this->returnSelf()); $this->addressHelperMock->expects($this->any())->method('isVatValidationEnabled')->will($this->returnValue($vatValidationEnabled)); $this->addressHelperMock->expects($this->any())->method('getTaxCalculationAddressType')->will($this->returnValue($addressType)); $this->model->execute(); }