5
5
* Copyright © Magento, Inc. All rights reserved.
6
6
* See COPYING.txt for license details.
7
7
*/
8
-
9
8
declare (strict_types=1 );
10
9
11
10
namespace Magento \Sales \Block \Adminhtml \Order \Create \Form ;
23
22
use PHPUnit \Framework \MockObject \MockObject ;
24
23
25
24
/**
25
+ * Class for test Account
26
+ *
26
27
* @magentoAppArea adminhtml
28
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27
29
*/
28
30
class AccountTest extends \PHPUnit \Framework \TestCase
29
31
{
@@ -43,42 +45,54 @@ class AccountTest extends \PHPUnit\Framework\TestCase
43
45
private $ session ;
44
46
45
47
/**
46
- * @magentoDataFixture Magento/Sales/_files/quote.php
48
+ * @inheritdoc
47
49
*/
48
50
protected function setUp ()
49
51
{
50
52
$ this ->objectManager = Bootstrap::getObjectManager ();
51
- $ quote = $ this ->objectManager ->create (Quote::class)->load (1 );
53
+ parent ::setUp ();
54
+ }
55
+
56
+ /**
57
+ * Test for get form with existing customer
58
+ *
59
+ * @magentoDataFixture Magento/Customer/_files/customer.php
60
+ */
61
+ public function testGetFormWithCustomer ()
62
+ {
63
+ $ customerGroup = 2 ;
64
+ $ quote = $ this ->objectManager ->create (Quote::class);
52
65
53
66
$ this ->session = $ this ->getMockBuilder (SessionQuote::class)
54
67
->disableOriginalConstructor ()
55
- ->setMethods (['getCustomerId ' , ' getStore ' , ' getStoreId ' , ' getQuote ' , ' getQuoteId ' ])
68
+ ->setMethods (['getCustomerId ' ,' getQuote ' ])
56
69
->getMock ();
57
- $ this ->session ->method ('getCustomerId ' )
58
- ->willReturn (1 );
59
70
$ this ->session ->method ('getQuote ' )
60
71
->willReturn ($ quote );
61
- $ this ->session ->method ('getQuoteId ' )
62
- ->willReturn ($ quote ->getId ());
72
+ $ this ->session ->method ('getCustomerId ' )
73
+ ->willReturn (1 );
74
+
63
75
/** @var LayoutInterface $layout */
64
76
$ layout = $ this ->objectManager ->get (LayoutInterface::class);
65
77
$ this ->accountBlock = $ layout ->createBlock (
66
78
Account::class,
67
79
'address_block ' . rand (),
68
80
['sessionQuote ' => $ this ->session ]
69
81
);
70
- parent ::setUp ();
71
- }
72
82
73
- /**
74
- * @magentoDataFixture Magento/Customer/_files/customer.php
75
- */
76
- public function testGetForm ()
77
- {
83
+ $ fixtureCustomerId = 1 ;
84
+ /** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
85
+ $ customerRepository = $ this ->objectManager ->get (\Magento \Customer \Api \CustomerRepositoryInterface::class);
86
+ /** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
87
+ $ customer = $ customerRepository ->getById ($ fixtureCustomerId );
88
+ $ customer ->setGroupId ($ customerGroup );
89
+ $ customerRepository ->save ($ customer );
90
+
78
91
$ expectedFields = ['group_id ' , 'email ' ];
79
92
$ form = $ this ->accountBlock ->getForm ();
80
93
self ::assertEquals (1 , $ form ->getElements ()->count (), "Form has invalid number of fieldsets " );
81
94
$ fieldset = $ form ->getElements ()[0 ];
95
+ $ content = $ form ->toHtml ();
82
96
83
97
self ::assertEquals (count ($ expectedFields ), $ fieldset ->getElements ()->count ());
84
98
@@ -88,22 +102,45 @@ public function testGetForm()
88
102
sprintf ('Unexpected field "%s" in form. ' , $ element ->getId ())
89
103
);
90
104
}
105
+
106
+ self ::assertContains (
107
+ '<option value=" ' .$ customerGroup .'" selected="selected">Wholesale</option> ' ,
108
+ $ content ,
109
+ 'The Customer Group specified for the chosen customer should be selected. '
110
+ );
111
+
112
+ self ::assertContains (
113
+ 'value=" ' .$ customer ->getEmail ().'" ' ,
114
+ $ content ,
115
+ 'The Customer Email specified for the chosen customer should be input '
116
+ );
91
117
}
92
118
93
119
/**
94
120
* Tests a case when user defined custom attribute has default value.
95
121
*
96
- * @magentoDataFixture Magento/Customer/_files/customer.php
97
- * @magentoConfigFixture current_store customer/create_account/default_group 3
122
+ * @magentoDataFixture Magento/Store/_files/core_second_third_fixturestore.php
123
+ * @magentoConfigFixture current_store customer/create_account/default_group 2
124
+ * @magentoConfigFixture secondstore_store customer/create_account/default_group 3
98
125
*/
99
126
public function testGetFormWithUserDefinedAttribute ()
100
127
{
128
+ /** @var \Magento\Store\Model\StoreManagerInterface $storeManager */
129
+ $ storeManager = Bootstrap::getObjectManager ()->get (\Magento \Store \Model \StoreManagerInterface::class);
130
+ $ secondStore = $ storeManager ->getStore ('secondstore ' );
131
+
132
+ $ quoteSession = $ this ->objectManager ->get (SessionQuote::class);
133
+ $ quoteSession ->setStoreId ($ secondStore ->getId ());
134
+
101
135
$ formFactory = $ this ->getFormFactoryMock ();
102
136
$ this ->objectManager ->addSharedInstance ($ formFactory , FormFactory::class);
103
137
104
138
/** @var LayoutInterface $layout */
105
139
$ layout = $ this ->objectManager ->get (LayoutInterface::class);
106
- $ accountBlock = $ layout ->createBlock (Account::class, 'address_block ' . rand ());
140
+ $ accountBlock = $ layout ->createBlock (
141
+ Account::class,
142
+ 'address_block ' . rand ()
143
+ );
107
144
108
145
$ form = $ accountBlock ->getForm ();
109
146
$ form ->setUseContainer (true );
@@ -116,7 +153,7 @@ public function testGetFormWithUserDefinedAttribute()
116
153
);
117
154
118
155
self ::assertContains (
119
- '<option value="3" selected="selected">Customer Group 1 </option> ' ,
156
+ '<option value="3" selected="selected">Retailer </option> ' ,
120
157
$ content ,
121
158
'The Customer Group specified for the chosen store should be selected. '
122
159
);
@@ -162,13 +199,13 @@ private function createCustomerGroupAttribute(): AttributeMetadataInterface
162
199
{
163
200
/** @var Option $option1 */
164
201
$ option1 = $ this ->objectManager ->create (Option::class);
165
- $ option1 ->setValue (3 );
166
- $ option1 ->setLabel ('Customer Group 1 ' );
202
+ $ option1 ->setValue (2 );
203
+ $ option1 ->setLabel ('Wholesale ' );
167
204
168
205
/** @var Option $option2 */
169
206
$ option2 = $ this ->objectManager ->create (Option::class);
170
- $ option2 ->setValue (4 );
171
- $ option2 ->setLabel ('Customer Group 2 ' );
207
+ $ option2 ->setValue (3 );
208
+ $ option2 ->setLabel ('Retailer ' );
172
209
173
210
/** @var AttributeMetadataInterfaceFactory $attributeMetadataFactory */
174
211
$ attributeMetadataFactory = $ this ->objectManager ->create (AttributeMetadataInterfaceFactory::class);
0 commit comments