ConfigProviderPluginTest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Persistent\Test\Unit\Model\Checkout;
  7. class ConfigProviderPluginTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \PHPUnit_Framework_MockObject_MockObject
  11. */
  12. protected $persistentHelperMock;
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $persistentSessionMock;
  17. /**
  18. * @var \PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $checkoutSessionMock;
  21. /**
  22. * @var \PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $maskFactoryMock;
  25. /**
  26. * @var \PHPUnit_Framework_MockObject_MockObject
  27. */
  28. protected $customerSessionMock;
  29. /**
  30. * @var \Magento\Persistent\Model\Checkout\ConfigProviderPlugin
  31. */
  32. protected $plugin;
  33. /**
  34. * @var \PHPUnit_Framework_MockObject_MockObject
  35. */
  36. protected $subjectMock;
  37. protected function setUp()
  38. {
  39. $this->persistentHelperMock = $this->createMock(\Magento\Persistent\Helper\Data::class);
  40. $this->persistentSessionMock = $this->createMock(\Magento\Persistent\Helper\Session::class);
  41. $this->checkoutSessionMock = $this->createMock(\Magento\Checkout\Model\Session::class);
  42. $this->maskFactoryMock = $this->createPartialMock(
  43. \Magento\Quote\Model\QuoteIdMaskFactory::class,
  44. ['create', '__wakeup']
  45. );
  46. $this->customerSessionMock = $this->createMock(\Magento\Customer\Model\Session::class);
  47. $this->subjectMock = $this->createMock(\Magento\Checkout\Model\DefaultConfigProvider::class);
  48. $this->plugin = new \Magento\Persistent\Model\Checkout\ConfigProviderPlugin(
  49. $this->persistentHelperMock,
  50. $this->persistentSessionMock,
  51. $this->checkoutSessionMock,
  52. $this->maskFactoryMock,
  53. $this->customerSessionMock
  54. );
  55. }
  56. /**
  57. * @param bool $persistenceEnabled
  58. * @param bool $isPersistent
  59. * @param bool $isLoggedIn
  60. *
  61. * @dataProvider configDataProvider
  62. */
  63. public function testAfterGetConfigNegative($persistenceEnabled, $isPersistent, $isLoggedIn)
  64. {
  65. $result = [40, 30, 50];
  66. $this->persistentHelperMock->expects($this->once())->method('isEnabled')->willReturn($persistenceEnabled);
  67. $this->persistentSessionMock->expects($this->any())->method('isPersistent')->willReturn($isPersistent);
  68. $this->customerSessionMock->expects($this->any())->method('isLoggedIn')->willReturn($isLoggedIn);
  69. $this->maskFactoryMock->expects($this->never())->method('create');
  70. $this->assertEquals($result, $this->plugin->afterGetConfig($this->subjectMock, $result));
  71. }
  72. /**
  73. * @return array
  74. */
  75. public function configDataProvider()
  76. {
  77. return [
  78. [false, true, true], //disabled persistence case
  79. [true, false, true], //persistence enabled but not persistent session
  80. [true, true, true], //logged in user
  81. ];
  82. }
  83. public function testAfterGetConfigPositive()
  84. {
  85. $maskedId = 3005;
  86. $result = [40, 30, 50];
  87. $expectedResult = $result;
  88. $expectedResult['quoteData']['entity_id'] = $maskedId;
  89. $this->persistentHelperMock->expects($this->once())->method('isEnabled')->willReturn(true);
  90. $this->persistentSessionMock->expects($this->once())->method('isPersistent')->willReturn(true);
  91. $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(false);
  92. $quoteMaskMock = $this->createPartialMock(\Magento\Quote\Model\QuoteIdMask::class, ['load', 'getMaskedId']);
  93. $this->maskFactoryMock->expects($this->once())->method('create')->willReturn($quoteMaskMock);
  94. $quoteMock = $this->createMock(\Magento\Quote\Model\Quote::class);
  95. $this->checkoutSessionMock->expects($this->once())->method('getQuote')->willReturn($quoteMock);
  96. $quoteMaskMock->expects($this->once())->method('load')->willReturnSelf();
  97. $quoteMaskMock->expects($this->once())->method('getMaskedId')->willReturn($maskedId);
  98. $this->assertEquals($expectedResult, $this->plugin->afterGetConfig($this->subjectMock, $result));
  99. }
  100. }