Skip to content

Commit 1c55514

Browse files
author
Bomko, Alex(abomko)
committed
Merge pull request #555 from magento-tango/MAGETWO-52010
[Tango] Bug fixes
2 parents c3199e7 + ad9ab40 commit 1c55514

File tree

30 files changed

+910
-403
lines changed

30 files changed

+910
-403
lines changed

app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/StockData.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public function __construct(LocatorInterface $locator)
2727
$this->locator = $locator;
2828
}
2929

30-
3130
/**
3231
* {@inheritdoc}
3332
*/
@@ -60,7 +59,6 @@ public function modifyMeta(array $meta)
6059
'is_qty_decimal' => $config,
6160
'is_decimal_divided' => $config,
6261
'container_backorders' => $config,
63-
'container_deferred_stock_update' => $config,
6462
'container_notify_stock_qty' => $config,
6563
],
6664
],

app/code/Magento/Captcha/Observer/CheckContactUsFormObserver.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace Magento\Captcha\Observer;
77

88
use Magento\Framework\Event\ObserverInterface;
9+
use Magento\Framework\App\Request\DataPersistorInterface;
10+
use Magento\Framework\App\ObjectManager;
911

1012
class CheckContactUsFormObserver implements ObserverInterface
1113
{
@@ -34,6 +36,11 @@ class CheckContactUsFormObserver implements ObserverInterface
3436
*/
3537
protected $captchaStringResolver;
3638

39+
/**
40+
* @var DataPersistorInterface
41+
*/
42+
private $dataPersistor;
43+
3744
/**
3845
* @param \Magento\Captcha\Helper\Data $helper
3946
* @param \Magento\Framework\App\ActionFlag $actionFlag
@@ -70,9 +77,25 @@ public function execute(\Magento\Framework\Event\Observer $observer)
7077
$controller = $observer->getControllerAction();
7178
if (!$captcha->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) {
7279
$this->messageManager->addError(__('Incorrect CAPTCHA.'));
80+
$this->getDataPersistor()->set($formId, $controller->getRequest()->getPostValue());
7381
$this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
7482
$this->redirect->redirect($controller->getResponse(), 'contact/index/index');
7583
}
7684
}
7785
}
86+
87+
/**
88+
* Get Data Persistor
89+
*
90+
* @return DataPersistorInterface
91+
*/
92+
private function getDataPersistor()
93+
{
94+
if ($this->dataPersistor === null) {
95+
$this->dataPersistor = ObjectManager::getInstance()
96+
->get(DataPersistorInterface::class);
97+
}
98+
99+
return $this->dataPersistor;
100+
}
78101
}

app/code/Magento/Captcha/Test/Unit/Observer/CheckContactUsFormObserverTest.php

Lines changed: 100 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -13,91 +13,98 @@ class CheckContactUsFormObserverTest extends \PHPUnit_Framework_TestCase
1313
protected $checkContactUsFormObserver;
1414

1515
/**
16-
* @var \PHPUnit_Framework_MockObject_MockObject
16+
* @var \Magento\Captcha\Helper\Data|\PHPUnit_Framework_MockObject_MockObject
1717
*/
18-
protected $_helper;
18+
protected $helperMock;
1919

2020
/**
21-
* @var \PHPUnit_Framework_MockObject_MockObject
21+
* @var \Magento\Framework\App\ActionFlag|\PHPUnit_Framework_MockObject_MockObject
2222
*/
23-
protected $_actionFlag;
23+
protected $actionFlagMock;
2424

2525
/*
26-
* @var \PHPUnit_Framework_MockObject_MockObject
26+
* @var \Magento\Framework\Message\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
2727
*/
28-
protected $_messageManager;
28+
protected $messageManagerMock;
2929

3030
/**
31-
* @var \PHPUnit_Framework_MockObject_MockObject
31+
* @var \Magento\Framework\App\Response\RedirectInterface|\PHPUnit_Framework_MockObject_MockObject
3232
*/
33-
protected $redirect;
33+
protected $redirectMock;
3434

3535
/**
3636
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
3737
*/
38-
protected $_objectManager;
38+
protected $objectManagerHelper;
3939

4040
/**
41-
* @var \Magento\Captcha\Observer\CaptchaStringResolver
41+
* @var \Magento\Captcha\Observer\CaptchaStringResolver|\PHPUnit_Framework_MockObject_MockObject
4242
*/
43-
protected $captchaStringResolver;
43+
protected $captchaStringResolverMock;
4444

4545
/**
46-
* @var \PHPUnit_Framework_MockObject_MockObject
46+
* @var \Magento\Framework\Session\SessionManager|\PHPUnit_Framework_MockObject_MockObject
4747
*/
48-
protected $_session;
48+
protected $sessionMock;
4949

5050
/**
51-
* @var \PHPUnit_Framework_MockObject_MockObject
51+
* @var \Magento\Captcha\Model\DefaultModel|\PHPUnit_Framework_MockObject_MockObject
5252
*/
53-
protected $_captcha;
53+
protected $captchaMock;
54+
55+
/**
56+
* @var \Magento\Framework\App\Request\DataPersistorInterface|\PHPUnit_Framework_MockObject_MockObject
57+
*/
58+
protected $dataPersistorMock;
5459

5560
protected function setUp()
5661
{
57-
$this->_objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
62+
$this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
5863

59-
$this->_helper = $this->getMock('Magento\Captcha\Helper\Data', [], [], '', false);
60-
61-
$this->_actionFlag = $this->getMock('Magento\Framework\App\ActionFlag', [], [], '', false);
62-
63-
$this->_messageManager = $this->getMock(
64+
$this->helperMock = $this->getMock('Magento\Captcha\Helper\Data', [], [], '', false);
65+
$this->actionFlagMock = $this->getMock('Magento\Framework\App\ActionFlag', [], [], '', false);
66+
$this->messageManagerMock = $this->getMock(
6467
'\Magento\Framework\Message\ManagerInterface',
6568
[],
6669
[],
6770
'',
6871
false
6972
);
70-
71-
$this->redirect = $this->getMock(
73+
$this->redirectMock = $this->getMock(
7274
'\Magento\Framework\App\Response\RedirectInterface',
7375
[],
7476
[],
7577
'',
7678
false
7779
);
78-
79-
$this->captchaStringResolver = $this->getMock(
80+
$this->captchaStringResolverMock = $this->getMock(
8081
'\Magento\Captcha\Observer\CaptchaStringResolver',
8182
[],
8283
[],
8384
'',
8485
false
8586
);
87+
$this->sessionMock = $this->getMock('Magento\Framework\Session\SessionManager', [], [], '', false);
88+
$this->dataPersistorMock = $this->getMockBuilder('Magento\Framework\App\Request\DataPersistorInterface')
89+
->getMockForAbstractClass();
8690

87-
$this->_session = $this->getMock('Magento\Framework\Session\SessionManager', [], [], '', false);
88-
89-
$this->checkContactUsFormObserver = $this->_objectManager->getObject(
91+
$this->checkContactUsFormObserver = $this->objectManagerHelper->getObject(
9092
'Magento\Captcha\Observer\CheckContactUsFormObserver',
9193
[
92-
'helper' => $this->_helper,
93-
'actionFlag' => $this->_actionFlag,
94-
'messageManager' => $this->_messageManager,
95-
'redirect' => $this->redirect,
96-
'captchaStringResolver' => $this->captchaStringResolver
94+
'helper' => $this->helperMock,
95+
'actionFlag' => $this->actionFlagMock,
96+
'messageManager' => $this->messageManagerMock,
97+
'redirect' => $this->redirectMock,
98+
'captchaStringResolver' => $this->captchaStringResolverMock
9799
]
98100
);
101+
$this->objectManagerHelper->setBackwardCompatibleProperty(
102+
$this->checkContactUsFormObserver,
103+
'dataPersistor',
104+
$this->dataPersistorMock
105+
);
99106

100-
$this->_captcha = $this->getMock('Magento\Captcha\Model\DefaultModel', [], [], '', false);
107+
$this->captchaMock = $this->getMock('Magento\Captcha\Model\DefaultModel', [], [], '', false);
101108
}
102109

103110
public function testCheckContactUsFormWhenCaptchaIsRequiredAndValid()
@@ -107,47 +114,24 @@ public function testCheckContactUsFormWhenCaptchaIsRequiredAndValid()
107114

108115
$controller = $this->getMock('Magento\Framework\App\Action\Action', [], [], '', false);
109116
$request = $this->getMock('Magento\Framework\App\Request\Http', [], [], '', false);
110-
$request->expects(
111-
$this->any()
112-
)->method(
113-
'getPost'
114-
)->with(
115-
\Magento\Captcha\Helper\Data::INPUT_NAME_FIELD_VALUE,
116-
null
117-
)->will(
118-
$this->returnValue([$formId => $captchaValue])
119-
);
120-
$controller->expects($this->any())->method('getRequest')->will($this->returnValue($request));
121-
$this->_captcha->expects($this->any())->method('isRequired')->will($this->returnValue(true));
122-
$this->_captcha->expects(
123-
$this->once()
124-
)->method(
125-
'isCorrect'
126-
)->with(
127-
$captchaValue
128-
)->will(
129-
$this->returnValue(true)
130-
);
131-
$this->captchaStringResolver->expects(
132-
$this->once()
133-
)->method(
134-
'resolve'
135-
)->with(
136-
$request,
137-
$formId
138-
)->will(
139-
$this->returnValue($captchaValue)
140-
);
141-
$this->_helper->expects(
142-
$this->any()
143-
)->method(
144-
'getCaptcha'
145-
)->with(
146-
$formId
147-
)->will(
148-
$this->returnValue($this->_captcha)
149-
);
150-
$this->_session->expects($this->never())->method('addError');
117+
$request->expects($this->any())
118+
->method('getPost')
119+
->with(\Magento\Captcha\Helper\Data::INPUT_NAME_FIELD_VALUE, null)
120+
->willReturn([$formId => $captchaValue]);
121+
$controller->expects($this->any())->method('getRequest')->willReturn($request);
122+
$this->captchaMock->expects($this->any())->method('isRequired')->willReturn(true);
123+
$this->captchaMock->expects($this->once())
124+
->method('isCorrect')
125+
->with($captchaValue)
126+
->willReturn(true);
127+
$this->captchaStringResolverMock->expects($this->once())
128+
->method('resolve')
129+
->with($request, $formId)
130+
->willReturn($captchaValue);
131+
$this->helperMock->expects($this->any())
132+
->method('getCaptcha')
133+
->with($formId)->willReturn($this->captchaMock);
134+
$this->sessionMock->expects($this->never())->method('addError');
151135

152136
$this->checkContactUsFormObserver->execute(
153137
new \Magento\Framework\Event\Observer(['controller_action' => $controller])
@@ -161,74 +145,46 @@ public function testCheckContactUsFormRedirectsCustomerWithWarningMessageWhenCap
161145
$warningMessage = 'Incorrect CAPTCHA.';
162146
$redirectRoutePath = 'contact/index/index';
163147
$redirectUrl = 'http://magento.com/contacts/';
148+
$postData = ['name' => 'Some Name'];
164149

165150
$request = $this->getMock('Magento\Framework\App\Request\Http', [], [], '', false);
166151
$response = $this->getMock('Magento\Framework\App\Response\Http', [], [], '', false);
167-
$request->expects(
168-
$this->any()
169-
)->method(
170-
'getPost'
171-
)->with(
172-
\Magento\Captcha\Helper\Data::INPUT_NAME_FIELD_VALUE,
173-
null
174-
)->will(
175-
$this->returnValue([$formId => $captchaValue])
176-
);
177-
178-
$this->redirect->expects(
179-
$this->once()
180-
)->method(
181-
'redirect'
182-
)->with(
183-
$response,
184-
$redirectRoutePath,
185-
[]
186-
)->will(
187-
$this->returnValue($redirectUrl)
188-
);
152+
$request->expects($this->any())
153+
->method('getPost')
154+
->with(\Magento\Captcha\Helper\Data::INPUT_NAME_FIELD_VALUE, null)
155+
->willReturn([$formId => $captchaValue]);
156+
$request->expects($this->once())
157+
->method('getPostValue')
158+
->willReturn($postData);
159+
160+
$this->redirectMock->expects($this->once())
161+
->method('redirect')
162+
->with($response, $redirectRoutePath, [])
163+
->willReturn($redirectUrl);
189164

190165
$controller = $this->getMock('Magento\Framework\App\Action\Action', [], [], '', false);
191-
$controller->expects($this->any())->method('getRequest')->will($this->returnValue($request));
192-
$controller->expects($this->any())->method('getResponse')->will($this->returnValue($response));
193-
$this->_captcha->expects($this->any())->method('isRequired')->will($this->returnValue(true));
194-
$this->_captcha->expects(
195-
$this->once()
196-
)->method(
197-
'isCorrect'
198-
)->with(
199-
$captchaValue
200-
)->will(
201-
$this->returnValue(false)
202-
);
203-
$this->captchaStringResolver->expects(
204-
$this->once()
205-
)->method(
206-
'resolve'
207-
)->with(
208-
$request,
209-
$formId
210-
)->will(
211-
$this->returnValue($captchaValue)
212-
);
213-
$this->_helper->expects(
214-
$this->any()
215-
)->method(
216-
'getCaptcha'
217-
)->with(
218-
$formId
219-
)->will(
220-
$this->returnValue($this->_captcha)
221-
);
222-
$this->_messageManager->expects($this->once())->method('addError')->with($warningMessage);
223-
$this->_actionFlag->expects(
224-
$this->once()
225-
)->method(
226-
'set'
227-
)->with(
228-
'',
229-
\Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH,
230-
true
231-
);
166+
$controller->expects($this->any())->method('getRequest')->willReturn($request);
167+
$controller->expects($this->any())->method('getResponse')->willReturn($response);
168+
$this->captchaMock->expects($this->any())->method('isRequired')->willReturn(true);
169+
$this->captchaMock->expects($this->once())
170+
->method('isCorrect')
171+
->with($captchaValue)
172+
->willReturn(false);
173+
$this->captchaStringResolverMock->expects($this->once())
174+
->method('resolve')
175+
->with($request, $formId)
176+
->willReturn($captchaValue);
177+
$this->helperMock->expects($this->any())
178+
->method('getCaptcha')
179+
->with($formId)
180+
->willReturn($this->captchaMock);
181+
$this->messageManagerMock->expects($this->once())->method('addError')->with($warningMessage);
182+
$this->actionFlagMock->expects($this->once())
183+
->method('set')
184+
->with('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
185+
$this->dataPersistorMock->expects($this->once())
186+
->method('set')
187+
->with($formId, $postData);
232188

233189
$this->checkContactUsFormObserver->execute(
234190
new \Magento\Framework\Event\Observer(['controller_action' => $controller])
@@ -237,17 +193,12 @@ public function testCheckContactUsFormRedirectsCustomerWithWarningMessageWhenCap
237193

238194
public function testCheckContactUsFormDoesNotCheckCaptchaWhenItIsNotRequired()
239195
{
240-
$this->_helper->expects(
241-
$this->any()
242-
)->method(
243-
'getCaptcha'
244-
)->with(
245-
'contact_us'
246-
)->will(
247-
$this->returnValue($this->_captcha)
248-
);
249-
$this->_captcha->expects($this->any())->method('isRequired')->will($this->returnValue(false));
250-
$this->_captcha->expects($this->never())->method('isCorrect');
196+
$this->helperMock->expects($this->any())
197+
->method('getCaptcha')
198+
->with('contact_us')
199+
->willReturn($this->captchaMock);
200+
$this->captchaMock->expects($this->any())->method('isRequired')->willReturn(false);
201+
$this->captchaMock->expects($this->never())->method('isCorrect');
251202

252203
$this->checkContactUsFormObserver->execute(new \Magento\Framework\Event\Observer());
253204
}

0 commit comments

Comments
 (0)