5
5
*/
6
6
namespace Magento \Customer \Block \Adminhtml \Edit \Tab ;
7
7
8
+ use Magento \Backend \Block \Template \Context ;
9
+ use Magento \Backend \Model \Session \Quote as SessionQuote ;
8
10
use Magento \Customer \Controller \RegistryConstants ;
11
+ use Magento \Framework \ObjectManagerInterface ;
12
+ use Magento \Framework \Registry ;
13
+ use Magento \Quote \Model \Quote ;
14
+ use Magento \Store \Model \StoreManagerInterface ;
9
15
10
16
/**
11
17
* Magento\Customer\Block\Adminhtml\Edit\Tab\Cart
12
18
*
13
19
* @magentoAppArea adminhtml
20
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
14
21
*/
15
22
class CartTest extends \PHPUnit \Framework \TestCase
16
23
{
17
24
const CUSTOMER_ID_VALUE = 1234 ;
18
25
19
- /** @var \Magento\Backend\Block\Template\Context */
26
+ /**
27
+ * @var Context
28
+ */
20
29
private $ _context ;
21
30
22
- /** @var \Magento\Framework\Registry */
31
+ /**
32
+ * @var Registry
33
+ */
23
34
private $ _coreRegistry ;
24
35
25
- /** @var \Magento\Store\Model\StoreManagerInterface */
36
+ /**
37
+ * @var StoreManagerInterface
38
+ */
26
39
private $ _storeManager ;
27
40
28
- /** @var Cart */
41
+ /**
42
+ * @var Cart
43
+ */
29
44
private $ _block ;
30
45
31
- /** @var \Magento\Framework\ObjectManagerInterface */
46
+ /**
47
+ * @var ObjectManagerInterface
48
+ */
32
49
private $ _objectManager ;
33
50
51
+ /**
52
+ * @inheritdoc
53
+ */
34
54
public function setUp ()
35
55
{
36
56
$ this ->_objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
@@ -53,22 +73,96 @@ public function setUp()
53
73
);
54
74
}
55
75
76
+ /**
77
+ * @inheritdoc
78
+ */
56
79
public function tearDown ()
57
80
{
58
81
$ this ->_coreRegistry ->unregister (RegistryConstants::CURRENT_CUSTOMER_ID );
59
82
}
60
83
61
- public function testGetCustomerId ()
84
+ /**
85
+ * Verify Grid with quote items
86
+ *
87
+ * @magentoDataFixture Magento/Sales/_files/quote_with_two_products_and_customer.php
88
+ * @magentoDataFixture Magento/Customer/_files/customer.php
89
+ * @dataProvider getQuoteDataProvider
90
+ *
91
+ * @param int $customerId
92
+ * @param bool $guest
93
+ * @param bool $contains
94
+ * @return void
95
+ */
96
+ public function testVerifyCollectionWithQuote (int $ customerId , bool $ guest , bool $ contains ): void
97
+ {
98
+ $ session = $ this ->_objectManager ->create (SessionQuote::class);
99
+ $ session ->setCustomerId ($ customerId );
100
+ $ quoteFixture = $ this ->_objectManager ->create (Quote::class);
101
+ $ quoteFixture ->load ('test01 ' , 'reserved_order_id ' );
102
+ $ quoteFixture ->setCustomerIsGuest ($ guest )
103
+ ->setCustomerId ($ customerId )
104
+ ->save ();
105
+ $ this ->_block ->toHtml ();
106
+ if ($ contains ) {
107
+ $ this ->assertContains (
108
+ "We couldn't find any records " ,
109
+ $ this ->_block ->getGridParentHtml ()
110
+ );
111
+ } else {
112
+ $ this ->assertNotContains (
113
+ "We couldn't find any records " ,
114
+ $ this ->_block ->getGridParentHtml ()
115
+ );
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Data provider for withQuoteTest
121
+ *
122
+ * @return array
123
+ */
124
+ public function getQuoteDataProvider (): array
125
+ {
126
+ return [
127
+ [
128
+ 6 ,
129
+ false ,
130
+ true
131
+ ],
132
+ [
133
+ self ::CUSTOMER_ID_VALUE ,
134
+ true ,
135
+ false
136
+ ],
137
+ ];
138
+ }
139
+
140
+ /**
141
+ * Verify Customer id
142
+ *
143
+ * @return void
144
+ */
145
+ public function testGetCustomerId (): void
62
146
{
63
147
$ this ->assertEquals (self ::CUSTOMER_ID_VALUE , $ this ->_block ->getCustomerId ());
64
148
}
65
149
66
- public function testGetGridUrl ()
150
+ /**
151
+ * Verify get grid url
152
+ *
153
+ * @return void
154
+ */
155
+ public function testGetGridUrl (): void
67
156
{
68
157
$ this ->assertContains ('/backend/customer/index/cart ' , $ this ->_block ->getGridUrl ());
69
158
}
70
159
71
- public function testGetGridParentHtml ()
160
+ /**
161
+ * Verify grid parent html
162
+ *
163
+ * @return void
164
+ */
165
+ public function testGetGridParentHtml (): void
72
166
{
73
167
$ this ->_block = $ this ->_objectManager ->get (
74
168
\Magento \Framework \View \LayoutInterface::class
@@ -87,14 +181,24 @@ public function testGetGridParentHtml()
87
181
);
88
182
}
89
183
90
- public function testGetRowUrl ()
184
+ /**
185
+ * Verify row url
186
+ *
187
+ * @return void
188
+ */
189
+ public function testGetRowUrl (): void
91
190
{
92
191
$ row = new \Magento \Framework \DataObject ();
93
192
$ row ->setProductId (1 );
94
193
$ this ->assertContains ('/backend/catalog/product/edit/id/1 ' , $ this ->_block ->getRowUrl ($ row ));
95
194
}
96
195
97
- public function testGetHtml ()
196
+ /**
197
+ * Verify get html
198
+ *
199
+ * @return void
200
+ */
201
+ public function testGetHtml (): void
98
202
{
99
203
$ html = $ this ->_block ->toHtml ();
100
204
$ this ->assertContains ("<div id= \"customer_cart_grid \"" , $ html );
0 commit comments