Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
AgreementsProviderTest.php
Go to the documentation of this file.
1 <?php
7 
11 
12 class AgreementsProviderTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $model;
18 
22  protected $scopeConfigMock;
23 
28 
32  protected $storeManagerMock;
33 
34  protected function setUp()
35  {
36  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
37 
38  $this->agreementCollFactoryMock = $this->createPartialMock(
39  \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\CollectionFactory::class,
40  ['create']
41  );
42  $this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
43  $this->scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
44 
45  $this->model = $objectManager->getObject(
46  \Magento\CheckoutAgreements\Model\AgreementsProvider::class,
47  [
48  'agreementCollectionFactory' => $this->agreementCollFactoryMock,
49  'storeManager' => $this->storeManagerMock,
50  'scopeConfig' => $this->scopeConfigMock
51  ]
52  );
53  }
54 
56  {
57  $storeId = 100;
58  $expectedResult = [1, 2, 3, 4, 5];
59  $this->scopeConfigMock->expects($this->once())
60  ->method('isSetFlag')
62  ->willReturn(true);
63 
64  $agreementCollection = $this->createMock(
65  \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\Collection::class
66  );
67  $this->agreementCollFactoryMock->expects($this->once())->method('create')->willReturn($agreementCollection);
68 
69  $storeMock = $this->createMock(\Magento\Store\Model\Store::class);
70  $storeMock->expects($this->once())->method('getId')->willReturn($storeId);
71  $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock);
72 
73  $agreementCollection->expects($this->once())->method('addStoreFilter')->with($storeId)->willReturnSelf();
74  $agreementCollection->expects($this->at(1))
75  ->method('addFieldToFilter')
76  ->with('is_active', 1)
77  ->willReturnSelf();
78  $agreementCollection->expects($this->at(2))
79  ->method('addFieldToFilter')
80  ->with('mode', AgreementModeOptions::MODE_MANUAL)
81  ->willReturnSelf();
82  $agreementCollection->expects($this->once())->method('getAllIds')->willReturn($expectedResult);
83 
84  $this->assertEquals($expectedResult, $this->model->getRequiredAgreementIds());
85  }
86 
88  {
89  $expectedResult = [];
90  $this->scopeConfigMock->expects($this->once())
91  ->method('isSetFlag')
93  ->willReturn(false);
94  $this->assertEquals($expectedResult, $this->model->getRequiredAgreementIds());
95  }
96 }
$objectManager
Definition: bootstrap.php:17