diff --git a/app/code/Magento/Sales/view/frontend/layout/sales_email_order_shipment_track.xml b/app/code/Magento/Sales/view/frontend/layout/sales_email_order_shipment_track.xml
new file mode 100644
index 0000000000000..91414663951d3
--- /dev/null
+++ b/app/code/Magento/Sales/view/frontend/layout/sales_email_order_shipment_track.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/code/Magento/SalesAnalytics/composer.json b/app/code/Magento/SalesAnalytics/composer.json
index 64424c8f5bc61..b77dcd7e71c65 100644
--- a/app/code/Magento/SalesAnalytics/composer.json
+++ b/app/code/Magento/SalesAnalytics/composer.json
@@ -4,7 +4,8 @@
"require": {
"php": "~7.1.3||~7.2.0",
"magento/framework": "*",
- "magento/module-sales": "*"
+ "magento/module-sales": "*",
+ "magento/module-analytics": "*"
},
"type": "magento2-module",
"license": [
diff --git a/app/code/Magento/SalesGraphQl/Model/Resolver/Orders.php b/app/code/Magento/SalesGraphQl/Model/Resolver/Orders.php
index 5802115d44b5e..3e592cf061dfc 100644
--- a/app/code/Magento/SalesGraphQl/Model/Resolver/Orders.php
+++ b/app/code/Magento/SalesGraphQl/Model/Resolver/Orders.php
@@ -11,7 +11,7 @@
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface;
-use Magento\CustomerGraphQl\Model\Customer\CheckCustomerAccount;
+use Magento\CustomerGraphQl\Model\Customer\GetCustomer;
/**
* Orders data reslover
@@ -24,20 +24,20 @@ class Orders implements ResolverInterface
private $collectionFactory;
/**
- * @var CheckCustomerAccount
+ * @var GetCustomer
*/
- private $checkCustomerAccount;
+ private $getCustomer;
/**
* @param CollectionFactoryInterface $collectionFactory
- * @param CheckCustomerAccount $checkCustomerAccount
+ * @param GetCustomer $getCustomer
*/
public function __construct(
CollectionFactoryInterface $collectionFactory,
- CheckCustomerAccount $checkCustomerAccount
+ GetCustomer $getCustomer
) {
$this->collectionFactory = $collectionFactory;
- $this->checkCustomerAccount = $checkCustomerAccount;
+ $this->getCustomer = $getCustomer;
}
/**
@@ -50,11 +50,10 @@ public function resolve(
array $value = null,
array $args = null
) {
- $customerId = $context->getUserId();
- $this->checkCustomerAccount->execute($customerId, $context->getUserType());
+ $customer = $this->getCustomer->execute($context);
$items = [];
- $orders = $this->collectionFactory->create($customerId);
+ $orders = $this->collectionFactory->create($customer->getId());
/** @var \Magento\Sales\Model\Order $order */
foreach ($orders as $order) {
diff --git a/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewConditionHtml.php b/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewConditionHtml.php
index a0238890d98af..50545fd864866 100644
--- a/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewConditionHtml.php
+++ b/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewConditionHtml.php
@@ -1,12 +1,16 @@
__('Subtotal (Excl. Tax)'),
'base_subtotal' => __('Subtotal'),
'total_qty' => __('Total Items Quantity'),
'weight' => __('Total Weight'),
diff --git a/app/code/Magento/SalesRule/Test/Mftf/Data/AdminMenuData.xml b/app/code/Magento/SalesRule/Test/Mftf/Data/AdminMenuData.xml
new file mode 100644
index 0000000000000..5a42980df1bbf
--- /dev/null
+++ b/app/code/Magento/SalesRule/Test/Mftf/Data/AdminMenuData.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+ Cart Price Rules
+ Cart Price Rules
+ magento-salesrule-promo-quote
+
+
diff --git a/app/code/Magento/SalesRule/Test/Mftf/Test/AdminCartRulesAppliedForProductInCartTest.xml b/app/code/Magento/SalesRule/Test/Mftf/Test/AdminCartRulesAppliedForProductInCartTest.xml
index fbcc871a69b97..ab085dc5ae137 100644
--- a/app/code/Magento/SalesRule/Test/Mftf/Test/AdminCartRulesAppliedForProductInCartTest.xml
+++ b/app/code/Magento/SalesRule/Test/Mftf/Test/AdminCartRulesAppliedForProductInCartTest.xml
@@ -21,26 +21,30 @@
-
-
200
500
+
+
+
-
+
+
+
+
@@ -57,12 +61,14 @@
+
+
@@ -92,7 +98,7 @@
-
+
diff --git a/app/code/Magento/SalesRule/Test/Mftf/Test/AdminMarketingCartPriceRulesNavigateMenuTest.xml b/app/code/Magento/SalesRule/Test/Mftf/Test/AdminMarketingCartPriceRulesNavigateMenuTest.xml
new file mode 100644
index 0000000000000..f281b0abf87a0
--- /dev/null
+++ b/app/code/Magento/SalesRule/Test/Mftf/Test/AdminMarketingCartPriceRulesNavigateMenuTest.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/code/Magento/Search/Controller/Adminhtml/Synonyms/MassDelete.php b/app/code/Magento/Search/Controller/Adminhtml/Synonyms/MassDelete.php
index f2770f77cc533..c32ca04d39b61 100644
--- a/app/code/Magento/Search/Controller/Adminhtml/Synonyms/MassDelete.php
+++ b/app/code/Magento/Search/Controller/Adminhtml/Synonyms/MassDelete.php
@@ -6,15 +6,17 @@
namespace Magento\Search\Controller\Adminhtml\Synonyms;
+use Magento\Framework\App\Action\HttpPostActionInterface;
+
/**
- * Mass-Delete Controller
+ * Mass-Delete Controller.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
-class MassDelete extends \Magento\Backend\App\Action
+class MassDelete extends \Magento\Backend\App\Action implements HttpPostActionInterface
{
/**
- * Authorization level of a basic admin session
+ * Authorization level of a basic admin session.
*
* @see _isAllowed()
*/
@@ -56,7 +58,7 @@ public function __construct(
}
/**
- * Execute action
+ * Execute action.
*
* @return \Magento\Backend\Model\View\Result\Redirect
* @throws \Magento\Framework\Exception\LocalizedException|\Exception
diff --git a/app/code/Magento/Search/Model/ResourceModel/SynonymReader.php b/app/code/Magento/Search/Model/ResourceModel/SynonymReader.php
index 46e794a1954cf..45eee0a4001d1 100644
--- a/app/code/Magento/Search/Model/ResourceModel/SynonymReader.php
+++ b/app/code/Magento/Search/Model/ResourceModel/SynonymReader.php
@@ -87,7 +87,7 @@ private function queryByPhrase($phrase)
{
$matchQuery = $this->fullTextSelect->getMatchQuery(
['synonyms' => 'synonyms'],
- $phrase,
+ $this->escapePhrase($phrase),
Fulltext::FULLTEXT_MODE_BOOLEAN
);
$query = $this->getConnection()->select()->from(
@@ -97,6 +97,18 @@ private function queryByPhrase($phrase)
return $this->getConnection()->fetchAll($query);
}
+ /**
+ * Cut trailing plus or minus sign, and @ symbol, using of which causes InnoDB to report a syntax error.
+ *
+ * @see https://dev.mysql.com/doc/refman/5.7/en/fulltext-boolean.html
+ * @param string $phrase
+ * @return string
+ */
+ private function escapePhrase(string $phrase): string
+ {
+ return preg_replace('/@+|[@+-]+$/', '', $phrase);
+ }
+
/**
* A private helper function to retrieve matching synonym groups per scope
*
diff --git a/app/code/Magento/Search/Test/Mftf/ActionGroup/AdminSearchTermActionGroup.xml b/app/code/Magento/Search/Test/Mftf/ActionGroup/AdminSearchTermActionGroup.xml
new file mode 100644
index 0000000000000..e0b3d4b850bbb
--- /dev/null
+++ b/app/code/Magento/Search/Test/Mftf/ActionGroup/AdminSearchTermActionGroup.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/code/Magento/Search/Test/Mftf/Data/SearchTermData.xml b/app/code/Magento/Search/Test/Mftf/Data/SearchTermData.xml
new file mode 100644
index 0000000000000..1518adad01347
--- /dev/null
+++ b/app/code/Magento/Search/Test/Mftf/Data/SearchTermData.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+ Query text
+ 1
+ http://example.com/
+ 0
+
+
diff --git a/app/code/Magento/Search/Test/Mftf/Metadata/search_term-meta.xml b/app/code/Magento/Search/Test/Mftf/Metadata/search_term-meta.xml
new file mode 100644
index 0000000000000..0bd2dc9be4855
--- /dev/null
+++ b/app/code/Magento/Search/Test/Mftf/Metadata/search_term-meta.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+ string
+ integer
+ string
+ integer
+
+
diff --git a/app/code/Magento/Search/Test/Mftf/Section/StorefrontQuickSearchResultsSection.xml b/app/code/Magento/Search/Test/Mftf/Section/StorefrontQuickSearchResultsSection.xml
index 9e5bde9a2be49..0bb929d889351 100644
--- a/app/code/Magento/Search/Test/Mftf/Section/StorefrontQuickSearchResultsSection.xml
+++ b/app/code/Magento/Search/Test/Mftf/Section/StorefrontQuickSearchResultsSection.xml
@@ -11,7 +11,13 @@
+
+
+
+
+
+
diff --git a/app/code/Magento/Search/Test/Mftf/Test/AdminMassDeleteSearchTermEntityTest.xml b/app/code/Magento/Search/Test/Mftf/Test/AdminMassDeleteSearchTermEntityTest.xml
new file mode 100644
index 0000000000000..67ccb51bf401e
--- /dev/null
+++ b/app/code/Magento/Search/Test/Mftf/Test/AdminMassDeleteSearchTermEntityTest.xml
@@ -0,0 +1,83 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/code/Magento/Search/i18n/de_DE.csv b/app/code/Magento/Search/i18n/de_DE.csv
deleted file mode 100644
index 8b4b04aa3b9ec..0000000000000
--- a/app/code/Magento/Search/i18n/de_DE.csv
+++ /dev/null
@@ -1 +0,0 @@
-"Search Engine","Search Engine"
diff --git a/app/code/Magento/Search/i18n/es_ES.csv b/app/code/Magento/Search/i18n/es_ES.csv
deleted file mode 100644
index 8b4b04aa3b9ec..0000000000000
--- a/app/code/Magento/Search/i18n/es_ES.csv
+++ /dev/null
@@ -1 +0,0 @@
-"Search Engine","Search Engine"
diff --git a/app/code/Magento/Search/i18n/fr_FR.csv b/app/code/Magento/Search/i18n/fr_FR.csv
deleted file mode 100644
index 8b4b04aa3b9ec..0000000000000
--- a/app/code/Magento/Search/i18n/fr_FR.csv
+++ /dev/null
@@ -1 +0,0 @@
-"Search Engine","Search Engine"
diff --git a/app/code/Magento/Search/i18n/nl_NL.csv b/app/code/Magento/Search/i18n/nl_NL.csv
deleted file mode 100644
index 8b4b04aa3b9ec..0000000000000
--- a/app/code/Magento/Search/i18n/nl_NL.csv
+++ /dev/null
@@ -1 +0,0 @@
-"Search Engine","Search Engine"
diff --git a/app/code/Magento/Search/i18n/pt_BR.csv b/app/code/Magento/Search/i18n/pt_BR.csv
deleted file mode 100644
index c10566a7c9800..0000000000000
--- a/app/code/Magento/Search/i18n/pt_BR.csv
+++ /dev/null
@@ -1 +0,0 @@
-"Search Engine","Mecanismo de Busca"
diff --git a/app/code/Magento/Search/i18n/zh_Hans_CN.csv b/app/code/Magento/Search/i18n/zh_Hans_CN.csv
deleted file mode 100644
index 8b4b04aa3b9ec..0000000000000
--- a/app/code/Magento/Search/i18n/zh_Hans_CN.csv
+++ /dev/null
@@ -1 +0,0 @@
-"Search Engine","Search Engine"
diff --git a/app/code/Magento/SendFriend/Block/Send.php b/app/code/Magento/SendFriend/Block/Send.php
index 43e95ebe43d48..1c4b550361359 100644
--- a/app/code/Magento/SendFriend/Block/Send.php
+++ b/app/code/Magento/SendFriend/Block/Send.php
@@ -5,6 +5,7 @@
*/
namespace Magento\SendFriend\Block;
+use Magento\Captcha\Block\Captcha;
use Magento\Customer\Model\Context;
/**
@@ -170,6 +171,7 @@ public function setFormData($data)
/**
* Retrieve Current Product Id
*
+ * @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
* @return int
*/
public function getProductId()
@@ -180,6 +182,7 @@ public function getProductId()
/**
* Retrieve current category id for product
*
+ * @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
* @return int
*/
public function getCategoryId()
@@ -222,4 +225,24 @@ public function canSend()
{
return !$this->sendfriend->isExceedLimit();
}
+
+ /**
+ * @inheritdoc
+ */
+ protected function _prepareLayout()
+ {
+ if (!$this->getChildBlock('captcha')) {
+ $this->addChild(
+ 'captcha',
+ Captcha::class,
+ [
+ 'cacheable' => false,
+ 'after' => '-',
+ 'form_id' => 'product_sendtofriend_form',
+ 'image_width' => 230,
+ 'image_height' => 230
+ ]
+ );
+ }
+ }
}
diff --git a/app/code/Magento/SendFriend/Controller/Product/Send.php b/app/code/Magento/SendFriend/Controller/Product/Send.php
index 8b0ae8dcf4383..d9fef595ce2a3 100644
--- a/app/code/Magento/SendFriend/Controller/Product/Send.php
+++ b/app/code/Magento/SendFriend/Controller/Product/Send.php
@@ -5,9 +5,13 @@
*/
namespace Magento\SendFriend\Controller\Product;
+use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\Controller\ResultFactory;
-class Send extends \Magento\SendFriend\Controller\Product
+/**
+ * Controller class. Represents rendering and request flow
+ */
+class Send extends \Magento\SendFriend\Controller\Product implements HttpGetActionInterface
{
/**
* @var \Magento\Catalog\Model\Session
diff --git a/app/code/Magento/SendFriend/Controller/Product/Sendmail.php b/app/code/Magento/SendFriend/Controller/Product/Sendmail.php
index 4b1f724cb83a6..696c235899370 100644
--- a/app/code/Magento/SendFriend/Controller/Product/Sendmail.php
+++ b/app/code/Magento/SendFriend/Controller/Product/Sendmail.php
@@ -6,10 +6,18 @@
namespace Magento\SendFriend\Controller\Product;
+use Magento\Framework\App\Action\HttpPostActionInterface;
+use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Controller\ResultFactory;
+use Magento\SendFriend\Model\CaptchaValidator;
-class Sendmail extends \Magento\SendFriend\Controller\Product
+/**
+ * Class Sendmail. Represents request flow logic of 'sendmail' feature
+ *
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
+ */
+class Sendmail extends \Magento\SendFriend\Controller\Product implements HttpPostActionInterface
{
/**
* @var \Magento\Catalog\Api\CategoryRepositoryInterface
@@ -22,6 +30,13 @@ class Sendmail extends \Magento\SendFriend\Controller\Product
protected $catalogSession;
/**
+ * @var CaptchaValidator
+ */
+ private $captchaValidator;
+
+ /**
+ * Sendmail class construct
+ *
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Framework\Registry $coreRegistry
* @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator
@@ -29,6 +44,7 @@ class Sendmail extends \Magento\SendFriend\Controller\Product
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
* @param \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository
* @param \Magento\Catalog\Model\Session $catalogSession
+ * @param CaptchaValidator|null $captchaValidator
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
@@ -37,11 +53,13 @@ public function __construct(
\Magento\SendFriend\Model\SendFriend $sendFriend,
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
\Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository,
- \Magento\Catalog\Model\Session $catalogSession
+ \Magento\Catalog\Model\Session $catalogSession,
+ CaptchaValidator $captchaValidator = null
) {
parent::__construct($context, $coreRegistry, $formKeyValidator, $sendFriend, $productRepository);
$this->categoryRepository = $categoryRepository;
$this->catalogSession = $catalogSession;
+ $this->captchaValidator = $captchaValidator ?: ObjectManager::getInstance()->create(CaptchaValidator::class);
}
/**
@@ -49,17 +67,13 @@ public function __construct(
*
* @return \Magento\Framework\Controller\ResultInterface
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
+ * @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function execute()
{
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
- if (!$this->_formKeyValidator->validate($this->getRequest())) {
- $resultRedirect->setPath('sendfriend/product/send', ['_current' => true]);
- return $resultRedirect;
- }
-
$product = $this->_initProduct();
$data = $this->getRequest()->getPostValue();
@@ -89,6 +103,9 @@ public function execute()
try {
$validate = $this->sendFriend->validate();
+
+ $this->captchaValidator->validateSending($this->getRequest());
+
if ($validate === true) {
$this->sendFriend->send();
$this->messageManager->addSuccess(__('The link to a friend was sent.'));
diff --git a/app/code/Magento/SendFriend/Model/CaptchaValidator.php b/app/code/Magento/SendFriend/Model/CaptchaValidator.php
new file mode 100644
index 0000000000000..11fbbdf72f6db
--- /dev/null
+++ b/app/code/Magento/SendFriend/Model/CaptchaValidator.php
@@ -0,0 +1,123 @@
+captchaHelper = $captchaHelper;
+ $this->captchaStringResolver = $captchaStringResolver;
+ $this->currentUser = $currentUser;
+ $this->customerRepository = $customerRepository;
+ }
+
+ /**
+ * Entry point for captcha validation
+ *
+ * @param RequestInterface $request
+ * @throws LocalizedException
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
+ */
+ public function validateSending(RequestInterface $request): void
+ {
+ $this->validateCaptcha($request);
+ }
+
+ /**
+ * Validates captcha and triggers log attempt
+ *
+ * @param RequestInterface $request
+ * @throws LocalizedException
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
+ */
+ private function validateCaptcha(RequestInterface $request): void
+ {
+ $captchaTargetFormName = 'product_sendtofriend_form';
+ /** @var DefaultModel $captchaModel */
+ $captchaModel = $this->captchaHelper->getCaptcha($captchaTargetFormName);
+
+ if ($captchaModel->isRequired()) {
+ $word = $this->captchaStringResolver->resolve(
+ $request,
+ $captchaTargetFormName
+ );
+
+ $isCorrectCaptcha = $captchaModel->isCorrect($word);
+
+ if (!$isCorrectCaptcha) {
+ $this->logCaptchaAttempt($captchaModel);
+ throw new LocalizedException(__('Incorrect CAPTCHA'));
+ }
+ }
+
+ $this->logCaptchaAttempt($captchaModel);
+ }
+
+ /**
+ * Log captcha attempts
+ *
+ * @param DefaultModel $captchaModel
+ * @throws LocalizedException
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
+ */
+ private function logCaptchaAttempt(DefaultModel $captchaModel): void
+ {
+ $email = '';
+
+ if ($this->currentUser->getUserType() == UserContextInterface::USER_TYPE_CUSTOMER) {
+ $email = $this->customerRepository->getById($this->currentUser->getUserId())->getEmail();
+ }
+
+ $captchaModel->logAttempt($email);
+ }
+}
diff --git a/app/code/Magento/SendFriend/Model/SendFriend.php b/app/code/Magento/SendFriend/Model/SendFriend.php
index 38525a9f83a12..825cac2bae10b 100644
--- a/app/code/Magento/SendFriend/Model/SendFriend.php
+++ b/app/code/Magento/SendFriend/Model/SendFriend.php
@@ -163,7 +163,7 @@ protected function _construct()
}
/**
- * Send email.
+ * Sends email to recipients
*
* @return $this
* @throws CoreException
diff --git a/app/code/Magento/SendFriend/Test/Unit/Controller/Product/SendTest.php b/app/code/Magento/SendFriend/Test/Unit/Controller/Product/SendTest.php
deleted file mode 100644
index 9d48133c1d500..0000000000000
--- a/app/code/Magento/SendFriend/Test/Unit/Controller/Product/SendTest.php
+++ /dev/null
@@ -1,423 +0,0 @@
-requestMock = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class)
- ->getMockForAbstractClass();
- $this->registryMock = $this->getMockBuilder(\Magento\Framework\Registry::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->validatorMock = $this->getMockBuilder(\Magento\Framework\Data\Form\FormKey\Validator::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->sendFriendMock = $this->getMockBuilder(\Magento\SendFriend\Model\SendFriend::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->productRepositoryMock = $this->getMockBuilder(\Magento\Catalog\Api\ProductRepositoryInterface::class)
- ->getMockForAbstractClass();
- $this->catalogSessionMock = $this->getMockBuilder(\Magento\Catalog\Model\Session::class)
- ->setMethods(['getSendfriendFormData', 'setSendfriendFormData'])
- ->disableOriginalConstructor()
- ->getMock();
- $this->messageManagerMock = $this->getMockBuilder(\Magento\Framework\Message\ManagerInterface::class)
- ->getMock();
- $this->resultFactoryMock = $this->getMockBuilder(\Magento\Framework\Controller\ResultFactory::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->eventManagerMock = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class)
- ->getMock();
-
- $this->objectManagerHelper = new ObjectManagerHelper($this);
- $this->model = $this->objectManagerHelper->getObject(
- \Magento\SendFriend\Controller\Product\Send::class,
- [
- 'request' => $this->requestMock,
- 'coreRegistry' => $this->registryMock,
- 'formKeyValidator' => $this->validatorMock,
- 'sendFriend' => $this->sendFriendMock,
- 'productRepository' => $this->productRepositoryMock,
- 'catalogSession' => $this->catalogSessionMock,
- 'messageManager' => $this->messageManagerMock,
- 'resultFactory' => $this->resultFactoryMock,
- 'eventManager' => $this->eventManagerMock,
- ]
- );
- }
-
- /**
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function testExecute()
- {
- $productId = 11;
- $formData = ['some' => 'data'];
-
- $this->requestMock->expects($this->once())
- ->method('getParam')
- ->with('id', null)
- ->willReturn($productId);
-
- /** @var \Magento\Catalog\Api\Data\ProductInterface|\PHPUnit_Framework_MockObject_MockObject $productMock */
- $productMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class)
- ->setMethods(['isVisibleInCatalog'])
- ->getMockForAbstractClass();
-
- $this->productRepositoryMock->expects($this->once())
- ->method('getById')
- ->with($productId, false, null, false)
- ->willReturn($productMock);
-
- $productMock->expects($this->once())
- ->method('isVisibleInCatalog')
- ->willReturn(true);
-
- $this->registryMock->expects($this->once())
- ->method('register')
- ->with('product', $productMock, false);
-
- $this->sendFriendMock->expects($this->once())
- ->method('getMaxSendsToFriend')
- ->willReturn(11);
- $this->sendFriendMock->expects($this->once())
- ->method('isExceedLimit')
- ->willReturn(false);
-
- $this->messageManagerMock->expects($this->never())
- ->method('addNotice');
-
- /** @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject $pageMock */
- $pageMock = $this->getMockBuilder(\Magento\Framework\View\Result\Page::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->resultFactoryMock->expects($this->once())
- ->method('create')
- ->with(\Magento\Framework\Controller\ResultFactory::TYPE_PAGE, [])
- ->willReturn($pageMock);
-
- $this->eventManagerMock->expects($this->once())
- ->method('dispatch')
- ->with('sendfriend_product', ['product' => $productMock]);
-
- $this->catalogSessionMock->expects($this->once())
- ->method('getSendfriendFormData')
- ->willReturn($formData);
- $this->catalogSessionMock->expects($this->once())
- ->method('setSendfriendFormData')
- ->with(true);
-
- /** @var \Magento\Framework\View\Layout|\PHPUnit_Framework_MockObject_MockObject $layoutMock */
- $layoutMock = $this->getMockBuilder(\Magento\Framework\View\Layout::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $pageMock->expects($this->once())
- ->method('getLayout')
- ->willReturn($layoutMock);
-
- /** @var \Magento\SendFriend\Block\Send|\PHPUnit_Framework_MockObject_MockObject $blockMock */
- $blockMock = $this->getMockBuilder(\Magento\SendFriend\Block\Send::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $layoutMock->expects($this->once())
- ->method('getBlock')
- ->with('sendfriend.send')
- ->willReturn($blockMock);
-
- $blockMock->expects($this->once())
- ->method('setFormData')
- ->with($formData)
- ->willReturnSelf();
-
- $this->assertEquals($pageMock, $this->model->execute());
- }
-
- /**
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function testExecuteWithoutBlock()
- {
- $productId = 11;
- $formData = ['some' => 'data'];
-
- $this->requestMock->expects($this->once())
- ->method('getParam')
- ->with('id', null)
- ->willReturn($productId);
-
- /** @var \Magento\Catalog\Api\Data\ProductInterface|\PHPUnit_Framework_MockObject_MockObject $productMock */
- $productMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class)
- ->setMethods(['isVisibleInCatalog'])
- ->getMockForAbstractClass();
-
- $this->productRepositoryMock->expects($this->once())
- ->method('getById')
- ->with($productId, false, null, false)
- ->willReturn($productMock);
-
- $productMock->expects($this->once())
- ->method('isVisibleInCatalog')
- ->willReturn(true);
-
- $this->registryMock->expects($this->once())
- ->method('register')
- ->with('product', $productMock, false);
-
- $this->sendFriendMock->expects($this->once())
- ->method('getMaxSendsToFriend')
- ->willReturn(11);
- $this->sendFriendMock->expects($this->once())
- ->method('isExceedLimit')
- ->willReturn(false);
-
- $this->messageManagerMock->expects($this->never())
- ->method('addNotice');
-
- /** @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject $pageMock */
- $pageMock = $this->getMockBuilder(\Magento\Framework\View\Result\Page::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->resultFactoryMock->expects($this->once())
- ->method('create')
- ->with(\Magento\Framework\Controller\ResultFactory::TYPE_PAGE, [])
- ->willReturn($pageMock);
-
- $this->eventManagerMock->expects($this->once())
- ->method('dispatch')
- ->with('sendfriend_product', ['product' => $productMock]);
-
- $this->catalogSessionMock->expects($this->once())
- ->method('getSendfriendFormData')
- ->willReturn($formData);
- $this->catalogSessionMock->expects($this->once())
- ->method('setSendfriendFormData')
- ->with(true);
-
- /** @var \Magento\Framework\View\Layout|\PHPUnit_Framework_MockObject_MockObject $layoutMock */
- $layoutMock = $this->getMockBuilder(\Magento\Framework\View\Layout::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $pageMock->expects($this->once())
- ->method('getLayout')
- ->willReturn($layoutMock);
-
- $layoutMock->expects($this->once())
- ->method('getBlock')
- ->with('sendfriend.send')
- ->willReturn(false);
-
- $this->assertEquals($pageMock, $this->model->execute());
- }
-
- public function testExecuteWithNoticeAndNoData()
- {
- $productId = 11;
- $formData = null;
-
- $this->requestMock->expects($this->once())
- ->method('getParam')
- ->with('id', null)
- ->willReturn($productId);
-
- /** @var \Magento\Catalog\Api\Data\ProductInterface|\PHPUnit_Framework_MockObject_MockObject $productMock */
- $productMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class)
- ->setMethods(['isVisibleInCatalog'])
- ->getMockForAbstractClass();
-
- $this->productRepositoryMock->expects($this->once())
- ->method('getById')
- ->with($productId, false, null, false)
- ->willReturn($productMock);
-
- $productMock->expects($this->once())
- ->method('isVisibleInCatalog')
- ->willReturn(true);
-
- $this->registryMock->expects($this->once())
- ->method('register')
- ->with('product', $productMock, false);
-
- $this->sendFriendMock->expects($this->exactly(2))
- ->method('getMaxSendsToFriend')
- ->willReturn(11);
- $this->sendFriendMock->expects($this->once())
- ->method('isExceedLimit')
- ->willReturn(true);
-
- $this->messageManagerMock->expects($this->once())
- ->method('addNotice')
- ->with(__('You can\'t send messages more than %1 times an hour.', 11))
- ->willReturnSelf();
-
- /** @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject $pageMock */
- $pageMock = $this->getMockBuilder(\Magento\Framework\View\Result\Page::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->resultFactoryMock->expects($this->once())
- ->method('create')
- ->with(\Magento\Framework\Controller\ResultFactory::TYPE_PAGE, [])
- ->willReturn($pageMock);
-
- $this->eventManagerMock->expects($this->once())
- ->method('dispatch')
- ->with('sendfriend_product', ['product' => $productMock]);
-
- $this->catalogSessionMock->expects($this->once())
- ->method('getSendfriendFormData')
- ->willReturn($formData);
- $this->catalogSessionMock->expects($this->never())
- ->method('setSendfriendFormData');
-
- $pageMock->expects($this->never())
- ->method('getLayout');
-
- $this->assertEquals($pageMock, $this->model->execute());
- }
-
- public function testExecuteWithoutParam()
- {
- $this->requestMock->expects($this->once())
- ->method('getParam')
- ->with('id', null)
- ->willReturn(null);
-
- /** @var \Magento\Framework\Controller\Result\Forward|\PHPUnit_Framework_MockObject_MockObject $forwardMock */
- $forwardMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Forward::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->resultFactoryMock->expects($this->once())
- ->method('create')
- ->with(\Magento\Framework\Controller\ResultFactory::TYPE_FORWARD, [])
- ->willReturn($forwardMock);
-
- $forwardMock->expects($this->once())
- ->method('forward')
- ->with('noroute')
- ->willReturnSelf();
-
- $this->assertEquals($forwardMock, $this->model->execute());
- }
-
- public function testExecuteWithoutProduct()
- {
- $productId = 11;
-
- $this->requestMock->expects($this->once())
- ->method('getParam')
- ->with('id', null)
- ->willReturn($productId);
-
- $this->productRepositoryMock->expects($this->once())
- ->method('getById')
- ->with($productId, false, null, false)
- ->willThrowException(new \Magento\Framework\Exception\NoSuchEntityException(__('No Product Exception.')));
-
- /** @var \Magento\Framework\Controller\Result\Forward|\PHPUnit_Framework_MockObject_MockObject $forwardMock */
- $forwardMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Forward::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->resultFactoryMock->expects($this->once())
- ->method('create')
- ->with(\Magento\Framework\Controller\ResultFactory::TYPE_FORWARD, [])
- ->willReturn($forwardMock);
-
- $forwardMock->expects($this->once())
- ->method('forward')
- ->with('noroute')
- ->willReturnSelf();
-
- $this->assertEquals($forwardMock, $this->model->execute());
- }
-
- public function testExecuteWithNonVisibleProduct()
- {
- $productId = 11;
-
- $this->requestMock->expects($this->once())
- ->method('getParam')
- ->with('id', null)
- ->willReturn($productId);
-
- /** @var \Magento\Catalog\Api\Data\ProductInterface|\PHPUnit_Framework_MockObject_MockObject $productMock */
- $productMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class)
- ->setMethods(['isVisibleInCatalog'])
- ->getMockForAbstractClass();
-
- $this->productRepositoryMock->expects($this->once())
- ->method('getById')
- ->with($productId, false, null, false)
- ->willReturn($productMock);
-
- $productMock->expects($this->once())
- ->method('isVisibleInCatalog')
- ->willReturn(false);
-
- /** @var \Magento\Framework\Controller\Result\Forward|\PHPUnit_Framework_MockObject_MockObject $forwardMock */
- $forwardMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Forward::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->resultFactoryMock->expects($this->once())
- ->method('create')
- ->with(\Magento\Framework\Controller\ResultFactory::TYPE_FORWARD, [])
- ->willReturn($forwardMock);
-
- $forwardMock->expects($this->once())
- ->method('forward')
- ->with('noroute')
- ->willReturnSelf();
-
- $this->assertEquals($forwardMock, $this->model->execute());
- }
-}
diff --git a/app/code/Magento/SendFriend/Test/Unit/Controller/Product/SendmailTest.php b/app/code/Magento/SendFriend/Test/Unit/Controller/Product/SendmailTest.php
deleted file mode 100644
index c7881f366f520..0000000000000
--- a/app/code/Magento/SendFriend/Test/Unit/Controller/Product/SendmailTest.php
+++ /dev/null
@@ -1,906 +0,0 @@
-requestMock = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class)
- ->setMethods(['getPost', 'getPostValue', 'getParam'])
- ->getMockForAbstractClass();
- $this->registryMock = $this->getMockBuilder(\Magento\Framework\Registry::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->validatorMock = $this->getMockBuilder(\Magento\Framework\Data\Form\FormKey\Validator::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->sendFriendMock = $this->getMockBuilder(\Magento\SendFriend\Model\SendFriend::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->productRepositoryMock = $this->getMockBuilder(\Magento\Catalog\Api\ProductRepositoryInterface::class)
- ->getMockForAbstractClass();
- $this->categoryRepositoryMock = $this->getMockBuilder(\Magento\Catalog\Api\CategoryRepositoryInterface::class)
- ->getMockForAbstractClass();
- $this->catalogSessionMock = $this->getMockBuilder(\Magento\Catalog\Model\Session::class)
- ->setMethods(['getSendfriendFormData', 'setSendfriendFormData'])
- ->disableOriginalConstructor()
- ->getMock();
- $this->messageManagerMock = $this->getMockBuilder(\Magento\Framework\Message\ManagerInterface::class)
- ->getMock();
- $this->resultFactoryMock = $this->getMockBuilder(\Magento\Framework\Controller\ResultFactory::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->eventManagerMock = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class)
- ->getMock();
- $this->redirectMock = $this->getMockBuilder(\Magento\Framework\App\Response\RedirectInterface::class)
- ->getMock();
- $this->urlBuilderMock = $this->getMockBuilder(\Magento\Framework\UrlInterface::class)
- ->getMock();
-
- $this->objectManagerHelper = new ObjectManagerHelper($this);
- $this->model = $this->objectManagerHelper->getObject(
- \Magento\SendFriend\Controller\Product\Sendmail::class,
- [
- 'request' => $this->requestMock,
- 'coreRegistry' => $this->registryMock,
- 'formKeyValidator' => $this->validatorMock,
- 'sendFriend' => $this->sendFriendMock,
- 'productRepository' => $this->productRepositoryMock,
- 'categoryRepository' => $this->categoryRepositoryMock,
- 'catalogSession' => $this->catalogSessionMock,
- 'messageManager' => $this->messageManagerMock,
- 'resultFactory' => $this->resultFactoryMock,
- 'eventManager' => $this->eventManagerMock,
- 'redirect' => $this->redirectMock,
- 'url' => $this->urlBuilderMock,
- ]
- );
- }
-
- /**
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function testExecute()
- {
- $productId = 11;
- $categoryId = 5;
- $sender = 'sender';
- $recipients = 'recipients';
- $formData = [
- 'sender' => $sender,
- 'recipients' => $recipients,
- ];
- $productUrl = 'product_url';
-
- /** @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
- $redirectMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Redirect::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->resultFactoryMock->expects($this->once())
- ->method('create')
- ->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT, [])
- ->willReturn($redirectMock);
-
- $this->validatorMock->expects($this->once())
- ->method('validate')
- ->with($this->requestMock)
- ->willReturn(true);
-
- $this->requestMock->expects($this->exactly(2))
- ->method('getParam')
- ->willReturnMap(
- [
- ['id', null, $productId],
- ['cat_id', null, $categoryId],
- ]
- );
-
- /** @var \Magento\Catalog\Api\Data\ProductInterface|\PHPUnit_Framework_MockObject_MockObject $productMock */
- $productMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class)
- ->setMethods(['isVisibleInCatalog', 'setCategory', 'getProductUrl'])
- ->getMockForAbstractClass();
-
- $this->productRepositoryMock->expects($this->once())
- ->method('getById')
- ->with($productId, false, null, false)
- ->willReturn($productMock);
-
- $productMock->expects($this->once())
- ->method('isVisibleInCatalog')
- ->willReturn(true);
-
- /** @var \Magento\Catalog\Api\Data\CategoryInterface|\PHPUnit_Framework_MockObject_MockObject $categoryMock */
- $categoryMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\CategoryInterface::class)
- ->getMockForAbstractClass();
-
- $this->categoryRepositoryMock->expects($this->once())
- ->method('get')
- ->with($categoryId, null)
- ->willReturn($categoryMock);
-
- $productMock->expects($this->once())
- ->method('setCategory')
- ->with($categoryMock);
-
- $this->registryMock->expects($this->exactly(2))
- ->method('register')
- ->willReturnMap(
- [
- ['product', $productMock, false, null],
- ['current_category', $categoryMock, false, null],
- ]
- );
-
- $this->requestMock->expects($this->once())
- ->method('getPostValue')
- ->willReturn($formData);
-
- $this->requestMock->expects($this->exactly(2))
- ->method('getPost')
- ->willReturnMap(
- [
- ['sender', $sender],
- ['recipients', $recipients],
- ]
- );
-
- $this->sendFriendMock->expects($this->once())
- ->method('setSender')
- ->with($sender)
- ->willReturnSelf();
- $this->sendFriendMock->expects($this->once())
- ->method('setRecipients')
- ->with($recipients)
- ->willReturnSelf();
- $this->sendFriendMock->expects($this->once())
- ->method('setProduct')
- ->with($productMock)
- ->willReturnSelf();
- $this->sendFriendMock->expects($this->once())
- ->method('validate')
- ->willReturn(true);
- $this->sendFriendMock->expects($this->once())
- ->method('send')
- ->willReturnSelf();
-
- $this->messageManagerMock->expects($this->once())
- ->method('addSuccess')
- ->with(__('The link to a friend was sent.'))
- ->willReturnSelf();
-
- $productMock->expects($this->once())
- ->method('getProductUrl')
- ->willReturn($productUrl);
-
- $this->redirectMock->expects($this->once())
- ->method('success')
- ->with($productUrl)
- ->willReturnArgument(0);
-
- $redirectMock->expects($this->once())
- ->method('setUrl')
- ->with($productUrl)
- ->willReturnSelf();
-
- $this->assertEquals($redirectMock, $this->model->execute());
- }
-
- /**
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function testExecuteWithoutValidationAndCategory()
- {
- $productId = 11;
- $categoryId = 5;
- $sender = 'sender';
- $recipients = 'recipients';
- $formData = [
- 'sender' => $sender,
- 'recipients' => $recipients,
- ];
- $redirectUrl = 'redirect_url';
-
- /** @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
- $redirectMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Redirect::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->resultFactoryMock->expects($this->once())
- ->method('create')
- ->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT, [])
- ->willReturn($redirectMock);
-
- $this->validatorMock->expects($this->once())
- ->method('validate')
- ->with($this->requestMock)
- ->willReturn(true);
-
- $this->requestMock->expects($this->exactly(2))
- ->method('getParam')
- ->willReturnMap(
- [
- ['id', null, $productId],
- ['cat_id', null, $categoryId],
- ]
- );
-
- /** @var \Magento\Catalog\Api\Data\ProductInterface|\PHPUnit_Framework_MockObject_MockObject $productMock */
- $productMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class)
- ->setMethods(['isVisibleInCatalog', 'setCategory', 'getProductUrl'])
- ->getMockForAbstractClass();
-
- $this->productRepositoryMock->expects($this->once())
- ->method('getById')
- ->with($productId, false, null, false)
- ->willReturn($productMock);
-
- $productMock->expects($this->once())
- ->method('isVisibleInCatalog')
- ->willReturn(true);
-
- $this->categoryRepositoryMock->expects($this->once())
- ->method('get')
- ->with($categoryId, null)
- ->willThrowException(new \Magento\Framework\Exception\NoSuchEntityException(__('No Category Exception.')));
-
- $productMock->expects($this->never())
- ->method('setCategory');
-
- $this->registryMock->expects($this->once())
- ->method('register')
- ->willReturnMap(
- [
- ['product', $productMock, false, null],
- ]
- );
-
- $this->requestMock->expects($this->once())
- ->method('getPostValue')
- ->willReturn($formData);
-
- $this->requestMock->expects($this->exactly(2))
- ->method('getPost')
- ->willReturnMap(
- [
- ['sender', $sender],
- ['recipients', $recipients],
- ]
- );
-
- $this->sendFriendMock->expects($this->once())
- ->method('setSender')
- ->with($sender)
- ->willReturnSelf();
- $this->sendFriendMock->expects($this->once())
- ->method('setRecipients')
- ->with($recipients)
- ->willReturnSelf();
- $this->sendFriendMock->expects($this->once())
- ->method('setProduct')
- ->with($productMock)
- ->willReturnSelf();
- $this->sendFriendMock->expects($this->once())
- ->method('validate')
- ->willReturn(['Some error']);
- $this->sendFriendMock->expects($this->never())
- ->method('send');
-
- $this->messageManagerMock->expects($this->once())
- ->method('addError')
- ->with(__('Some error'))
- ->willReturnSelf();
-
- $this->catalogSessionMock->expects($this->once())
- ->method('setSendfriendFormData')
- ->with($formData);
-
- $this->urlBuilderMock->expects($this->once())
- ->method('getUrl')
- ->with('sendfriend/product/send', ['_current' => true])
- ->willReturn($redirectUrl);
-
- $this->redirectMock->expects($this->once())
- ->method('error')
- ->with($redirectUrl)
- ->willReturnArgument(0);
-
- $redirectMock->expects($this->once())
- ->method('setUrl')
- ->with($redirectUrl)
- ->willReturnSelf();
-
- $this->assertEquals($redirectMock, $this->model->execute());
- }
-
- /**
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function testExecuteWithoutValidationAndCategoryWithProblems()
- {
- $productId = 11;
- $categoryId = 5;
- $sender = 'sender';
- $recipients = 'recipients';
- $formData = [
- 'sender' => $sender,
- 'recipients' => $recipients,
- ];
- $redirectUrl = 'redirect_url';
-
- /** @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
- $redirectMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Redirect::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->resultFactoryMock->expects($this->once())
- ->method('create')
- ->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT, [])
- ->willReturn($redirectMock);
-
- $this->validatorMock->expects($this->once())
- ->method('validate')
- ->with($this->requestMock)
- ->willReturn(true);
-
- $this->requestMock->expects($this->exactly(2))
- ->method('getParam')
- ->willReturnMap(
- [
- ['id', null, $productId],
- ['cat_id', null, $categoryId],
- ]
- );
-
- /** @var \Magento\Catalog\Api\Data\ProductInterface|\PHPUnit_Framework_MockObject_MockObject $productMock */
- $productMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class)
- ->setMethods(['isVisibleInCatalog', 'setCategory', 'getProductUrl'])
- ->getMockForAbstractClass();
-
- $this->productRepositoryMock->expects($this->once())
- ->method('getById')
- ->with($productId, false, null, false)
- ->willReturn($productMock);
-
- $productMock->expects($this->once())
- ->method('isVisibleInCatalog')
- ->willReturn(true);
-
- $this->categoryRepositoryMock->expects($this->once())
- ->method('get')
- ->with($categoryId, null)
- ->willThrowException(new \Magento\Framework\Exception\NoSuchEntityException(__('No Category Exception.')));
-
- $productMock->expects($this->never())
- ->method('setCategory');
-
- $this->registryMock->expects($this->once())
- ->method('register')
- ->willReturnMap(
- [
- ['product', $productMock, false, null],
- ]
- );
-
- $this->requestMock->expects($this->once())
- ->method('getPostValue')
- ->willReturn($formData);
-
- $this->requestMock->expects($this->exactly(2))
- ->method('getPost')
- ->willReturnMap(
- [
- ['sender', $sender],
- ['recipients', $recipients],
- ]
- );
-
- $this->sendFriendMock->expects($this->once())
- ->method('setSender')
- ->with($sender)
- ->willReturnSelf();
- $this->sendFriendMock->expects($this->once())
- ->method('setRecipients')
- ->with($recipients)
- ->willReturnSelf();
- $this->sendFriendMock->expects($this->once())
- ->method('setProduct')
- ->with($productMock)
- ->willReturnSelf();
- $this->sendFriendMock->expects($this->once())
- ->method('validate')
- ->willReturn('Some error');
- $this->sendFriendMock->expects($this->never())
- ->method('send');
-
- $this->messageManagerMock->expects($this->once())
- ->method('addError')
- ->with(__('We found some problems with the data.'))
- ->willReturnSelf();
-
- $this->catalogSessionMock->expects($this->once())
- ->method('setSendfriendFormData')
- ->with($formData);
-
- $this->urlBuilderMock->expects($this->once())
- ->method('getUrl')
- ->with('sendfriend/product/send', ['_current' => true])
- ->willReturn($redirectUrl);
-
- $this->redirectMock->expects($this->once())
- ->method('error')
- ->with($redirectUrl)
- ->willReturnArgument(0);
-
- $redirectMock->expects($this->once())
- ->method('setUrl')
- ->with($redirectUrl)
- ->willReturnSelf();
-
- $this->assertEquals($redirectMock, $this->model->execute());
- }
-
- /**
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function testExecuteWithLocalizedException()
- {
- $productId = 11;
- $categoryId = 5;
- $sender = 'sender';
- $recipients = 'recipients';
- $formData = [
- 'sender' => $sender,
- 'recipients' => $recipients,
- ];
- $redirectUrl = 'redirect_url';
-
- /** @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
- $redirectMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Redirect::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->resultFactoryMock->expects($this->once())
- ->method('create')
- ->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT, [])
- ->willReturn($redirectMock);
-
- $this->validatorMock->expects($this->once())
- ->method('validate')
- ->with($this->requestMock)
- ->willReturn(true);
-
- $this->requestMock->expects($this->exactly(2))
- ->method('getParam')
- ->willReturnMap(
- [
- ['id', null, $productId],
- ['cat_id', null, $categoryId],
- ]
- );
-
- /** @var \Magento\Catalog\Api\Data\ProductInterface|\PHPUnit_Framework_MockObject_MockObject $productMock */
- $productMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class)
- ->setMethods(['isVisibleInCatalog', 'setCategory', 'getProductUrl'])
- ->getMockForAbstractClass();
-
- $this->productRepositoryMock->expects($this->once())
- ->method('getById')
- ->with($productId, false, null, false)
- ->willReturn($productMock);
-
- $productMock->expects($this->once())
- ->method('isVisibleInCatalog')
- ->willReturn(true);
-
- $this->categoryRepositoryMock->expects($this->once())
- ->method('get')
- ->with($categoryId, null)
- ->willThrowException(new \Magento\Framework\Exception\NoSuchEntityException(__('No Category Exception.')));
-
- $productMock->expects($this->never())
- ->method('setCategory');
-
- $this->registryMock->expects($this->once())
- ->method('register')
- ->willReturnMap(
- [
- ['product', $productMock, false, null],
- ]
- );
-
- $this->requestMock->expects($this->once())
- ->method('getPostValue')
- ->willReturn($formData);
-
- $this->requestMock->expects($this->exactly(2))
- ->method('getPost')
- ->willReturnMap(
- [
- ['sender', $sender],
- ['recipients', $recipients],
- ]
- );
-
- $this->sendFriendMock->expects($this->once())
- ->method('setSender')
- ->with($sender)
- ->willReturnSelf();
- $this->sendFriendMock->expects($this->once())
- ->method('setRecipients')
- ->with($recipients)
- ->willReturnSelf();
- $this->sendFriendMock->expects($this->once())
- ->method('setProduct')
- ->with($productMock)
- ->willReturnSelf();
- $this->sendFriendMock->expects($this->once())
- ->method('validate')
- ->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('Localized Exception.')));
- $this->sendFriendMock->expects($this->never())
- ->method('send');
-
- $this->messageManagerMock->expects($this->once())
- ->method('addError')
- ->with(__('Localized Exception.'))
- ->willReturnSelf();
-
- $this->catalogSessionMock->expects($this->once())
- ->method('setSendfriendFormData')
- ->with($formData);
-
- $this->urlBuilderMock->expects($this->once())
- ->method('getUrl')
- ->with('sendfriend/product/send', ['_current' => true])
- ->willReturn($redirectUrl);
-
- $this->redirectMock->expects($this->once())
- ->method('error')
- ->with($redirectUrl)
- ->willReturnArgument(0);
-
- $redirectMock->expects($this->once())
- ->method('setUrl')
- ->with($redirectUrl)
- ->willReturnSelf();
-
- $this->assertEquals($redirectMock, $this->model->execute());
- }
-
- /**
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function testExecuteWithException()
- {
- $productId = 11;
- $categoryId = 5;
- $sender = 'sender';
- $recipients = 'recipients';
- $formData = [
- 'sender' => $sender,
- 'recipients' => $recipients,
- ];
- $redirectUrl = 'redirect_url';
-
- /** @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
- $redirectMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Redirect::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->resultFactoryMock->expects($this->once())
- ->method('create')
- ->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT, [])
- ->willReturn($redirectMock);
-
- $this->validatorMock->expects($this->once())
- ->method('validate')
- ->with($this->requestMock)
- ->willReturn(true);
-
- $this->requestMock->expects($this->exactly(2))
- ->method('getParam')
- ->willReturnMap(
- [
- ['id', null, $productId],
- ['cat_id', null, $categoryId],
- ]
- );
-
- /** @var \Magento\Catalog\Api\Data\ProductInterface|\PHPUnit_Framework_MockObject_MockObject $productMock */
- $productMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class)
- ->setMethods(['isVisibleInCatalog', 'setCategory', 'getProductUrl'])
- ->getMockForAbstractClass();
-
- $this->productRepositoryMock->expects($this->once())
- ->method('getById')
- ->with($productId, false, null, false)
- ->willReturn($productMock);
-
- $productMock->expects($this->once())
- ->method('isVisibleInCatalog')
- ->willReturn(true);
-
- $this->categoryRepositoryMock->expects($this->once())
- ->method('get')
- ->with($categoryId, null)
- ->willThrowException(new \Magento\Framework\Exception\NoSuchEntityException(__('No Category Exception.')));
-
- $productMock->expects($this->never())
- ->method('setCategory');
-
- $this->registryMock->expects($this->once())
- ->method('register')
- ->willReturnMap(
- [
- ['product', $productMock, false, null],
- ]
- );
-
- $this->requestMock->expects($this->once())
- ->method('getPostValue')
- ->willReturn($formData);
-
- $this->requestMock->expects($this->exactly(2))
- ->method('getPost')
- ->willReturnMap(
- [
- ['sender', $sender],
- ['recipients', $recipients],
- ]
- );
-
- $this->sendFriendMock->expects($this->once())
- ->method('setSender')
- ->with($sender)
- ->willReturnSelf();
- $this->sendFriendMock->expects($this->once())
- ->method('setRecipients')
- ->with($recipients)
- ->willReturnSelf();
- $this->sendFriendMock->expects($this->once())
- ->method('setProduct')
- ->with($productMock)
- ->willReturnSelf();
- $exception = new \Exception(__('Exception.'));
- $this->sendFriendMock->expects($this->once())
- ->method('validate')
- ->willThrowException($exception);
- $this->sendFriendMock->expects($this->never())
- ->method('send');
-
- $this->messageManagerMock->expects($this->once())
- ->method('addException')
- ->with($exception, __('Some emails were not sent.'))
- ->willReturnSelf();
-
- $this->catalogSessionMock->expects($this->once())
- ->method('setSendfriendFormData')
- ->with($formData);
-
- $this->urlBuilderMock->expects($this->once())
- ->method('getUrl')
- ->with('sendfriend/product/send', ['_current' => true])
- ->willReturn($redirectUrl);
-
- $this->redirectMock->expects($this->once())
- ->method('error')
- ->with($redirectUrl)
- ->willReturnArgument(0);
-
- $redirectMock->expects($this->once())
- ->method('setUrl')
- ->with($redirectUrl)
- ->willReturnSelf();
-
- $this->assertEquals($redirectMock, $this->model->execute());
- }
-
- /**
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function testExecuteWithoutProduct()
- {
- $sender = 'sender';
- $recipients = 'recipients';
- $formData = [
- 'sender' => $sender,
- 'recipients' => $recipients,
- ];
-
- /** @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
- $redirectMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Redirect::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- /** @var \Magento\Framework\Controller\Result\Forward|\PHPUnit_Framework_MockObject_MockObject $forwardMock */
- $forwardMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Forward::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->resultFactoryMock->expects($this->exactly(2))
- ->method('create')
- ->willReturnMap(
- [
- [\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT, [], $redirectMock],
- [\Magento\Framework\Controller\ResultFactory::TYPE_FORWARD, [], $forwardMock],
- ]
- );
-
- $this->validatorMock->expects($this->once())
- ->method('validate')
- ->with($this->requestMock)
- ->willReturn(true);
-
- $this->requestMock->expects($this->once())
- ->method('getParam')
- ->willReturnMap(
- [
- ['id', null, null],
- ]
- );
-
- $this->requestMock->expects($this->once())
- ->method('getPostValue')
- ->willReturn($formData);
-
- $forwardMock->expects($this->once())
- ->method('forward')
- ->with('noroute')
- ->willReturnSelf();
-
- $this->assertEquals($forwardMock, $this->model->execute());
- }
-
- /**
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function testExecuteWithoutData()
- {
- $productId = 11;
- $formData = '';
-
- /** @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
- $redirectMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Redirect::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- /** @var \Magento\Framework\Controller\Result\Forward|\PHPUnit_Framework_MockObject_MockObject $forwardMock */
- $forwardMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Forward::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->resultFactoryMock->expects($this->exactly(2))
- ->method('create')
- ->willReturnMap(
- [
- [\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT, [], $redirectMock],
- [\Magento\Framework\Controller\ResultFactory::TYPE_FORWARD, [], $forwardMock],
- ]
- );
-
- $this->validatorMock->expects($this->once())
- ->method('validate')
- ->with($this->requestMock)
- ->willReturn(true);
-
- $this->requestMock->expects($this->once())
- ->method('getParam')
- ->willReturnMap(
- [
- ['id', null, $productId],
- ]
- );
-
- /** @var \Magento\Catalog\Api\Data\ProductInterface|\PHPUnit_Framework_MockObject_MockObject $productMock */
- $productMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class)
- ->setMethods(['isVisibleInCatalog', 'setCategory', 'getProductUrl'])
- ->getMockForAbstractClass();
-
- $this->productRepositoryMock->expects($this->once())
- ->method('getById')
- ->with($productId, false, null, false)
- ->willReturn($productMock);
-
- $productMock->expects($this->once())
- ->method('isVisibleInCatalog')
- ->willReturn(true);
-
- $this->registryMock->expects($this->once())
- ->method('register')
- ->willReturnMap(
- [
- ['product', $productMock, false, null],
- ]
- );
-
- $this->requestMock->expects($this->once())
- ->method('getPostValue')
- ->willReturn($formData);
-
- $forwardMock->expects($this->once())
- ->method('forward')
- ->with('noroute')
- ->willReturnSelf();
-
- $this->assertEquals($forwardMock, $this->model->execute());
- }
-
- public function testExecuteWithoutFormKey()
- {
- /** @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
- $redirectMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Redirect::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->resultFactoryMock->expects($this->once())
- ->method('create')
- ->willReturnMap(
- [
- [\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT, [], $redirectMock],
- ]
- );
-
- $this->validatorMock->expects($this->once())
- ->method('validate')
- ->with($this->requestMock)
- ->willReturn(false);
-
- $redirectMock->expects($this->once())
- ->method('setPath')
- ->with('sendfriend/product/send', ['_current' => true])
- ->willReturnSelf();
-
- $this->assertEquals($redirectMock, $this->model->execute());
- }
-}
diff --git a/app/code/Magento/SendFriend/composer.json b/app/code/Magento/SendFriend/composer.json
index 30aecf13c3588..932093004cf7a 100644
--- a/app/code/Magento/SendFriend/composer.json
+++ b/app/code/Magento/SendFriend/composer.json
@@ -9,7 +9,9 @@
"magento/framework": "*",
"magento/module-catalog": "*",
"magento/module-customer": "*",
- "magento/module-store": "*"
+ "magento/module-store": "*",
+ "magento/module-captcha": "*",
+ "magento/module-authorization": "*"
},
"type": "magento2-module",
"license": [
diff --git a/app/code/Magento/SendFriend/etc/config.xml b/app/code/Magento/SendFriend/etc/config.xml
index 9fa005dcd2fd4..d65e5a4a073dd 100644
--- a/app/code/Magento/SendFriend/etc/config.xml
+++ b/app/code/Magento/SendFriend/etc/config.xml
@@ -17,5 +17,21 @@
0
+
+
+
+
+ Send To Friend Form
+
+
+
+
+
+
+
+ 1
+
+
+
diff --git a/app/code/Magento/SendFriend/etc/module.xml b/app/code/Magento/SendFriend/etc/module.xml
index 01c267b3c4fcb..7876ef88618c2 100644
--- a/app/code/Magento/SendFriend/etc/module.xml
+++ b/app/code/Magento/SendFriend/etc/module.xml
@@ -10,6 +10,7 @@
+
diff --git a/app/code/Magento/SendFriend/view/frontend/layout/sendfriend_product_send.xml b/app/code/Magento/SendFriend/view/frontend/layout/sendfriend_product_send.xml
index 8065b7e236132..4d6f3d8c628b2 100644
--- a/app/code/Magento/SendFriend/view/frontend/layout/sendfriend_product_send.xml
+++ b/app/code/Magento/SendFriend/view/frontend/layout/sendfriend_product_send.xml
@@ -13,7 +13,7 @@
-
+
diff --git a/app/code/Magento/SendFriend/view/frontend/templates/send.phtml b/app/code/Magento/SendFriend/view/frontend/templates/send.phtml
index 4922a9f365ced..3e00353a9157d 100644
--- a/app/code/Magento/SendFriend/view/frontend/templates/send.phtml
+++ b/app/code/Magento/SendFriend/view/frontend/templates/send.phtml
@@ -108,6 +108,7 @@
= $block->getChildHtml('form_additional_info') ?>
+ = $block->getChildHtml('captcha'); ?>