/
ChooserTest.php
139 lines (117 loc) · 5.31 KB
/
ChooserTest.php
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Widget\Test\Unit\Block\Adminhtml\Widget\Catalog\Category;
class ChooserTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Catalog\Model\Resource\Category\Collection|\PHPUnit_Framework_MockObject_MockObject
*/
protected $collection;
/**
* @var \Magento\Framework\Data\Tree\Node|\PHPUnit_Framework_MockObject_MockObject
*/
protected $childNode;
/**
* @var \Magento\Framework\Data\Tree\Node|\PHPUnit_Framework_MockObject_MockObject
*/
protected $rootNode;
/**
* @var \Magento\Catalog\Model\Resource\Category\Tree|\PHPUnit_Framework_MockObject_MockObject
*/
protected $categoryTree;
/**
* @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject
*/
protected $store;
/**
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $storeManager;
/**
* @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $request;
/**
* @var \Magento\Framework\Escaper|\PHPUnit_Framework_MockObject_MockObject
*/
protected $escaper;
/**
* @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $eventManager;
/**
* @var \Magento\Backend\Block\Template\Context|\PHPUnit_Framework_MockObject_MockObject
*/
protected $context;
public function setUp()
{
$this->collection = $this->getMock('Magento\Catalog\Model\Resource\Category\Collection', [], [], '', false);
$this->childNode = $this->getMock(
'Magento\Framework\Data\Tree\Node',
['getLevel', 'hasChildren'],
[],
'',
false
);
$this->rootNode = $this->getMock(
'Magento\Framework\Data\Tree\Node',
['getLevel', 'hasChildren', 'getChildren'],
[],
'',
false
);
$this->categoryTree = $this->getMock('Magento\Catalog\Model\Resource\Category\Tree', [], [], '', false);
$this->store = $this->getMock('Magento\Store\Model\Store', [], [], '', false);
$this->storeManager = $this->getMock('Magento\Store\Model\StoreManagerInterface', [], [], '', false);
$this->request = $this->getMock('Magento\Framework\App\RequestInterface', [], [], '', false);
$this->escaper = $this->getMock('Magento\Framework\Escaper', [], [], '', false);
$this->eventManager = $this->getMock('Magento\Framework\Event\ManagerInterface', [], [], '', false);
$this->context = $this->getMock('Magento\Backend\Block\Template\Context', [], [], '', false);
}
public function testGetTreeHasLevelField()
{
$rootId = \Magento\Catalog\Model\Category::TREE_ROOT_ID;
$storeGroups = [];
$storeId = 1;
$rootLevel = 2;
$level = 3;
$this->collection->expects($this->any())->method('addAttributeToSelect')->willReturnMap(
[
['url_key', false, $this->collection],
['is_anchor', false, $this->collection]
]
);
$this->childNode->expects($this->atLeastOnce())->method('getLevel')->willReturn($level);
$this->rootNode->expects($this->atLeastOnce())->method('getLevel')->willReturn($rootLevel);
$this->rootNode->expects($this->once())->method('hasChildren')->willReturn(true);
$this->rootNode->expects($this->once())->method('getChildren')->willReturn([$this->childNode]);
$this->categoryTree->expects($this->once())->method('load')->with(null, 3)->willReturnSelf();
$this->categoryTree->expects($this->atLeastOnce())
->method('addCollectionData')
->with($this->collection)
->willReturnSelf();
$this->categoryTree->expects($this->once())->method('getNodeById')->with($rootId)->willReturn($this->rootNode);
$this->store->expects($this->atLeastOnce())->method('getId')->willReturn($storeId);
$this->storeManager->expects($this->once())->method('getGroups')->willReturn($storeGroups);
$this->storeManager->expects($this->atLeastOnce())->method('getStore')->willReturn($this->store);
$this->context->expects($this->once())->method('getStoreManager')->willReturn($this->storeManager);
$this->context->expects($this->once())->method('getRequest')->willReturn($this->request);
$this->context->expects($this->once())->method('getEscaper')->willReturn($this->escaper);
$this->context->expects($this->once())->method('getEventManager')->willReturn($this->eventManager);
/** @var \Magento\Widget\Block\Adminhtml\Widget\Catalog\Category\Chooser $chooser */
$chooser = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))
->getObject(
'Magento\Widget\Block\Adminhtml\Widget\Catalog\Category\Chooser',
[
'categoryTree' => $this->categoryTree,
'context' => $this->context
]
);
$chooser->setData('category_collection', $this->collection);
$result = $chooser->getTree();
$this->assertEquals($level, $result[0]['level']);
}
}