AgreementsProviderTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CheckoutAgreements\Test\Unit\Model;
  7. use Magento\CheckoutAgreements\Model\AgreementModeOptions;
  8. use Magento\CheckoutAgreements\Model\AgreementsProvider;
  9. use Magento\Store\Model\ScopeInterface;
  10. class AgreementsProviderTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\CheckoutAgreements\Model\AgreementsProvider
  14. */
  15. protected $model;
  16. /**
  17. * @var \PHPUnit_Framework_MockObject_MockObject
  18. */
  19. protected $scopeConfigMock;
  20. /**
  21. * @var \PHPUnit_Framework_MockObject_MockObject
  22. */
  23. protected $agreementCollFactoryMock;
  24. /**
  25. * @var \PHPUnit_Framework_MockObject_MockObject
  26. */
  27. protected $storeManagerMock;
  28. protected function setUp()
  29. {
  30. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  31. $this->agreementCollFactoryMock = $this->createPartialMock(
  32. \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\CollectionFactory::class,
  33. ['create']
  34. );
  35. $this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
  36. $this->scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
  37. $this->model = $objectManager->getObject(
  38. \Magento\CheckoutAgreements\Model\AgreementsProvider::class,
  39. [
  40. 'agreementCollectionFactory' => $this->agreementCollFactoryMock,
  41. 'storeManager' => $this->storeManagerMock,
  42. 'scopeConfig' => $this->scopeConfigMock
  43. ]
  44. );
  45. }
  46. public function testGetRequiredAgreementIdsIfAgreementsEnabled()
  47. {
  48. $storeId = 100;
  49. $expectedResult = [1, 2, 3, 4, 5];
  50. $this->scopeConfigMock->expects($this->once())
  51. ->method('isSetFlag')
  52. ->with(AgreementsProvider::PATH_ENABLED, ScopeInterface::SCOPE_STORE)
  53. ->willReturn(true);
  54. $agreementCollection = $this->createMock(
  55. \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\Collection::class
  56. );
  57. $this->agreementCollFactoryMock->expects($this->once())->method('create')->willReturn($agreementCollection);
  58. $storeMock = $this->createMock(\Magento\Store\Model\Store::class);
  59. $storeMock->expects($this->once())->method('getId')->willReturn($storeId);
  60. $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock);
  61. $agreementCollection->expects($this->once())->method('addStoreFilter')->with($storeId)->willReturnSelf();
  62. $agreementCollection->expects($this->at(1))
  63. ->method('addFieldToFilter')
  64. ->with('is_active', 1)
  65. ->willReturnSelf();
  66. $agreementCollection->expects($this->at(2))
  67. ->method('addFieldToFilter')
  68. ->with('mode', AgreementModeOptions::MODE_MANUAL)
  69. ->willReturnSelf();
  70. $agreementCollection->expects($this->once())->method('getAllIds')->willReturn($expectedResult);
  71. $this->assertEquals($expectedResult, $this->model->getRequiredAgreementIds());
  72. }
  73. public function testGetRequiredAgreementIdsIfAgreementsDisabled()
  74. {
  75. $expectedResult = [];
  76. $this->scopeConfigMock->expects($this->once())
  77. ->method('isSetFlag')
  78. ->with(AgreementsProvider::PATH_ENABLED, ScopeInterface::SCOPE_STORE)
  79. ->willReturn(false);
  80. $this->assertEquals($expectedResult, $this->model->getRequiredAgreementIds());
  81. }
  82. }