|
10 | 10 | namespace Magento\Sales\Block\Adminhtml\Order\Create\Form;
|
11 | 11 |
|
12 | 12 | use Magento\Backend\Model\Session\Quote as SessionQuote;
|
| 13 | +use Magento\Customer\Api\CustomerRepositoryInterface; |
13 | 14 | use Magento\Customer\Api\Data\AttributeMetadataInterface;
|
14 | 15 | use Magento\Customer\Api\Data\AttributeMetadataInterfaceFactory;
|
| 16 | +use Magento\Customer\Api\Data\CustomerInterface; |
15 | 17 | use Magento\Customer\Model\Data\Option;
|
16 | 18 | use Magento\Customer\Model\Metadata\Form;
|
17 | 19 | use Magento\Customer\Model\Metadata\FormFactory;
|
18 | 20 | use Magento\Framework\View\LayoutInterface;
|
19 | 21 | use Magento\Quote\Model\Quote;
|
| 22 | +use Magento\Store\Model\StoreManagerInterface; |
20 | 23 | use Magento\TestFramework\Helper\Bootstrap;
|
21 | 24 | use Magento\TestFramework\ObjectManager;
|
22 | 25 | use PHPUnit\Framework\MockObject\MockObject;
|
| 26 | +use PHPUnit\Framework\TestCase; |
23 | 27 |
|
24 | 28 | /**
|
25 | 29 | * Class for test Account
|
26 | 30 | *
|
27 | 31 | * @magentoAppArea adminhtml
|
28 | 32 | * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
29 | 33 | */
|
30 |
| -class AccountTest extends \PHPUnit\Framework\TestCase |
| 34 | +class AccountTest extends TestCase |
31 | 35 | {
|
32 | 36 | /**
|
33 | 37 | * @var Account
|
@@ -81,9 +85,9 @@ public function testGetFormWithCustomer()
|
81 | 85 | );
|
82 | 86 |
|
83 | 87 | $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 */ |
| 88 | + /** @var CustomerRepositoryInterface $customerRepository */ |
| 89 | + $customerRepository = $this->objectManager->get(CustomerRepositoryInterface::class); |
| 90 | + /** @var CustomerInterface $customer */ |
87 | 91 | $customer = $customerRepository->getById($fixtureCustomerId);
|
88 | 92 | $customer->setGroupId($customerGroup);
|
89 | 93 | $customerRepository->save($customer);
|
@@ -125,8 +129,8 @@ public function testGetFormWithCustomer()
|
125 | 129 | */
|
126 | 130 | public function testGetFormWithUserDefinedAttribute()
|
127 | 131 | {
|
128 |
| - /** @var \Magento\Store\Model\StoreManagerInterface $storeManager */ |
129 |
| - $storeManager = Bootstrap::getObjectManager()->get(\Magento\Store\Model\StoreManagerInterface::class); |
| 132 | + /** @var StoreManagerInterface $storeManager */ |
| 133 | + $storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class); |
130 | 134 | $secondStore = $storeManager->getStore('secondstore');
|
131 | 135 |
|
132 | 136 | $quoteSession = $this->objectManager->get(SessionQuote::class);
|
@@ -159,6 +163,46 @@ public function testGetFormWithUserDefinedAttribute()
|
159 | 163 | );
|
160 | 164 | }
|
161 | 165 |
|
| 166 | + /** |
| 167 | + * Test for get form with default customer group |
| 168 | + * |
| 169 | + */ |
| 170 | + public function testGetFormWithDefaultCustomerGroup() |
| 171 | + { |
| 172 | + $customerGroup = 0; |
| 173 | + $quote = $this->objectManager->create(Quote::class); |
| 174 | + $quote->setCustomerGroupId($customerGroup); |
| 175 | + |
| 176 | + $this->session = $this->getMockBuilder(SessionQuote::class) |
| 177 | + ->disableOriginalConstructor() |
| 178 | + ->setMethods(['getCustomerId', 'getQuote']) |
| 179 | + ->getMock(); |
| 180 | + $this->session->method('getQuote') |
| 181 | + ->willReturn($quote); |
| 182 | + $this->session->method('getCustomerId') |
| 183 | + ->willReturn(1); |
| 184 | + |
| 185 | + $formFactory = $this->getFormFactoryMock(); |
| 186 | + $this->objectManager->addSharedInstance($formFactory, FormFactory::class); |
| 187 | + |
| 188 | + /** @var LayoutInterface $layout */ |
| 189 | + $layout = $this->objectManager->get(LayoutInterface::class); |
| 190 | + $accountBlock = $layout->createBlock( |
| 191 | + Account::class, |
| 192 | + 'address_block' . rand(), |
| 193 | + ['sessionQuote' => $this->session] |
| 194 | + ); |
| 195 | + |
| 196 | + $expectedGroupId = 1; |
| 197 | + $form = $accountBlock->getForm(); |
| 198 | + |
| 199 | + self::assertEquals( |
| 200 | + $expectedGroupId, |
| 201 | + $form->getElement('group_id')->getValue(), |
| 202 | + 'The Customer Group specified for the chosen customer should be selected.' |
| 203 | + ); |
| 204 | + } |
| 205 | + |
162 | 206 | /**
|
163 | 207 | * Creates a mock for Form object.
|
164 | 208 | *
|
|
0 commit comments