/** * @dataProvider queryTextDataProvider */ public function testGetEscapedQueryText($queryText, $maxQueryLength, $expected) { $this->requestMock->expects($this->once())->method('getParam')->willReturn($queryText); $this->stringMock->expects($this->any())->method('cleanString')->willReturnArgument(0); $this->scopeConfigMock->expects($this->any())->method('getValue')->willReturn($maxQueryLength); $this->stringMock->expects($this->any())->method('strlen')->will($this->returnCallback(function ($queryText) { return strlen($queryText); })); $this->stringMock->expects($this->any())->method('substr')->with($queryText, 0, $maxQueryLength)->willReturn($expected); $this->escaperMock->expects($this->any())->method('escapeHtml')->willReturnArgument(0); $this->assertEquals($expected, $this->model->getEscapedQueryText()); }
public function testGetTooLongQuery() { $queryId = 123; $this->mapScopeConfig([self::XML_PATH_MAX_QUERY_LENGTH => 12]); $rawQueryText = 'This is very long search query text'; $preparedQueryText = 'This is very'; $this->stringMock->expects($this->once())->method('substr')->with($this->equalTo($rawQueryText))->will($this->returnValue($preparedQueryText)); $this->requestMock->expects($this->once())->method('getParam')->with($this->equalTo(self::QUERY_VAR_NAME))->will($this->returnValue($rawQueryText)); $this->objectManagerMock->expects($this->once())->method('create')->with($this->equalTo('Magento\\Search\\Model\\Query'))->will($this->returnValue($this->queryMock)); $this->queryMock->expects($this->once())->method('loadByQuery')->with($this->equalTo($preparedQueryText))->will($this->returnSelf()); $this->queryMock->expects($this->once())->method('getId')->will($this->returnValue($queryId)); $this->queryMock->expects($this->once())->method('setIsQueryTextExceeded')->with($this->equalTo(true))->will($this->returnSelf()); $query = $this->queryFactory->get(); $this->assertSame($this->queryMock, $query); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testCreateAccountWithPassword() { $websiteId = 1; $storeId = null; $defaultStoreId = 1; $customerId = 1; $customerEmail = '*****@*****.**'; $password = '******'; $hash = '4nj54lkj5jfi03j49f8bgujfgsd'; $newLinkToken = '2jh43j5h2345jh23lh452h345hfuzasd96ofu'; $templateIdentifier = 'Template Identifier'; $sender = 'Sender'; $this->string->expects($this->any())->method('strlen')->willReturnCallback(function ($string) { return strlen($string); }); $this->encryptor->expects($this->once())->method('getHash')->with($password, true)->willReturn($hash); $address = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->disableOriginalConstructor()->getMock(); $address->expects($this->once())->method('setCustomerId')->with($customerId); $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $store->expects($this->once())->method('getId')->willReturn($defaultStoreId); $website = $this->getMockBuilder('Magento\\Store\\Model\\Website')->disableOriginalConstructor()->getMock(); $website->expects($this->atLeastOnce())->method('getStoreIds')->willReturn([1, 2, 3]); $website->expects($this->once())->method('getDefaultStore')->willReturn($store); $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock(); $customer->expects($this->atLeastOnce())->method('getId')->willReturn($customerId); $customer->expects($this->atLeastOnce())->method('getEmail')->willReturn($customerEmail); $customer->expects($this->atLeastOnce())->method('getWebsiteId')->willReturn($websiteId); $customer->expects($this->atLeastOnce())->method('getStoreId')->willReturn($storeId); $customer->expects($this->once())->method('setStoreId')->with($defaultStoreId); $customer->expects($this->once())->method('getAddresses')->willReturn([$address]); $customer->expects($this->once())->method('setAddresses')->with(null); $this->customerRepository->expects($this->once())->method('get')->with($customerEmail)->willReturn($customer); $this->share->expects($this->once())->method('isWebsiteScope')->willReturn(true); $this->storeManager->expects($this->atLeastOnce())->method('getWebsite')->with($websiteId)->willReturn($website); $this->customerRepository->expects($this->atLeastOnce())->method('save')->willReturn($customer); $this->addressRepository->expects($this->atLeastOnce())->method('save')->with($address); $this->customerRepository->expects($this->once())->method('getById')->with($customerId)->willReturn($customer); $this->random->expects($this->once())->method('getUniqueHash')->willReturn($newLinkToken); $customerSecure = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\CustomerSecure')->setMethods(['setRpToken', 'setRpTokenCreatedAt', 'getPasswordHash'])->disableOriginalConstructor()->getMock(); $customerSecure->expects($this->any())->method('setRpToken')->with($newLinkToken); $customerSecure->expects($this->any())->method('setRpTokenCreatedAt'); $customerSecure->expects($this->any())->method('getPasswordHash')->willReturn($hash); $this->customerRegistry->expects($this->atLeastOnce())->method('retrieveSecureData')->willReturn($customerSecure); $this->dataObjectProcessor->expects($this->once())->method('buildOutputDataArray')->willReturn([]); $this->scopeConfig->expects($this->at(1))->method('getValue')->with(AccountManagement::XML_PATH_REGISTER_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE, $defaultStoreId)->willReturn($templateIdentifier); $this->scopeConfig->expects($this->at(2))->method('getValue')->willReturn($sender); $transport = $this->getMockBuilder('Magento\\Framework\\Mail\\TransportInterface')->getMock(); $this->transportBuilder->expects($this->once())->method('setTemplateIdentifier')->with($templateIdentifier)->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('setTemplateOptions')->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('setTemplateVars')->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('setFrom')->with($sender)->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('addTo')->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('getTransport')->willReturn($transport); $transport->expects($this->once())->method('sendMessage'); $this->accountManagement->createAccount($customer, $password); }
public function testRenderMetadata() { $metadata = ['charset' => 'charsetValue', 'metadataName' => 'metadataValue', 'content_type' => 'content_type_value', 'x_ua_compatible' => 'x_ua_compatible_value', 'media_type' => 'media_type_value']; $metadataValueCharset = 'newCharsetValue'; $expected = '<meta charset="newCharsetValue"/>' . "\n" . '<meta name="metadataName" content="metadataValue"/>' . "\n" . '<meta http-equiv="Content-Type" content="content_type_value"/>' . "\n" . '<meta http-equiv="X-UA-Compatible" content="x_ua_compatible_value"/>' . "\n"; $this->stringMock->expects($this->at(0))->method('upperCaseWords')->with('charset', '_', '')->willReturn('Charset'); $this->pageConfigMock->expects($this->once())->method('getCharset')->willReturn($metadataValueCharset); $this->pageConfigMock->expects($this->once())->method('getMetadata')->will($this->returnValue($metadata)); $this->assertEquals($expected, $this->renderer->renderMetadata()); }
/** * @return void */ public function testChangePassword() { $customerId = 7; $email = '*****@*****.**'; $currentPassword = '******'; $newPassword = '******'; $passwordHash = '1a2b3f4c'; $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock(); $customer->expects($this->any())->method('getId')->willReturn($customerId); $this->customerRepository->expects($this->once())->method('get')->with($email)->willReturn($customer); $this->authenticationMock->expects($this->once())->method('authenticate'); $customerSecure = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\CustomerSecure')->setMethods(['setRpToken', 'setRpTokenCreatedAt', 'getPasswordHash'])->disableOriginalConstructor()->getMock(); $customerSecure->expects($this->once())->method('setRpToken')->with(null); $customerSecure->expects($this->once())->method('setRpTokenCreatedAt')->with(null); $customerSecure->expects($this->any())->method('getPasswordHash')->willReturn($passwordHash); $this->customerRegistry->expects($this->any())->method('retrieveSecureData')->with($customerId)->willReturn($customerSecure); $this->scopeConfig->expects($this->any())->method('getValue')->willReturnMap([[AccountManagement::XML_PATH_MINIMUM_PASSWORD_LENGTH, 'default', null, 7], [AccountManagement::XML_PATH_REQUIRED_CHARACTER_CLASSES_NUMBER, 'default', null, 1]]); $this->string->expects($this->any())->method('strlen')->with($newPassword)->willReturn(7); $this->customerRepository->expects($this->once())->method('save')->with($customer); $this->assertTrue($this->accountManagement->changePassword($email, $currentPassword, $newPassword)); }
/** * @param string $cleanedRawText * @return void */ private function mockString($cleanedRawText) { $this->string->expects($this->any())->method('cleanString')->withConsecutive([$cleanedRawText])->willReturnArgument(0); $this->string->expects($this->any())->method('strlen')->withConsecutive([$cleanedRawText])->willReturn(strlen($cleanedRawText)); }
/** * @param boolean $clean * @return $this */ protected function _prepareCleanString($clean) { $cleanStringExpects = $clean ? $this->once() : $this->never(); $this->_converter->expects($cleanStringExpects)->method('cleanString')->will($this->returnValue('converted value')); return $this; }