5
5
*/
6
6
namespace Magento \Sales \Test \Unit \Block \Order ;
7
7
8
+ use Magento \Framework \View \Element \Template \Context ;
9
+ use Magento \Sales \Model \ResourceModel \Order \CollectionFactory ;
10
+ use Magento \Customer \Model \Session ;
11
+ use Magento \Sales \Model \Order \Config ;
12
+ use Magento \Store \Model \StoreManagerInterface ;
13
+ use Magento \Framework \View \Layout ;
14
+ use Magento \Store \Api \Data \StoreInterface ;
15
+ use Magento \Sales \Model \ResourceModel \Order \Collection ;
16
+
8
17
class RecentTest extends \PHPUnit \Framework \TestCase
9
18
{
10
19
/**
@@ -32,26 +41,33 @@ class RecentTest extends \PHPUnit\Framework\TestCase
32
41
*/
33
42
protected $ orderConfig ;
34
43
44
+ /**
45
+ * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
46
+ */
47
+ protected $ storeManagerMock ;
48
+
35
49
protected function setUp ()
36
50
{
37
- $ this ->context = $ this ->createMock (\ Magento \ Framework \ View \ Element \ Template \ Context::class);
51
+ $ this ->context = $ this ->createMock (Context::class);
38
52
$ this ->orderCollectionFactory = $ this ->createPartialMock (
39
- \ Magento \ Sales \ Model \ ResourceModel \ Order \ CollectionFactory::class,
53
+ CollectionFactory::class,
40
54
['create ' ]
41
55
);
42
- $ this ->customerSession = $ this ->createPartialMock (\ Magento \ Customer \ Model \ Session::class, ['getCustomerId ' ]);
56
+ $ this ->customerSession = $ this ->createPartialMock (Session::class, ['getCustomerId ' ]);
43
57
$ this ->orderConfig = $ this ->createPartialMock (
44
- \ Magento \ Sales \ Model \ Order \ Config::class,
58
+ Config::class,
45
59
['getVisibleOnFrontStatuses ' ]
46
60
);
61
+ $ this ->storeManagerMock = $ this ->getMockBuilder (StoreManagerInterface::class)
62
+ ->getMockForAbstractClass ();
47
63
}
48
64
49
65
public function testConstructMethod ()
50
66
{
51
- $ data = [];
52
- $ attribute = ['customer_id ' , 'status ' ];
67
+ $ attribute = ['customer_id ' , 'store_id ' , 'status ' ];
53
68
$ customerId = 25 ;
54
- $ layout = $ this ->createPartialMock (\Magento \Framework \View \Layout::class, ['getBlock ' ]);
69
+ $ storeId = 4 ;
70
+ $ layout = $ this ->createPartialMock (Layout::class, ['getBlock ' ]);
55
71
$ this ->context ->expects ($ this ->once ())
56
72
->method ('getLayout ' )
57
73
->will ($ this ->returnValue ($ layout ));
@@ -64,14 +80,20 @@ public function testConstructMethod()
64
80
->method ('getVisibleOnFrontStatuses ' )
65
81
->will ($ this ->returnValue ($ statuses ));
66
82
67
- $ orderCollection = $ this ->createPartialMock (\Magento \Sales \Model \ResourceModel \Order \Collection::class, [
68
- 'addAttributeToSelect ' ,
69
- 'addFieldToFilter ' ,
70
- 'addAttributeToFilter ' ,
71
- 'addAttributeToSort ' ,
72
- 'setPageSize ' ,
73
- 'load '
74
- ]);
83
+ $ this ->storeManagerMock = $ this ->getMockBuilder (StoreManagerInterface::class)
84
+ ->getMockForAbstractClass ();
85
+ $ storeMock = $ this ->getMockBuilder (StoreInterface::class)->getMockForAbstractClass ();
86
+ $ this ->storeManagerMock ->expects ($ this ->once ())->method ('getStore ' )->willReturn ($ storeMock );
87
+ $ storeMock ->expects ($ this ->any ())->method ('getId ' )->willReturn ($ storeId );
88
+
89
+ $ orderCollection = $ this ->createPartialMock (Collection::class, [
90
+ 'addAttributeToSelect ' ,
91
+ 'addFieldToFilter ' ,
92
+ 'addAttributeToFilter ' ,
93
+ 'addAttributeToSort ' ,
94
+ 'setPageSize ' ,
95
+ 'load '
96
+ ]);
75
97
$ this ->orderCollectionFactory ->expects ($ this ->once ())
76
98
->method ('create ' )
77
99
->will ($ this ->returnValue ($ orderCollection ));
@@ -85,25 +107,30 @@ public function testConstructMethod()
85
107
->willReturnSelf ();
86
108
$ orderCollection ->expects ($ this ->at (2 ))
87
109
->method ('addAttributeToFilter ' )
88
- ->with ($ attribute [1 ], $ this ->equalTo ([ ' in ' => $ statuses ] ))
89
- ->will ( $ this -> returnSelf () );
110
+ ->with ($ attribute [1 ], $ this ->equalTo ($ storeId ))
111
+ ->willReturnSelf ( );
90
112
$ orderCollection ->expects ($ this ->at (3 ))
113
+ ->method ('addAttributeToFilter ' )
114
+ ->with ($ attribute [2 ], $ this ->equalTo (['in ' => $ statuses ]))
115
+ ->will ($ this ->returnSelf ());
116
+ $ orderCollection ->expects ($ this ->at (4 ))
91
117
->method ('addAttributeToSort ' )
92
118
->with ('created_at ' , 'desc ' )
93
119
->will ($ this ->returnSelf ());
94
- $ orderCollection ->expects ($ this ->at (4 ))
120
+ $ orderCollection ->expects ($ this ->at (5 ))
95
121
->method ('setPageSize ' )
96
122
->with ('5 ' )
97
123
->will ($ this ->returnSelf ());
98
- $ orderCollection ->expects ($ this ->at (5 ))
124
+ $ orderCollection ->expects ($ this ->at (6 ))
99
125
->method ('load ' )
100
126
->will ($ this ->returnSelf ());
101
127
$ this ->block = new \Magento \Sales \Block \Order \Recent (
102
128
$ this ->context ,
103
129
$ this ->orderCollectionFactory ,
104
130
$ this ->customerSession ,
105
131
$ this ->orderConfig ,
106
- $ data
132
+ [],
133
+ $ this ->storeManagerMock
107
134
);
108
135
$ this ->assertEquals ($ orderCollection , $ this ->block ->getOrders ());
109
136
}
0 commit comments