20 private $messageManager;
23 private $interpretationStrategyMock;
26 private $cookieManagerMock;
31 private $serializerMock;
35 $testObjectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
37 $this->messageManager = $this->createMock(\
Magento\Framework\Message\Manager::class);
38 $this->cookieManagerMock = $this->createMock(CookieManagerInterface::class);
39 $this->serializerMock = $this->getMockBuilder(\
Magento\Framework\
Serialize\Serializer\Json::class)
40 ->disableOriginalConstructor()
42 $this->serializerMock->expects($this->any())->method(
'unserialize')->willReturnCallback(
43 function ($serializedData) {
44 return json_decode($serializedData,
true);
47 $this->interpretationStrategyMock = $this->createMock(InterpretationStrategyInterface::class);
48 $this->interpretationStrategyMock->expects($this->any())
56 $request = $testObjectManager->getObject(\
Magento\TestFramework\Request::class);
57 $response = $testObjectManager->getObject(\
Magento\TestFramework\Response::class);
58 $this->_objectManager =
59 $this->createPartialMock(\
Magento\TestFramework\ObjectManager::class, [
'get',
'create']);
60 $this->_objectManager->expects($this->any())
63 $this->returnValueMap(
67 [\
Magento\Framework\Message\Manager::class, $this->messageManager],
68 [CookieManagerInterface::class, $this->cookieManagerMock],
69 [\
Magento\Framework\
Serialize\Serializer\Json::class, $this->serializerMock],
70 [InterpretationStrategyInterface::class, $this->interpretationStrategyMock],
84 if (!$this->_bootstrap) {
85 $this->_bootstrap = $this->createPartialMock(\
Magento\TestFramework\Bootstrap::class, [
'getAllOptions']);
93 $this->assertInstanceOf(\
Magento\TestFramework\Request::class,
$request);
107 $this->
getRequest()->setControllerName(
'noroute');
109 '404 Not Found test <h3>We are sorry, but the page you are looking for cannot be found.</h3>' 116 }
catch (\PHPUnit\Framework\AssertionFailedError $e) {
119 $this->fail(
'Failed response body validation');
140 $setRedirectMethod = new \ReflectionMethod(\
Magento\Framework\
App\
Response\Http::class,
'setRedirect');
141 $setRedirectMethod->invoke($this->
getResponse(),
'http://magentocommerce.com');
143 $this->
assertRedirect($this->equalTo(
'http://magentocommerce.com'));
151 public function testAssertSessionMessagesSuccess(array $expectedMessages, $messageTypeFilter)
153 $this->addSessionMessages();
156 $this->createPartialMock(\PHPUnit\Framework\Constraint\Constraint::class, [
'toString',
'matches']);
160 ->with($expectedMessages)
161 ->will($this->returnValue(
true));
162 $this->assertSessionMessages(
$constraint, $messageTypeFilter);
168 'message warning type filtering' => [
169 [
'some_warning',
'warning_cookie'],
172 'message error type filtering' => [
173 [
'error_one',
'error_two',
'error_cookie'],
176 'message notice type filtering' => [
177 [
'some_notice',
'notice_cookie'],
180 'message success type filtering' => [
181 [
'success!',
'success_cookie'],
189 $this->addSessionMessages();
191 $this->assertSessionMessages(
210 $messagesCollection = new \Magento\Framework\Message\Collection();
211 $this->messageManager->expects($this->any())->method(
'getMessages')
212 ->will($this->returnValue($messagesCollection));
214 $this->assertSessionMessages($this->isEmpty());
217 private function addSessionMessages()
220 $messagesCollection = new \Magento\Framework\Message\Collection();
222 ->addMessage(
new \
Magento\Framework\Message\Warning(
'some_warning'))
223 ->addMessage(
new \
Magento\Framework\Message\Error(
'error_one'))
224 ->addMessage(
new \
Magento\Framework\Message\Error(
'error_two'))
225 ->addMessage(
new \
Magento\Framework\Message\Notice(
'some_notice'))
226 ->addMessage(
new \
Magento\Framework\Message\Success(
'success!'));
227 $this->messageManager->expects($this->any())->method(
'getMessages')
228 ->will($this->returnValue($messagesCollection));
233 'text' =>
'warning_cookie',
237 'text' =>
'notice_cookie',
241 'text' =>
'success_cookie',
245 'text' =>
'error_cookie',
249 $this->cookieManagerMock->expects($this->any())
250 ->method(
'getCookie')
251 ->willReturn(json_encode($cookieMessages));
testAssertRedirectFailure()
testAssertSessionMessagesAll()
assertRedirect(\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)
assertSessionMessagesDataProvider()
testAssertSessionMessagesEmpty()