예제 #1
0
 /**
  * @dataProvider getUrlDataProvider
  * @covers \Magento\Catalog\Model\Product\Url::getUrl
  * @covers \Magento\Catalog\Model\Product\Url::getUrlInStore
  * @covers \Magento\Catalog\Model\Product\Url::getProductUrl
  *
  * @param $getUrlMethod
  * @param $routePath
  * @param $requestPathProduct
  * @param $storeId
  * @param $categoryId
  * @param $routeParams
  * @param $routeParamsUrl
  * @param $productId
  * @param $productUrlKey
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function testGetUrl($getUrlMethod, $routePath, $requestPathProduct, $storeId, $categoryId, $routeParams, $routeParamsUrl, $productId, $productUrlKey)
 {
     $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['getStoreId', 'getEntityId', 'getId', 'getUrlKey', 'setRequestPath', 'hasUrlDataObject', 'getRequestPath', 'getCategoryId', 'getDoNotUseCategoryId', '__wakeup'])->getMock();
     $product->expects($this->any())->method('getStoreId')->will($this->returnValue($storeId));
     $product->expects($this->any())->method('getCategoryId')->will($this->returnValue($categoryId));
     $product->expects($this->any())->method('getRequestPath')->will($this->returnValue($requestPathProduct));
     $product->expects($this->any())->method('setRequestPath')->with(false)->will($this->returnSelf());
     $product->expects($this->any())->method('getId')->will($this->returnValue($productId));
     $product->expects($this->any())->method('getUrlKey')->will($this->returnValue($productUrlKey));
     $this->url->expects($this->any())->method('setScope')->with($storeId)->will($this->returnSelf());
     $this->url->expects($this->any())->method('getUrl')->with($routePath, $routeParamsUrl)->will($this->returnValue($requestPathProduct));
     $this->urlFinder->expects($this->any())->method('findOneByData')->will($this->returnValue(false));
     switch ($getUrlMethod) {
         case 'getUrl':
             $this->assertEquals($requestPathProduct, $this->model->getUrl($product, $routeParams));
             break;
         case 'getUrlInStore':
             $this->assertEquals($requestPathProduct, $this->model->getUrlInStore($product, $routeParams));
             break;
         case 'getProductUrl':
             $this->assertEquals($requestPathProduct, $this->model->getProductUrl($product, true));
             $this->sidResolver->expects($this->once())->method('getUseSessionInUrl')->will($this->returnValue(true));
             $this->assertEquals($requestPathProduct, $this->model->getProductUrl($product, null));
             break;
     }
 }
 protected function prepareAttemptToMinifyMock($fileExists, $rootDirExpectations = true, $originalExists = true)
 {
     $this->asset->expects($this->atLeastOnce())->method('getPath')->will($this->returnValue('test/admin.js'));
     $this->asset->expects($this->atLeastOnce())->method('getSourceFile')->will($this->returnValue('/foo/bar/test/admin.js'));
     if ($rootDirExpectations) {
         $this->rootDir->expects($this->once())->method('getRelativePath')->with('/foo/bar/test/admin.min.js')->will($this->returnValue('test/admin.min.js'));
         $this->rootDir->expects($this->once())->method('isExist')->with('test/admin.min.js')->will($this->returnValue(false));
     }
     $this->baseUrl->expects($this->once())->method('getBaseUrl')->will($this->returnValue('http://example.com/'));
     $this->staticViewDir->expects($this->exactly(2 - intval($originalExists)))->method('isExist')->will($this->returnValue($fileExists));
 }
예제 #3
0
 /**
  * @covers \Magento\Config\Block\System\Config\Form\Field\Image::_getUrl
  */
 public function testGetElementHtmlWithValue()
 {
     $type = 'media';
     $url = 'http://test.example.com/media/';
     $this->urlBuilderMock->expects($this->once())->method('getBaseUrl')->with(['_type' => $type])->will($this->returnValue($url));
     $this->_image->setValue('test_value');
     $this->_image->setFieldConfig(['id' => 'placeholder', 'type' => 'image', 'sortOrder' => '1', 'showInDefault' => '1', 'showInWebsite' => '1', 'showInStore' => '1', 'label' => null, 'backend_model' => 'Magento\\Backend\\Model\\Config\\Backend\\Image', 'upload_dir' => ['config' => 'system/filesystem/media', 'scope_info' => '1', 'value' => 'catalog/product/placeholder'], 'base_url' => ['type' => $type, 'scope_info' => '1', 'value' => 'catalog/product/placeholder'], '_elementType' => 'field', 'path' => 'catalog/placeholder']);
     $html = $this->_image->getElementHtml();
     $this->assertContains('class="input-file"', $html);
     $this->assertContains('<input', $html);
     $this->assertContains('type="file"', $html);
     $this->assertContains('value="test_value"', $html);
     $this->assertContains('<a href="' . $url . 'catalog/product/placeholder/test_value" onclick="imagePreview(\'_image\'); return false;"', $html);
     $this->assertContains('<input type="checkbox"', $html);
 }
예제 #4
0
 private function prepareAttemptToMinifyMock($fileExists, $rootDirExpectations = true)
 {
     $this->_asset->expects($this->atLeastOnce())->method('getPath')->will($this->returnValue('test/library.js'));
     $this->_asset->expects($this->atLeastOnce())->method('getSourceFile')->will($this->returnValue('/foo/bar/test/library.js'));
     if ($rootDirExpectations) {
         $this->_rootDir->expects($this->once())->method('getRelativePath')->with('/foo/bar/test/library.min.js')->will($this->returnValue('test/library.min.js'));
         $this->_rootDir->expects($this->once())->method('isExist')->with('test/library.min.js')->will($this->returnValue(false));
     }
     $this->_baseUrl->expects($this->once())->method('getBaseUrl')->will($this->returnValue('http://example.com/'));
     $this->_staticViewDir->expects($this->once())->method('isExist')->will($this->returnValue($fileExists));
 }
예제 #5
0
 /**
  * @param $customerId
  * @param $key
  * @param $backUrl
  * @param $successUrl
  * @param $resultUrl
  * @param $isSetFlag
  * @param $successMessage
  *
  * @dataProvider getSuccessRedirectDataProvider
  */
 public function testSuccessRedirect($customerId, $key, $backUrl, $successUrl, $resultUrl, $isSetFlag, $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], ['back_url', false, $backUrl]]);
     $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->storeMock->expects($this->any())->method('getFrontendName')->will($this->returnValue('frontend'));
     $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($this->storeMock));
     $this->urlMock->expects($this->any())->method('getUrl')->with($this->equalTo('*/*/index'), ['_secure' => true])->will($this->returnValue($successUrl));
     $this->redirectMock->expects($this->never())->method('success')->with($this->equalTo($resultUrl))->willReturn($resultUrl);
     $this->scopeConfigMock->expects($this->never())->method('isSetFlag')->with(Url::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD, ScopeInterface::SCOPE_STORE)->willReturn($isSetFlag);
     $this->model->execute();
 }
 /**
  * @dataProvider getConfigDataProvider
  */
 public function testGetConfig($configData, $vaultData, $tokenNonceMap, $expectedResult)
 {
     foreach ($configData as $key => $value) {
         $this->configMock->expects($this->any())->method($key)->willReturn($value);
     }
     foreach ($vaultData as $key => $value) {
         $this->vaultMock->expects($this->any())->method($key)->willReturn($value);
     }
     $this->vaultMock->expects($this->any())->method('generatePaymentMethodToken')->willReturnMap($tokenNonceMap);
     $cardTypeMap = [['Visa', 'VI'], ['Master Card', 'MA'], ['American Express', 'AE'], ['Discover Card', 'DI']];
     $this->helperMock->expects($this->any())->method('getCcTypeCodeByName')->willReturnMap($cardTypeMap);
     $this->helperMock->expects($this->once())->method('getTodayMonth')->willReturn(self::TODAY_MONTH);
     $this->helperMock->expects($this->once())->method('getTodayYear')->willReturn(self::TODAY_YEAR);
     $this->helperMock->expects($this->once())->method('getCcAvailableCardTypes')->willReturn($this->availableCardTypes);
     $this->customerSessionMock->expects($this->any())->method('isLoggedIn')->willReturn(true);
     $this->urlBuilderMock->expects($this->once())->method('getUrl')->with('braintree/creditcard/generate')->willReturn(self::PAYMENT_NONCE_GENERATION_URL);
     $this->assertEquals($expectedResult, $this->model->getConfig());
 }
예제 #7
0
 /**
  * @dataProvider getConfigDataProvider
  */
 public function testGetConfig($configData, $vaultData, $tokenNonceMap, $expectedResult)
 {
     foreach ($configData as $key => $value) {
         $this->configMock->expects($this->any())->method($key)->willReturn($value);
     }
     foreach ($vaultData as $key => $value) {
         $this->vaultMock->expects($this->any())->method($key)->willReturn($value);
     }
     $this->vaultMock->expects($this->any())->method('generatePaymentMethodToken')->willReturnMap($tokenNonceMap);
     $quoteMock = $this->getMockBuilder('\\Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->getMock();
     $quoteMock->expects($this->once())->method('getBillingAddress')->willReturn(new \Magento\Framework\Object(['country_id' => 'US']));
     $this->checkoutSessionMock->expects($this->once())->method('getQuote')->willReturn($quoteMock);
     $cardTypeMap = [['Visa', 'VI'], ['Master Card', 'MA'], ['American Express', 'AE'], ['Discover Card', 'DI']];
     $this->helperMock->expects($this->any())->method('getCcTypeCodeByName')->willReturnMap($cardTypeMap);
     $this->helperMock->expects($this->once())->method('getTodayMonth')->willReturn(self::TODAY_MONTH);
     $this->helperMock->expects($this->once())->method('getTodayYear')->willReturn(self::TODAY_YEAR);
     $this->helperMock->expects($this->once())->method('getCcAvailableCardTypes')->willReturn($this->availableCardTypes);
     $this->customerSessionMock->expects($this->any())->method('isLoggedIn')->willReturn(true);
     $this->urlBuilderMock->expects($this->once())->method('getUrl')->with('braintree/creditcard/generate')->willReturn(self::PAYMENT_NONCE_GENERATION_URL);
     $this->assertEquals($expectedResult, $this->model->getConfig());
 }
예제 #8
0
 public function testInitiatePasswordResetEmailReminder()
 {
     $customerId = 1;
     $email = '*****@*****.**';
     $template = AccountManagement::EMAIL_REMINDER;
     $templateIdentifier = 'Template Identifier';
     $sender = 'Sender';
     $storeId = 1;
     $isFrontendSecure = true;
     $resetUrl = 'reset url';
     mt_srand(mt_rand() + 100000000 * microtime() % PHP_INT_MAX);
     $hash = md5(uniqid(microtime() . mt_rand(0, mt_getrandmax()), true));
     $this->store->expects($this->once())->method('isFrontUrlSecure')->willReturn($isFrontendSecure);
     $this->url->expects($this->once())->method('setScope')->with($storeId)->willReturnSelf();
     $this->url->expects($this->once())->method('getUrl')->with('customer/account/createPassword', ['_query' => ['id' => $customerId, 'token' => $hash], '_store' => $storeId, '_secure' => $isFrontendSecure])->willReturn($resetUrl);
     $this->scopeConfig->expects($this->at(0))->method('getValue')->with(AccountManagement::XML_PATH_REMIND_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE, $storeId)->willReturn($templateIdentifier);
     $this->scopeConfig->expects($this->at(1))->method('getValue')->with(AccountManagement::XML_PATH_FORGOT_EMAIL_IDENTITY, ScopeInterface::SCOPE_STORE, $storeId)->willReturn($sender);
     $this->customerSecure->expects($this->any())->method('setResetPasswordUrl')->with($resetUrl)->willReturnSelf();
     $this->prepareInitiatePasswordReset($email, $templateIdentifier, $sender, $storeId, $customerId, $hash);
     $this->assertTrue($this->accountManagement->initiatePasswordReset($email, $template));
 }
 /**
  * @param $customerId
  * @param $password
  * @param $confirmationStatus
  * @param $successUrl
  * @param $isSetFlag
  * @param $successMessage
  *
  * @dataProvider getSuccessRedirectDataProvider
  */
 public function testSuccessRedirect($customerId, $password, $confirmationStatus, $successUrl, $isSetFlag, $successMessage)
 {
     $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false));
     $this->registration->expects($this->once())->method('isAllowed')->will($this->returnValue(true));
     $this->customerSessionMock->expects($this->once())->method('regenerateId');
     $this->customerMock->expects($this->any())->method('getId')->will($this->returnValue($customerId));
     $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->urlMock->expects($this->any())->method('getUrl')->willReturnMap([['*/*/index', ['_secure' => true], $successUrl], ['*/*/create', ['_secure' => true], $successUrl]]);
     $this->redirectMock->expects($this->once())->method('success')->with($this->equalTo($successUrl))->will($this->returnValue($successUrl));
     $this->scopeConfigMock->expects($this->once())->method('isSetFlag')->with($this->equalTo(Url::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD), $this->equalTo(ScopeInterface::SCOPE_STORE))->will($this->returnValue($isSetFlag));
     $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();
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testSendPasswordReminderEmail()
 {
     $customerId = 1;
     $customerStoreId = 2;
     $customerEmail = '*****@*****.**';
     $passwordToken = 'token';
     $isFrontendSecure = true;
     $resetUrl = 'reset url';
     $customerData = ['key' => 'value'];
     $customerName = 'Customer Name';
     $templateIdentifier = 'Template Identifier';
     $sender = 'Sender';
     $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
     $customer->expects($this->any())->method('getStoreId')->willReturn($customerStoreId);
     $customer->expects($this->any())->method('getId')->willReturn($customerId);
     $customer->expects($this->any())->method('getEmail')->willReturn($customerEmail);
     $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $this->storeManager->expects($this->any())->method('getStore')->with($customerStoreId)->willReturn($store);
     $store->expects($this->any())->method('isFrontUrlSecure')->willReturn($isFrontendSecure);
     $this->url->expects($this->once())->method('getUrl')->with('customer/account/createPassword', ['_query' => ['id' => $customerId, 'token' => $passwordToken], '_store' => $customerStoreId, '_secure' => $isFrontendSecure])->willReturn($resetUrl);
     $customerSecure = $this->getMockBuilder('\\Magento\\Customer\\Model\\Data\\CustomerSecure')->disableOriginalConstructor()->setMethods(['addData', 'setData', 'setResetPasswordUrl'])->getMock();
     $this->customerRegistry->expects($this->once())->method('retrieveSecureData')->with($customerId)->willReturn($customerSecure);
     $this->dataObjectProcessor->expects($this->once())->method('buildOutputDataArray')->with($customer, '\\Magento\\Customer\\Api\\Data\\CustomerInterface')->willReturn($customerData);
     $this->customerViewHelper->expects($this->any())->method('getCustomerName')->with($customer)->willReturn($customerName);
     $customerSecure->expects($this->once())->method('addData')->with($customerData)->willReturnSelf();
     $customerSecure->expects($this->once())->method('setData')->with('name', $customerName)->willReturnSelf();
     $customerSecure->expects($this->once())->method('setResetPasswordUrl')->with($resetUrl);
     $this->scopeConfig->expects($this->at(0))->method('getValue')->with(AccountManagement::XML_PATH_REMIND_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE, $customerStoreId)->willReturn($templateIdentifier);
     $this->scopeConfig->expects($this->at(1))->method('getValue')->with(AccountManagement::XML_PATH_FORGOT_EMAIL_IDENTITY, ScopeInterface::SCOPE_STORE, $customerStoreId)->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')->with(['area' => Area::AREA_FRONTEND, 'store' => $customerStoreId])->willReturnSelf();
     $this->transportBuilder->expects($this->once())->method('setTemplateVars')->with(['customer' => $customerSecure, 'store' => $store])->willReturnSelf();
     $this->transportBuilder->expects($this->once())->method('setFrom')->with($sender)->willReturnSelf();
     $this->transportBuilder->expects($this->once())->method('addTo')->with($customerEmail, $customerName)->willReturnSelf();
     $this->transportBuilder->expects($this->once())->method('getTransport')->willReturn($transport);
     $transport->expects($this->once())->method('sendMessage');
     $this->assertEquals($this->accountManagement, $this->accountManagement->sendPasswordReminderEmail($customer, $passwordToken));
 }
예제 #11
0
 public function testExecuteCanNotSaveWishlistAndWithRedirect()
 {
     $referer = 'http://referer-url.com';
     $exception = new \Exception('Message');
     $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false);
     $wishlist->expects($this->once())->method('save')->willThrowException($exception);
     $this->wishlistProvider->expects($this->once())->method('getWishlist')->with(2)->willReturn($wishlist);
     $this->messageManager->expects($this->once())->method('addError')->with('An error occurred while deleting the item from wish list.')->willReturn(true);
     $wishlistHelper = $this->getMock('Magento\\Wishlist\\Helper\\Data', [], [], '', false);
     $wishlistHelper->expects($this->once())->method('calculate')->willReturnSelf();
     $this->om->expects($this->once())->method('get')->with('Magento\\Wishlist\\Helper\\Data')->will($this->returnValue($wishlistHelper));
     $item = $this->getMock('Magento\\Wishlist\\Model\\Item', [], [], '', false);
     $item->expects($this->once())->method('load')->with(1)->willReturnSelf();
     $item->expects($this->once())->method('getId')->willReturn(1);
     $item->expects($this->once())->method('__call')->with('getWishlistId')->willReturn(2);
     $item->expects($this->once())->method('delete')->willReturn(true);
     $this->om->expects($this->once())->method('create')->with('Magento\\Wishlist\\Model\\Item')->willReturn($item);
     $this->request->expects($this->once())->method('getServer')->with('HTTP_REFERER')->willReturn($referer);
     $this->request->expects($this->exactly(3))->method('getParam')->willReturnMap([['item', null, 1], ['referer_url', null, $referer], ['uenc', null, false]]);
     $this->url->expects($this->once())->method('getUrl')->with('*/*')->willReturn('http:/test.com/frontname/module/controller/action');
     $this->redirect->expects($this->once())->method('getRedirectUrl')->willReturn('http:/test.com/frontname/module/controller/action');
     $this->response->expects($this->once())->method('setRedirect')->with('http:/test.com/frontname/module/controller/action')->willReturn(true);
     $this->getController()->execute();
 }