Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AgreementsTest.php
Go to the documentation of this file.
1 <?php
7 
10 
11 class AgreementsTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $model;
17 
22 
26  protected $scopeConfigMock;
27 
31  protected $storeManagerMock;
32 
33  protected function setUp()
34  {
35  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
36  $this->agreementCollFactoryMock = $this->createPartialMock(
37  \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\CollectionFactory::class,
38  ['create']
39  );
40 
41  $this->scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
42  $this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
43 
44  $contextMock = $this->createMock(\Magento\Framework\View\Element\Template\Context::class);
45  $contextMock->expects($this->once())->method('getScopeConfig')->willReturn($this->scopeConfigMock);
46  $contextMock->expects($this->once())->method('getStoreManager')->willReturn($this->storeManagerMock);
47 
48  $this->model = $objectManager->getObject(
49  \Magento\CheckoutAgreements\Block\Agreements::class,
50  [
51  'agreementCollectionFactory' => $this->agreementCollFactoryMock,
52  'context' => $contextMock
53  ]
54  );
55  }
56 
57  public function testGetAgreements()
58  {
59  $storeId = 100;
60  $this->scopeConfigMock->expects($this->once())
61  ->method('isSetFlag')
63  ->willReturn(true);
64 
65  $agreementCollection = $this->createMock(
66  \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\Collection::class
67  );
68  $this->agreementCollFactoryMock->expects($this->once())->method('create')->willReturn($agreementCollection);
69 
70  $storeMock = $this->createMock(\Magento\Store\Model\Store::class);
71  $storeMock->expects($this->once())->method('getId')->willReturn($storeId);
72  $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock);
73 
74  $agreementCollection->expects($this->once())->method('addStoreFilter')->with($storeId)->willReturnSelf();
75  $agreementCollection->expects($this->once())
76  ->method('addFieldToFilter')
77  ->with('is_active', 1)
78  ->willReturnSelf();
79 
80  $this->assertEquals($agreementCollection, $this->model->getAgreements());
81  }
82 
84  {
85  $expectedResult = [];
86  $this->scopeConfigMock->expects($this->once())
87  ->method('isSetFlag')
89  ->willReturn(false);
90  $this->assertEquals($expectedResult, $this->model->getAgreements());
91  }
92 }
$objectManager
Definition: bootstrap.php:17