Beispiel #1
0
 public function testGetCookie()
 {
     $key = "cookieName";
     $default = "defaultValue";
     $this->cookieManager->expects($this->once())->method('getCookie')->with($key, $default);
     $this->request->getCookie($key, $default);
 }
Beispiel #2
0
 public function testGet()
 {
     //Data
     $formKey = 'test_from_key';
     //Verification
     $this->cookieManagerMock->expects($this->once())->method('getCookie')->with(\Magento\Framework\App\PageCache\FormKey::COOKIE_NAME)->will($this->returnValue($formKey));
     $this->assertEquals($formKey, $this->formKey->get());
 }
Beispiel #3
0
 public function testSentCountByCookies()
 {
     $cookieName = 'testCookieName';
     $this->sendfriendDataMock->expects($this->once())->method('getCookieName')->with()->will($this->returnValue($cookieName));
     $this->cookieManagerMock->expects($this->once())->method('getCookie')->with($cookieName);
     $this->cookieManagerMock->expects($this->once())->method('setPublicCookie');
     $sendFriendClass = new \ReflectionClass('Magento\\Sendfriend\\Model\\Sendfriend');
     $method = $sendFriendClass->getMethod('_sentCountByCookies');
     $method->setAccessible(true);
     $method->invokeArgs($this->model, [true]);
 }
Beispiel #4
0
 /**
  * @dataProvider processProvider
  * @param bool $isPost
  */
 public function testProcess($isPost)
 {
     $this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue($isPost));
     if ($isPost) {
         $publicCookieMetadataMock = $this->getMock('Magento\\Framework\\Stdlib\\Cookie\\PublicCookieMetadata');
         $publicCookieMetadataMock->expects($this->once())->method('setPath')->with('/')->will($this->returnSelf());
         $publicCookieMetadataMock->expects($this->once())->method('setDuration')->with(Version::COOKIE_PERIOD)->will($this->returnSelf());
         $this->cookieMetadataFactoryMock->expects($this->once())->method('createPublicCookieMetadata')->with()->will($this->returnValue($publicCookieMetadataMock));
         $this->cookieManagerMock->expects($this->once())->method('setPublicCookie');
     }
     $this->version->process();
 }
Beispiel #5
0
 public function testSendVaryEmptyData()
 {
     $expectedCookieName = Http::COOKIE_VARY_STRING;
     $cookieMetadataMock = $this->getMock('Magento\\Framework\\Stdlib\\Cookie\\CookieMetadata');
     $cookieMetadataMock->expects($this->once())->method('setPath')->with('/')->will($this->returnSelf());
     $this->cookieMetadataFactoryMock->expects($this->once())->method('createCookieMetadata')->with()->will($this->returnValue($cookieMetadataMock));
     $this->cookieManagerMock->expects($this->once())->method('deleteCookie')->with($expectedCookieName, $cookieMetadataMock);
     $this->model->sendVary();
 }
Beispiel #6
0
 /**
  * @param bool $isPost
  * @param int $numOfCalls
  * @dataProvider afterDispatchTestDataProvider
  */
 public function testAfterDispatch($isPost, $numOfCalls)
 {
     $this->messageManagerMock->expects($this->exactly($numOfCalls))->method('hasMessages')->will($this->returnValue(true));
     $this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue($isPost));
     $this->cookieMetadataFactoryMock->expects($this->exactly($numOfCalls))->method('createPublicCookieMetadata')->will($this->returnValue($this->publicCookieMetadataMock));
     $this->publicCookieMetadataMock->expects($this->exactly($numOfCalls))->method('setDuration')->with(MessageBox::COOKIE_PERIOD)->will($this->returnValue($this->publicCookieMetadataMock));
     $this->publicCookieMetadataMock->expects($this->exactly($numOfCalls))->method('setPath')->with('/')->will($this->returnValue($this->publicCookieMetadataMock));
     $this->cookieManagerMock->expects($this->exactly($numOfCalls))->method('setPublicCookie')->with(MessageBox::COOKIE_NAME, 1, $this->publicCookieMetadataMock);
     $this->assertSame($this->responseMock, $this->msgBox->afterDispatch($this->objectMock, $this->responseMock));
 }
Beispiel #7
0
 public function testLoadValidOrderStoredCookie()
 {
     $this->sessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false));
     $orderMock = $this->getMock('Magento\\Sales\\Model\\Order', ['getProtectCode', 'loadByIncrementId', 'getId', 'getBillingAddress', '__wakeup'], [], '', false);
     $protectedCode = 'protectedCode';
     $incrementId = 1;
     $cookieData = $protectedCode . ':' . $incrementId;
     $cookieDataHash = base64_encode($cookieData);
     $this->orderFactoryMock->expects($this->once())->method('create')->will($this->returnValue($orderMock));
     $this->cookieManagerMock->expects($this->once())->method('getCookie')->with(Guest::COOKIE_NAME)->will($this->returnValue($cookieDataHash));
     $orderMock->expects($this->once())->method('loadByIncrementId')->with($incrementId);
     $orderMock->expects($this->exactly(1))->method('getId')->will($this->returnValue($incrementId));
     $orderMock->expects($this->once())->method('getProtectCode')->will($this->returnValue($protectedCode));
     $metaData = new \Magento\Framework\Stdlib\Cookie\PublicCookieMetadata();
     $this->cookieMetadataFactoryMock->expects($this->once())->method('createPublicCookieMetadata')->will($this->returnValue($metaData));
     $this->cookieManagerMock->expects($this->once())->method('setPublicCookie')->with(Guest::COOKIE_NAME, $this->anything(), $metaData);
     $requestMock = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
     $responseMock = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
     $this->assertTrue($this->guest->loadValidOrder($requestMock, $responseMock));
 }