15
15
use Magento \Framework \Exception \InputException ;
16
16
use Magento \Framework \Stdlib \Cookie \FailureToSendException ;
17
17
use Magento \Framework \Stdlib \Cookie \CookieSizeLimitReachedException ;
18
+ use Magento \Framework \Phrase ;
19
+ use Magento \Framework \HTTP \Header as HttpHeader ;
20
+ use Psr \Log \LoggerInterface ;
18
21
// @codingStandardsIgnoreEnd
19
22
20
23
/**
@@ -95,6 +98,16 @@ class PhpCookieManagerTest extends \PHPUnit_Framework_TestCase
95
98
*/
96
99
protected $ readerMock ;
97
100
101
+ /**
102
+ * @var LoggerInterface | \PHPUnit_Framework_MockObject_MockObject
103
+ */
104
+ protected $ loggerMock ;
105
+
106
+ /**
107
+ * @var HttpHeader | \PHPUnit_Framework_MockObject_MockObject
108
+ */
109
+ protected $ httpHeaderMock ;
110
+
98
111
/**
99
112
* @var array
100
113
*/
@@ -113,11 +126,18 @@ protected function setUp()
113
126
->disableOriginalConstructor ()
114
127
->getMock ();
115
128
$ this ->readerMock = $ this ->getMock (\Magento \Framework \Stdlib \Cookie \CookieReaderInterface::class);
129
+ $ this ->loggerMock = $ this ->getMockBuilder (LoggerInterface::class)
130
+ ->getMockForAbstractClass ();
131
+ $ this ->httpHeaderMock = $ this ->getMockBuilder (HttpHeader::class)
132
+ ->disableOriginalConstructor ()
133
+ ->getMock ();
116
134
$ this ->cookieManager = $ this ->objectManager ->getObject (
117
135
\Magento \Framework \Stdlib \Cookie \PhpCookieManager::class,
118
136
[
119
137
'scope ' => $ this ->scopeMock ,
120
138
'reader ' => $ this ->readerMock ,
139
+ 'logger ' => $ this ->loggerMock ,
140
+ 'httpHeader ' => $ this ->httpHeaderMock
121
141
]
122
142
);
123
143
@@ -503,11 +523,11 @@ public function testSetTooManyCookies()
503
523
\Magento \Framework \Stdlib \Cookie \PublicCookieMetadata::class
504
524
);
505
525
506
- $ cookieValue = 'some_value ' ;
526
+ $ userAgent = 'some_user_agent ' ;
507
527
508
528
// Set self::MAX_NUM_COOKIES number of cookies in superglobal $_COOKIE.
509
529
for ($ i = count ($ _COOKIE ); $ i < self ::MAX_NUM_COOKIES ; $ i ++) {
510
- $ _COOKIE ['test_cookie_ ' . $ i ] = ' some_value ' ;
530
+ $ _COOKIE ['test_cookie_ ' . $ i ] = self :: COOKIE_VALUE . ' _ ' . $ i ;
511
531
}
512
532
513
533
$ this ->scopeMock ->expects ($ this ->once ())
@@ -517,19 +537,22 @@ public function testSetTooManyCookies()
517
537
$ this ->returnValue ($ publicCookieMetadata )
518
538
);
519
539
520
- try {
521
- $ this ->cookieManager ->setPublicCookie (
522
- self ::MAX_COOKIE_SIZE_TEST_NAME ,
523
- $ cookieValue ,
524
- $ publicCookieMetadata
525
- );
526
- $ this ->fail ('Failed to throw exception of too many cookies. ' );
527
- } catch (CookieSizeLimitReachedException $ e ) {
528
- $ this ->assertEquals (
529
- 'Unable to send the cookie. Maximum number of cookies would be exceeded. ' ,
530
- $ e ->getMessage ()
540
+ $ this ->httpHeaderMock ->expects ($ this ->any ())
541
+ ->method ('getHttpUserAgent ' )
542
+ ->willReturn ($ userAgent );
543
+
544
+ $ this ->loggerMock ->expects ($ this ->once ())
545
+ ->method ('warning ' )
546
+ ->with (
547
+ new Phrase ('Unable to send the cookie. Maximum number of cookies would be exceeded. ' ),
548
+ array_merge ($ _COOKIE , ['user-agent ' => $ userAgent ])
531
549
);
532
- }
550
+
551
+ $ this ->cookieManager ->setPublicCookie (
552
+ self ::MAX_COOKIE_SIZE_TEST_NAME ,
553
+ self ::COOKIE_VALUE ,
554
+ $ publicCookieMetadata
555
+ );
533
556
}
534
557
535
558
/**
0 commit comments