AgreementsTest.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CheckoutAgreements\Test\Unit\Block;
  7. use Magento\CheckoutAgreements\Model\AgreementsProvider;
  8. use Magento\Store\Model\ScopeInterface;
  9. class AgreementsTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * @var \Magento\CheckoutAgreements\Block\Agreements
  13. */
  14. protected $model;
  15. /**
  16. * @var \PHPUnit_Framework_MockObject_MockObject
  17. */
  18. protected $agreementCollFactoryMock;
  19. /**
  20. * @var \PHPUnit_Framework_MockObject_MockObject
  21. */
  22. protected $scopeConfigMock;
  23. /**
  24. * @var \PHPUnit_Framework_MockObject_MockObject
  25. */
  26. protected $storeManagerMock;
  27. protected function setUp()
  28. {
  29. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  30. $this->agreementCollFactoryMock = $this->createPartialMock(
  31. \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\CollectionFactory::class,
  32. ['create']
  33. );
  34. $this->scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
  35. $this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
  36. $contextMock = $this->createMock(\Magento\Framework\View\Element\Template\Context::class);
  37. $contextMock->expects($this->once())->method('getScopeConfig')->willReturn($this->scopeConfigMock);
  38. $contextMock->expects($this->once())->method('getStoreManager')->willReturn($this->storeManagerMock);
  39. $this->model = $objectManager->getObject(
  40. \Magento\CheckoutAgreements\Block\Agreements::class,
  41. [
  42. 'agreementCollectionFactory' => $this->agreementCollFactoryMock,
  43. 'context' => $contextMock
  44. ]
  45. );
  46. }
  47. public function testGetAgreements()
  48. {
  49. $storeId = 100;
  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->once())
  63. ->method('addFieldToFilter')
  64. ->with('is_active', 1)
  65. ->willReturnSelf();
  66. $this->assertEquals($agreementCollection, $this->model->getAgreements());
  67. }
  68. public function testGetAgreementsIfAgreementsDisabled()
  69. {
  70. $expectedResult = [];
  71. $this->scopeConfigMock->expects($this->once())
  72. ->method('isSetFlag')
  73. ->with(AgreementsProvider::PATH_ENABLED, ScopeInterface::SCOPE_STORE)
  74. ->willReturn(false);
  75. $this->assertEquals($expectedResult, $this->model->getAgreements());
  76. }
  77. }