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