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()); }
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(); }
/** * @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->publicCookieMetadataMock->expects($this->exactly($numOfCalls))->method('setHttpOnly')->with(false)->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)); }
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('setSensitiveCookie'); $sendFriendClass = new \ReflectionClass('Magento\\Sendfriend\\Model\\Sendfriend'); $method = $sendFriendClass->getMethod('_sentCountByCookies'); $method->setAccessible(true); $method->invokeArgs($this->model, [true]); }
/** * @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()); $publicCookieMetadataMock->expects($this->once())->method('setHttpOnly')->with(false)->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(); }
public function testDelete() { $cookiePath = '/'; $cookieDomain = 'example.com'; /** @var PublicCookieMetadata|\PHPUnit_Framework_MockObject_MockObject $metadata */ $metadata = $this->getMockBuilder('Magento\\Framework\\Stdlib\\Cookie\\PublicCookieMetadata')->disableOriginalConstructor()->getMock(); $this->cookieMetadataFactory->expects(static::once())->method('createCookieMetadata')->willReturn($metadata); $this->sessionManager->expects(static::once())->method('getCookiePath')->willReturn($cookiePath); $metadata->expects(static::once())->method('setPath')->with($cookiePath)->willReturnSelf(); $this->sessionManager->expects(static::once())->method('getCookieDomain')->willReturn($cookieDomain); $metadata->expects(static::once())->method('setDomain')->with($cookieDomain)->willReturnSelf(); $this->cookieManagerMock->expects(static::once())->method('deleteCookie')->with(FormKey::COOKIE_NAME, $metadata); $this->formKey->delete(); }
public function testAfterRenderResultWithWrongArray() { $messageType = 'message1type'; $messageText = 'message1text'; $messages = [['type' => $messageType, 'text' => $messageText]]; /** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $resultMock */ $resultMock = $this->getMockBuilder(Redirect::class)->disableOriginalConstructor()->getMock(); /** @var PublicCookieMetadata|\PHPUnit_Framework_MockObject_MockObject $cookieMetadataMock */ $cookieMetadataMock = $this->getMockBuilder(PublicCookieMetadata::class)->disableOriginalConstructor()->getMock(); $this->cookieMetadataFactoryMock->expects($this->once())->method('createPublicCookieMetadata')->willReturn($cookieMetadataMock); $this->cookieManagerMock->expects($this->once())->method('setPublicCookie')->with(MessagePlugin::MESSAGES_COOKIES_NAME, \Zend_Json::encode($messages), $cookieMetadataMock); $this->cookieManagerMock->expects($this->once())->method('getCookie')->with(MessagePlugin::MESSAGES_COOKIES_NAME, \Zend_Json::encode([]))->willReturn(\Zend_Json::encode('string')); $this->dataMock->expects($this->any())->method('jsonDecode')->willReturnCallback(function ($data) { return \Zend_Json::decode($data); }); $this->dataMock->expects($this->any())->method('jsonEncode')->willReturnCallback(function ($data) { return \Zend_Json::encode($data); }); /** @var MessageInterface|\PHPUnit_Framework_MockObject_MockObject $messageMock */ $messageMock = $this->getMockBuilder(MessageInterface::class)->getMock(); $messageMock->expects($this->once())->method('getType')->willReturn($messageType); $this->interpretationStrategyMock->expects($this->once())->method('interpret')->with($messageMock)->willReturn($messageText); /** @var Collection|\PHPUnit_Framework_MockObject_MockObject $collectionMock */ $collectionMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock(); $collectionMock->expects($this->once())->method('getItems')->willReturn([$messageMock]); $this->managerMock->expects($this->once())->method('getMessages')->with(true, null)->willReturn($collectionMock); $this->assertEquals($resultMock, $this->model->afterRenderResult($resultMock, $resultMock)); }
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)); $metaDataMock = $this->getMock('Magento\\Framework\\Stdlib\\Cookie\\PublicCookieMetadata', [], [], '', false); $metaDataMock->expects($this->once())->method('setPath')->with(Guest::COOKIE_PATH)->will($this->returnSelf()); $metaDataMock->expects($this->once())->method('setHttpOnly')->with(true)->will($this->returnSelf()); $this->cookieMetadataFactoryMock->expects($this->once())->method('createPublicCookieMetadata')->will($this->returnValue($metaDataMock)); $this->cookieManagerMock->expects($this->once())->method('setPublicCookie')->with(Guest::COOKIE_NAME, $this->anything(), $metaDataMock); $requestMock = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false); $this->assertTrue($this->guest->loadValidOrder($requestMock)); }