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,34 @@ 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
67
$ data = [];
52
- $ attribute = ['customer_id ' , 'status ' ];
68
+ $ attribute = ['customer_id ' , 'store_id ' , ' status ' ];
53
69
$ customerId = 25 ;
54
- $ layout = $ this ->createPartialMock (\Magento \Framework \View \Layout::class, ['getBlock ' ]);
70
+ $ storeId = 4 ;
71
+ $ layout = $ this ->createPartialMock (Layout::class, ['getBlock ' ]);
55
72
$ this ->context ->expects ($ this ->once ())
56
73
->method ('getLayout ' )
57
74
->will ($ this ->returnValue ($ layout ));
@@ -64,14 +81,20 @@ public function testConstructMethod()
64
81
->method ('getVisibleOnFrontStatuses ' )
65
82
->will ($ this ->returnValue ($ statuses ));
66
83
67
- $ orderCollection = $ this ->createPartialMock (\Magento \Sales \Model \ResourceModel \Order \Collection::class, [
68
- 'addAttributeToSelect ' ,
69
- 'addFieldToFilter ' ,
70
- 'addAttributeToFilter ' ,
71
- 'addAttributeToSort ' ,
72
- 'setPageSize ' ,
73
- 'load '
74
- ]);
84
+ $ this ->storeManagerMock = $ this ->getMockBuilder (StoreManagerInterface::class)
85
+ ->getMockForAbstractClass ();
86
+ $ storeMock = $ this ->getMockBuilder (StoreInterface::class)->getMockForAbstractClass ();
87
+ $ this ->storeManagerMock ->expects ($ this ->once ())->method ('getStore ' )->willReturn ($ storeMock );
88
+ $ storeMock ->expects ($ this ->any ())->method ('getId ' )->willReturn ($ storeId );
89
+
90
+ $ orderCollection = $ this ->createPartialMock (Collection::class, [
91
+ 'addAttributeToSelect ' ,
92
+ 'addFieldToFilter ' ,
93
+ 'addAttributeToFilter ' ,
94
+ 'addAttributeToSort ' ,
95
+ 'setPageSize ' ,
96
+ 'load '
97
+ ]);
75
98
$ this ->orderCollectionFactory ->expects ($ this ->once ())
76
99
->method ('create ' )
77
100
->will ($ this ->returnValue ($ orderCollection ));
@@ -85,24 +108,29 @@ public function testConstructMethod()
85
108
->willReturnSelf ();
86
109
$ orderCollection ->expects ($ this ->at (2 ))
87
110
->method ('addAttributeToFilter ' )
88
- ->with ($ attribute [1 ], $ this ->equalTo ([ ' in ' => $ statuses ] ))
89
- ->will ( $ this -> returnSelf () );
111
+ ->with ($ attribute [1 ], $ this ->equalTo ($ storeId ))
112
+ ->willReturnSelf ( );
90
113
$ orderCollection ->expects ($ this ->at (3 ))
114
+ ->method ('addAttributeToFilter ' )
115
+ ->with ($ attribute [2 ], $ this ->equalTo (['in ' => $ statuses ]))
116
+ ->will ($ this ->returnSelf ());
117
+ $ orderCollection ->expects ($ this ->at (4 ))
91
118
->method ('addAttributeToSort ' )
92
119
->with ('created_at ' , 'desc ' )
93
120
->will ($ this ->returnSelf ());
94
- $ orderCollection ->expects ($ this ->at (4 ))
121
+ $ orderCollection ->expects ($ this ->at (5 ))
95
122
->method ('setPageSize ' )
96
123
->with ('5 ' )
97
124
->will ($ this ->returnSelf ());
98
- $ orderCollection ->expects ($ this ->at (5 ))
125
+ $ orderCollection ->expects ($ this ->at (6 ))
99
126
->method ('load ' )
100
127
->will ($ this ->returnSelf ());
101
128
$ this ->block = new \Magento \Sales \Block \Order \Recent (
102
129
$ this ->context ,
103
130
$ this ->orderCollectionFactory ,
104
131
$ this ->customerSession ,
105
132
$ this ->orderConfig ,
133
+ $ this ->storeManagerMock ,
106
134
$ data
107
135
);
108
136
$ this ->assertEquals ($ orderCollection , $ this ->block ->getOrders ());
0 commit comments