ContextPluginTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Test\Unit\Model\App\Action;
  7. use Magento\Customer\Model\Context;
  8. /**
  9. * Class ContextPluginTest
  10. */
  11. class ContextPluginTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var \Magento\Customer\Model\App\Action\ContextPlugin
  15. */
  16. protected $plugin;
  17. /**
  18. * @var \Magento\Customer\Model\Session|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $customerSessionMock;
  21. /**
  22. * @var \Magento\Framework\App\Http\Context $httpContext|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $httpContextMock;
  25. /**
  26. * @var \PHPUnit_Framework_MockObject_MockObject
  27. */
  28. protected $subjectMock;
  29. /**
  30. * @var \PHPUnit_Framework_MockObject_MockObject
  31. */
  32. protected $requestMock;
  33. /**
  34. * Set up
  35. */
  36. protected function setUp()
  37. {
  38. $this->customerSessionMock = $this->createMock(\Magento\Customer\Model\Session::class);
  39. $this->httpContextMock = $this->createMock(\Magento\Framework\App\Http\Context::class);
  40. $this->subjectMock = $this->createMock(\Magento\Framework\App\Action\Action::class);
  41. $this->requestMock = $this->createMock(\Magento\Framework\App\RequestInterface::class);
  42. $this->plugin = new \Magento\Customer\Model\App\Action\ContextPlugin(
  43. $this->customerSessionMock,
  44. $this->httpContextMock
  45. );
  46. }
  47. /**
  48. * Test aroundDispatch
  49. */
  50. public function testBeforeDispatch()
  51. {
  52. $this->customerSessionMock->expects($this->once())
  53. ->method('getCustomerGroupId')
  54. ->will($this->returnValue(1));
  55. $this->customerSessionMock->expects($this->once())
  56. ->method('isLoggedIn')
  57. ->will($this->returnValue(true));
  58. $this->httpContextMock->expects($this->atLeastOnce())
  59. ->method('setValue')
  60. ->will(
  61. $this->returnValueMap(
  62. [
  63. [Context::CONTEXT_GROUP, 'UAH', $this->httpContextMock],
  64. [Context::CONTEXT_AUTH, 0, $this->httpContextMock],
  65. ]
  66. )
  67. );
  68. $this->plugin->beforeDispatch($this->subjectMock, $this->requestMock);
  69. }
  70. }