Skip to content

Commit

Permalink
Merge branch '2.3-develop' into MAGETWO-70803
Browse files Browse the repository at this point in the history
  • Loading branch information
Aliaksei Yakimovich2 committed Sep 16, 2019
2 parents f969941 + de0fc3b commit d4bb503
Show file tree
Hide file tree
Showing 72 changed files with 2,142 additions and 703 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminAssociateBundleProductToWebsitesTest">
<annotations>
<features value="Bundle"/>
<stories value="Create/Edit bundle product in Admin"/>
<title value="Admin should be able to associate bundle product to websites"/>
<description value="Admin should be able to associate bundle product to websites"/>
<testCaseId value="MC-3344"/>
<severity value="CRITICAL"/>
<group value="bundle"/>
<group value="catalog"/>
</annotations>
<before>
<!-- Configure Store URLs -->
<magentoCLI command="config:set {{StorefrontEnableAddStoreCodeToUrls.path}} {{StorefrontEnableAddStoreCodeToUrls.value}}" stepKey="setAddStoreCodeToUrlsToYes"/>

<!-- Create category -->
<createData entity="SimpleSubCategory" stepKey="createCategory"/>

<!-- Create Simple product -->
<createData entity="SimpleProduct2" stepKey="createSimpleProduct"/>

<!-- Create Bundle product -->
<createData entity="ApiBundleProductPriceViewRange" stepKey="createBundleProduct">
<requiredEntity createDataKey="createCategory"/>
</createData>
<createData entity="DropDownBundleOption" stepKey="bundleOption">
<requiredEntity createDataKey="createBundleProduct"/>
</createData>
<createData entity="ApiBundleLink" stepKey="createNewBundleLink">
<requiredEntity createDataKey="createBundleProduct"/>
<requiredEntity createDataKey="bundleOption"/>
<requiredEntity createDataKey="createSimpleProduct"/>
</createData>

<!-- Reindex -->
<magentoCLI command="indexer:reindex" stepKey="reindex"/>

<!-- Login as admin -->
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>

<!--Create website-->
<actionGroup ref="AdminCreateWebsiteActionGroup" stepKey="createSecondWebsite">
<argument name="newWebsiteName" value="{{secondCustomWebsite.name}}"/>
<argument name="websiteCode" value="{{secondCustomWebsite.code}}"/>
</actionGroup>
<!-- Create second store -->
<actionGroup ref="AdminCreateNewStoreGroupActionGroup" stepKey="createSecondStoreGroup">
<argument name="website" value="{{secondCustomWebsite.name}}"/>
<argument name="storeGroupName" value="{{SecondStoreGroupUnique.name}}"/>
<argument name="storeGroupCode" value="{{SecondStoreGroupUnique.code}}"/>
</actionGroup>
<!-- Create second store view -->
<actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createSecondStoreView">
<argument name="StoreGroup" value="SecondStoreGroupUnique"/>
<argument name="customStore" value="SecondStoreUnique"/>
</actionGroup>
</before>
<after>
<!-- Disabled Store URLs -->
<magentoCLI command="config:set {{StorefrontDisableAddStoreCodeToUrls.path}} {{StorefrontDisableAddStoreCodeToUrls.value}}" stepKey="setAddStoreCodeToUrlsToNo"/>

<!-- Delete simple product -->
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
<!-- Delete bundle product -->
<deleteData createDataKey="createBundleProduct" stepKey="deleteBundleProduct"/>

<!-- Delete second website -->
<actionGroup ref="AdminDeleteWebsiteActionGroup" stepKey="deleteWebsite">
<argument name="websiteName" value="{{secondCustomWebsite.name}}"/>
</actionGroup>

<actionGroup ref="NavigateToAndResetProductGridToDefaultView" stepKey="resetProductGridFilter"/>

<!-- Admin logout -->
<actionGroup ref="logout" stepKey="adminLogout"/>
</after>

<!-- Open product page and assign grouped project to second website -->
<actionGroup ref="filterAndSelectProduct" stepKey="openAdminProductPage">
<argument name="productSku" value="$$createBundleProduct.sku$$"/>
</actionGroup>
<actionGroup ref="AdminAssignProductInWebsiteActionGroup" stepKey="assignProductToSecondWebsite">
<argument name="website" value="{{secondCustomWebsite.name}}"/>
</actionGroup>
<actionGroup ref="AdminUnassignProductInWebsiteActionGroup" stepKey="unassignProductFromDefaultWebsite">
<argument name="website" value="{{_defaultWebsite.name}}"/>
</actionGroup>
<actionGroup ref="saveProductForm" stepKey="saveGroupedProduct"/>

<!-- Assert product is assigned to Second website -->
<actionGroup ref="AssertProductIsAssignedToWebsite" stepKey="seeCustomWebsiteIsChecked">
<argument name="website" value="{{secondCustomWebsite.name}}"/>
</actionGroup>

<!-- Assert product is not assigned to Main website -->
<actionGroup ref="AssertProductIsNotAssignedToWebsite" stepKey="seeMainWebsiteIsNotChecked">
<argument name="website" value="{{_defaultWebsite.name}}"/>
</actionGroup>

<!-- Go to frontend and open product on Main website -->
<actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="openProductPage">
<argument name="productUrl" value="$$createBundleProduct.custom_attributes[url_key]$$"/>
</actionGroup>

<!-- Assert 404 page -->
<actionGroup ref="StorefrontAssertPageNotFoundErrorOnProductDetailPageActionGroup" stepKey="assertPageNotFoundError">
<argument name="product" value="$$createBundleProduct$$"/>
</actionGroup>

<!-- Assert product is present at Second website -->
<actionGroup ref="StorefrontOpenProductPageUsingStoreCodeInUrlActionGroup" stepKey="openProductPageUsingStoreCodeInUrl">
<argument name="product" value="$$createBundleProduct$$"/>
<argument name="storeView" value="SecondStoreUnique"/>
</actionGroup>
</test>
</tests>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\Framework\App\ObjectManager;

/**
* Class CheckContactUsFormObserver
*/
class CheckContactUsFormObserver implements ObserverInterface
{
/**
Expand Down Expand Up @@ -76,7 +79,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
/** @var \Magento\Framework\App\Action\Action $controller */
$controller = $observer->getControllerAction();
if (!$captcha->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) {
$this->messageManager->addError(__('Incorrect CAPTCHA.'));
$this->messageManager->addErrorMessage(__('Incorrect CAPTCHA.'));
$this->getDataPersistor()->set($formId, $controller->getRequest()->getPostValue());
$this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->redirect->redirect($controller->getResponse(), 'contact/index/index');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

use Magento\Framework\Event\ObserverInterface;

/**
* Class CheckForgotpasswordObserver
*/
class CheckForgotpasswordObserver implements ObserverInterface
{
/**
Expand Down Expand Up @@ -69,7 +72,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
/** @var \Magento\Framework\App\Action\Action $controller */
$controller = $observer->getControllerAction();
if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) {
$this->messageManager->addError(__('Incorrect CAPTCHA'));
$this->messageManager->addErrorMessage(__('Incorrect CAPTCHA'));
$this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->redirect->redirect($controller->getResponse(), '*/*/forgotpassword');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

use Magento\Framework\Event\ObserverInterface;

/**
* Class CheckUserCreateObserver
*
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
*/
class CheckUserCreateObserver implements ObserverInterface
{
/**
Expand Down Expand Up @@ -86,7 +91,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
/** @var \Magento\Framework\App\Action\Action $controller */
$controller = $observer->getControllerAction();
if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) {
$this->messageManager->addError(__('Incorrect CAPTCHA'));
$this->messageManager->addErrorMessage(__('Incorrect CAPTCHA'));
$this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->_session->setCustomerFormData($controller->getRequest()->getPostValue());
$url = $this->_urlManager->getUrl('*/*/create', ['_nosecret' => true]);
Expand Down
14 changes: 7 additions & 7 deletions app/code/Magento/Captcha/Observer/CheckUserEditObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
use Magento\Framework\App\Config\ScopeConfigInterface;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* Class CheckUserEditObserver
*
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
*/
class CheckUserEditObserver implements ObserverInterface
{
/**
* Form ID
*/
const FORM_ID = 'user_edit';

/**
Expand Down Expand Up @@ -96,7 +95,8 @@ public function __construct(
* Check Captcha On Forgot Password Page
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
* @return $this|void
* @throws \Magento\Framework\Exception\SessionException
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
Expand All @@ -119,9 +119,9 @@ public function execute(\Magento\Framework\Event\Observer $observer)
'The account is locked. Please wait and try again or contact %1.',
$this->scopeConfig->getValue('contact/email/recipient_email')
);
$this->messageManager->addError($message);
$this->messageManager->addErrorMessage($message);
}
$this->messageManager->addError(__('Incorrect CAPTCHA'));
$this->messageManager->addErrorMessage(__('Incorrect CAPTCHA'));
$this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->redirect->redirect($controller->getResponse(), '*/*/edit');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

use Magento\Framework\Event\ObserverInterface;

/**
* Class CheckUserForgotPasswordBackendObserver
*
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
*/
class CheckUserForgotPasswordBackendObserver implements ObserverInterface
{
/**
Expand Down Expand Up @@ -76,7 +81,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
) {
$this->_session->setEmail((string)$controller->getRequest()->getPost('email'));
$this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->messageManager->addError(__('Incorrect CAPTCHA'));
$this->messageManager->addErrorMessage(__('Incorrect CAPTCHA'));
$controller->getResponse()->setRedirect(
$controller->getUrl('*/*/forgotpassword', ['_nosecret' => true])
);
Expand Down
10 changes: 6 additions & 4 deletions app/code/Magento/Captcha/Observer/CheckUserLoginObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

namespace Magento\Captcha\Observer;

use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Model\AuthenticationInterface;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Customer\Api\CustomerRepositoryInterface;

/**
* Check captcha on user login page observer.
Expand Down Expand Up @@ -64,6 +64,8 @@ class CheckUserLoginObserver implements ObserverInterface
protected $authentication;

/**
* CheckUserLoginObserver constructor.
*
* @param \Magento\Captcha\Helper\Data $helper
* @param \Magento\Framework\App\ActionFlag $actionFlag
* @param \Magento\Framework\Message\ManagerInterface $messageManager
Expand Down Expand Up @@ -125,8 +127,7 @@ private function getAuthentication()
* Check captcha on user login page
*
* @param \Magento\Framework\Event\Observer $observer
* @throws NoSuchEntityException
* @return $this
* @return $this|void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
Expand All @@ -143,10 +144,11 @@ public function execute(\Magento\Framework\Event\Observer $observer)
try {
$customer = $this->getCustomerRepository()->get($login);
$this->getAuthentication()->processAuthenticationFailure($customer->getId());
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
} catch (NoSuchEntityException $e) {
//do nothing as customer existence is validated later in authenticate method
}
$this->messageManager->addError(__('Incorrect CAPTCHA'));
$this->messageManager->addErrorMessage(__('Incorrect CAPTCHA'));
$this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->_session->setUsername($login);
$beforeUrl = $this->_session->getBeforeAuthUrl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ protected function setUp()
$this->messageManagerMock = $this->createMock(\Magento\Framework\Message\ManagerInterface::class);
$this->redirectMock = $this->createMock(\Magento\Framework\App\Response\RedirectInterface::class);
$this->captchaStringResolverMock = $this->createMock(\Magento\Captcha\Observer\CaptchaStringResolver::class);
$this->sessionMock = $this->createPartialMock(\Magento\Framework\Session\SessionManager::class, ['addError']);
$this->sessionMock = $this->createPartialMock(
\Magento\Framework\Session\SessionManager::class,
['addErrorMessage']
);
$this->dataPersistorMock = $this->getMockBuilder(\Magento\Framework\App\Request\DataPersistorInterface::class)
->getMockForAbstractClass();

Expand Down Expand Up @@ -116,7 +119,7 @@ public function testCheckContactUsFormWhenCaptchaIsRequiredAndValid()
$this->helperMock->expects($this->any())
->method('getCaptcha')
->with($formId)->willReturn($this->captchaMock);
$this->sessionMock->expects($this->never())->method('addError');
$this->sessionMock->expects($this->never())->method('addErrorMessage');

$this->checkContactUsFormObserver->execute(
new \Magento\Framework\Event\Observer(['controller_action' => $controller])
Expand Down Expand Up @@ -163,7 +166,7 @@ public function testCheckContactUsFormRedirectsCustomerWithWarningMessageWhenCap
->method('getCaptcha')
->with($formId)
->willReturn($this->captchaMock);
$this->messageManagerMock->expects($this->once())->method('addError')->with($warningMessage);
$this->messageManagerMock->expects($this->once())->method('addErrorMessage')->with($warningMessage);
$this->actionFlagMock->expects($this->once())
->method('set')
->with('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function testCheckForgotpasswordRedirects()
)->will(
$this->returnValue($this->_captcha)
);
$this->_messageManager->expects($this->once())->method('addError')->with($warningMessage);
$this->_messageManager->expects($this->once())->method('addErrorMessage')->with($warningMessage);
$this->_actionFlag->expects(
$this->once()
)->method(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function testCheckUserCreateRedirectsError()
)->will(
$this->returnValue($this->_captcha)
);
$this->_messageManager->expects($this->once())->method('addError')->with($warningMessage);
$this->_messageManager->expects($this->once())->method('addErrorMessage')->with($warningMessage);
$this->_actionFlag->expects(
$this->once()
)->method(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function testExecute()

$message = __('The account is locked. Please wait and try again or contact %1.', $email);
$this->messageManagerMock->expects($this->exactly(2))
->method('addError')
->method('addErrorMessage')
->withConsecutive([$message], [__('Incorrect CAPTCHA')]);

$this->actionFlagMock->expects($this->once())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function testExecute()
->with($customerId);

$this->messageManagerMock->expects($this->once())
->method('addError')
->method('addErrorMessage')
->with(__('Incorrect CAPTCHA'));

$this->actionFlagMock->expects($this->once())
Expand Down
Loading

0 comments on commit d4bb503

Please sign in to comment.