|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2016 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Customer\Test\Unit\CustomerData\Plugin; |
| 7 | + |
| 8 | +use Magento\Customer\CustomerData\Plugin\SessionChecker; |
| 9 | + |
| 10 | +class SessionCheckerTest extends \PHPUnit_Framework_TestCase |
| 11 | +{ |
| 12 | + /** |
| 13 | + * @var SessionChecker |
| 14 | + */ |
| 15 | + protected $plugin; |
| 16 | + |
| 17 | + /** |
| 18 | + * @var \Magento\Framework\Stdlib\Cookie\PhpCookieManager|\PHPUnit_Framework_MockObject_MockObject |
| 19 | + */ |
| 20 | + protected $cookieManager; |
| 21 | + |
| 22 | + /** |
| 23 | + * @var \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory|\PHPUnit_Framework_MockObject_MockObject |
| 24 | + */ |
| 25 | + protected $metadataFactory; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var \Magento\Framework\Stdlib\Cookie\CookieMetadata|\PHPUnit_Framework_MockObject_MockObject |
| 29 | + */ |
| 30 | + protected $metadata; |
| 31 | + |
| 32 | + /** |
| 33 | + * @var \Magento\Customer\Model\Session|\PHPUnit_Framework_MockObject_MockObject |
| 34 | + */ |
| 35 | + protected $session; |
| 36 | + |
| 37 | + /** |
| 38 | + * @var \Magento\Framework\App\Response\Http|\PHPUnit_Framework_MockObject_MockObject |
| 39 | + */ |
| 40 | + protected $response; |
| 41 | + |
| 42 | + public function setUp() |
| 43 | + { |
| 44 | + $this->cookieManager = $this->getMockBuilder('Magento\Framework\Stdlib\Cookie\PhpCookieManager') |
| 45 | + ->disableOriginalConstructor() |
| 46 | + ->getMock(); |
| 47 | + $this->metadataFactory = $this->getMockBuilder('Magento\Framework\Stdlib\Cookie\CookieMetadataFactory') |
| 48 | + ->disableOriginalConstructor() |
| 49 | + ->getMock(); |
| 50 | + $this->metadata = $this->getMockBuilder('Magento\Framework\Stdlib\Cookie\CookieMetadata') |
| 51 | + ->disableOriginalConstructor() |
| 52 | + ->getMock(); |
| 53 | + $this->session = $this->getMockBuilder('Magento\Customer\Model\Session') |
| 54 | + ->disableOriginalConstructor() |
| 55 | + ->getMock(); |
| 56 | + $this->response = $this->getMockBuilder('Magento\Framework\App\Response\Http') |
| 57 | + ->disableOriginalConstructor() |
| 58 | + ->getMock(); |
| 59 | + |
| 60 | + $this->plugin = new SessionChecker($this->cookieManager, $this->metadataFactory, $this->session); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * @param bool $result |
| 65 | + * @param string $callCount |
| 66 | + * @return void |
| 67 | + * @dataProvider testAfterIsLoggedInDataProvider |
| 68 | + */ |
| 69 | + public function testBeforeSendVary($result, $callCount) |
| 70 | + { |
| 71 | + $this->session->expects($this->once()) |
| 72 | + ->method('isLoggedIn') |
| 73 | + ->willReturn($result); |
| 74 | + |
| 75 | + $this->metadataFactory->expects($this->{$callCount}()) |
| 76 | + ->method('createCookieMetadata') |
| 77 | + ->willReturn($this->metadata); |
| 78 | + $this->metadata->expects($this->{$callCount}()) |
| 79 | + ->method('setPath') |
| 80 | + ->with('/'); |
| 81 | + $this->cookieManager->expects($this->{$callCount}()) |
| 82 | + ->method('deleteCookie') |
| 83 | + ->with('mage-cache-sessid', $this->metadata); |
| 84 | + $this->plugin->beforeSendVary($this->response); |
| 85 | + } |
| 86 | + |
| 87 | + public function testAfterIsLoggedInDataProvider() |
| 88 | + { |
| 89 | + return [ |
| 90 | + [false, 'once'], |
| 91 | + [true, 'never'] |
| 92 | + ]; |
| 93 | + } |
| 94 | +} |
0 commit comments