/** * @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()); }
/** * @return void */ public function testExecute() { $customerId = 1; $observerMock = $this->getMock('Magento\\Framework\\Event\\Observer', [], [], '', false); $eventMock = $this->getMock('Magento\\Framework\\Event', ['getData'], [], '', false); $observerMock->expects($this->once())->method('getEvent')->willReturn($eventMock); $eventMock->expects($this->once())->method('getData')->with('model')->willReturn($this->customerModelMock); $this->customerModelMock->expects($this->once())->method('getId')->willReturn($customerId); $this->authenticationMock->expects($this->once())->method('unlock')->with($customerId); $this->customerLoginSuccessObserver->execute($observerMock); }
/** * @return void */ public function testExecute() { $customerId = 1; $observerMock = $this->getMock('Magento\\Framework\\Event\\Observer', [], [], '', false); $eventMock = $this->getMock('Magento\\Framework\\Event', ['getData'], [], '', false); $observerMock->expects($this->once())->method('getEvent')->willReturn($eventMock); $eventMock->expects($this->once())->method('getData')->with('model')->willReturn($this->customerModelMock); $this->customerModelMock->expects($this->once())->method('getId')->willReturn($customerId); $this->customerRepositoryMock->expects($this->once())->method('getById')->willReturn($this->customerDataMock); $this->customerDataMock->expects($this->once())->method('getId')->willReturn($customerId); $this->accountManagementHelperMock->expects($this->once())->method('processUnlockData')->with($customerId); $this->customerRepositoryMock->expects($this->once())->method('save')->with($this->customerDataMock); $this->customerLoginSuccessObserver->execute($observerMock); }
/** * @param string $expectedResult * @param bool $value * @dataProvider getAccountLockDataProvider * @return void */ public function testGetAccountLock($expectedResult, $value) { $this->customerRegistry->expects($this->once())->method('retrieve')->willReturn($this->customerModel); $this->customerModel->expects($this->once())->method('isCustomerLocked')->willReturn($value); $expectedResult = new \Magento\Framework\Phrase($expectedResult); $this->assertEquals($expectedResult, $this->block->getAccountLock()); }
/** * return bool */ public function testValidateResetPasswordToken() { $this->reInitModel(); $this->customer->expects($this->once())->method('getResetPasswordLinkExpirationPeriod')->willReturn(100000); $this->customerRegistry->expects($this->atLeastOnce())->method('retrieveSecureData')->willReturn($this->customerSecure); $this->assertTrue($this->accountManagement->validateResetPasswordLinkToken(22, 'newStringToken')); }
public function testDeleteById() { $addressId = 12; $customerId = 43; $this->address->expects($this->once())->method('getCustomerId')->willReturn($customerId); $addressCollection = $this->getMock('Magento\\Customer\\Model\\ResourceModel\\Address\\Collection', [], [], '', false); $this->addressRegistry->expects($this->once())->method('retrieve')->with($addressId)->willReturn($this->address); $this->customerRegistry->expects($this->once())->method('retrieve')->with($customerId)->willReturn($this->customer); $this->customer->expects($this->once())->method('getAddressesCollection')->willReturn($addressCollection); $addressCollection->expects($this->once())->method('clear'); $this->addressResourceModel->expects($this->once())->method('delete')->with($this->address); $this->addressRegistry->expects($this->once())->method('remove')->with($addressId); $this->assertTrue($this->repository->deleteById($addressId)); }
public function testRemoveByEmail() { $this->customer->expects($this->exactly(2))->method('loadByEmail')->with(self::CUSTOMER_EMAIL)->will($this->returnValue($this->customer)); $this->customer->expects($this->any())->method('getId')->will($this->returnValue(self::CUSTOMER_ID)); $this->customer->expects($this->any())->method('getEmail')->will($this->returnValue(self::CUSTOMER_EMAIL)); $this->customer->expects($this->any())->method('getWebsiteId')->will($this->returnValue(self::WEBSITE_ID)); $this->customer->expects($this->any())->method('setEmail')->will($this->returnValue($this->customer)); $this->customer->expects($this->any())->method('setWebsiteId')->will($this->returnValue($this->customer)); $this->customerFactory->expects($this->exactly(2))->method('create')->will($this->returnValue($this->customer)); $actual = $this->customerRegistry->retrieveByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID); $this->assertEquals($this->customer, $actual); $this->customerRegistry->removeByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID); $actual = $this->customerRegistry->retrieveByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID); $this->assertEquals($this->customer, $actual); }
public function testAfterGenerateXmlNoDepersonalize() { $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false); $this->depersonalizeCheckerMock->expects($this->once())->method('checkIfDepersonalize')->willReturn(false); $this->visitorMock->expects($this->never())->method('setSkipRequestLogging'); $this->visitorMock->expects($this->never())->method('unsetData'); $this->sessionMock->expects($this->never())->method('clearStorage'); $this->customerSessionMock->expects($this->never())->method('clearStorage'); $this->customerSessionMock->expects($this->never())->method('setCustomerGroupId'); $this->customerMock->expects($this->never())->method('setGroupId'); $this->sessionMock->expects($this->never())->method('setData'); $this->customerSessionMock->expects($this->never())->method('setCustomer'); $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult); $this->assertSame($expectedResult, $actualResult); }
/** * Test method afterGenerateXml with enabled module PageCache */ public function testAfterGenerateXmlPageCacheEnabled() { $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', array(), array(), '', false); $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with('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(true)); $this->visitorMock->expects($this->once())->method('setSkipRequestLogging')->with($this->equalTo(true)); $this->visitorMock->expects($this->once())->method('unsetData'); $this->sessionMock->expects($this->once())->method('clearStorage'); $this->customerSessionMock->expects($this->once())->method('clearStorage'); $this->customerSessionMock->expects($this->once())->method('setCustomerGroupId')->with($this->equalTo(null)); $this->customerMock->expects($this->once())->method('setGroupId')->with($this->equalTo(null)); $this->sessionMock->expects($this->once())->method('setData')->with($this->equalTo(\Magento\Framework\Data\Form\FormKey::FORM_KEY), $this->equalTo(null)); $this->customerSessionMock->expects($this->once())->method('setCustomer')->with($this->equalTo($this->customerMock)); $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult); $this->assertSame($expectedResult, $actualResult); }
/** * @param string $params * @dataProvider dataProcessNonce */ public function testProcessNonceException($params = null, $exceptionMessage = null) { $this->customerSessionMock->expects($this->any())->method('getCustomerId')->willReturn($params['customerId']); $countryCollectionMock = $this->getMockBuilder('\\Magento\\Directory\\Model\\Resource\\Country\\Collection')->disableOriginalConstructor()->getMock(); $countryCollectionMock->expects($this->any())->method('addCountryCodeFilter')->willReturn($countryCollectionMock); $this->countryFactoryMock->expects($this->any())->method('create')->willReturn($countryCollectionMock); $this->configMock->expects($this->any())->method('canUseForCountry')->willReturn($params['canUseForCountry']); $this->configMock->expects($this->any())->method('canUseCcTypeForCountry')->willReturn($params['canUseCcTypeForCountry']); $this->helperMock->expects($this->any())->method('generateCustomerId')->willReturn($params['customerId']); $this->customerMock->expects($this->any())->method('load')->willReturn($this->customerMock); $this->customerFactoryMock->expects($this->any())->method('create')->willReturn($this->customerMock); if (is_object($params['paymentMethodObj'])) { if (!$params['optionsArray']['update']) { $this->braintreePaymentMethodMock->expects($this->once())->method('create')->willReturn($params['paymentMethodObj']); } else { $this->braintreePaymentMethodMock->expects($this->once())->method('update')->willReturn($params['paymentMethodObj']); } if (!$params['paymentMethodObj']->success) { $this->errorHelperMock->expects($this->once())->method('parseBraintreeError')->willReturn(new \Magento\Framework\Phrase($exceptionMessage)); } else { $this->errorHelperMock->expects($this->never())->method('parseBraintreeError'); } } try { $this->model->processNonce($params['nonce'], $params['optionsArray'], $params['billingAddress']); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->assertEquals($exceptionMessage, $e->getMessage()); } }