Skip to content

Commit

Permalink
MAGETWO-85305: 12560: Back-End issue for multi-store website: when ed…
Browse files Browse the repository at this point in the history
…iting Order shipping/billing address - allowed countries are selected from wrong Store View #982

 - Merge Pull Request magento-engcom/magento2ce#982 from RomaKis/magento2:12560
 - Merged commits:
   1. 41db211
  • Loading branch information
Oleksii Korshenko committed Dec 12, 2017
2 parents a1ee98a + 41db211 commit 5ff7c71
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 3 deletions.
16 changes: 16 additions & 0 deletions app/code/Magento/Sales/Block/Adminhtml/Order/Address/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,20 @@ public function getFormValues()
{
return $this->_getAddress()->getData();
}

/**
* @inheritdoc
*/
protected function processCountryOptions(
\Magento\Framework\Data\Form\Element\AbstractElement $countryElement,
$storeId = null
) {
/** @var \Magento\Sales\Model\Order\Address $address */
$address = $this->_coreRegistry->registry('order_address');
if ($address !== null) {
$storeId = $address->getOrder()->getStoreId();
}

parent::processCountryOptions($countryElement, $storeId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,17 @@ protected function _prepareForm()

/**
* @param \Magento\Framework\Data\Form\Element\AbstractElement $countryElement
* @param string|int $storeId
*
* @return void
*/
private function processCountryOptions(\Magento\Framework\Data\Form\Element\AbstractElement $countryElement)
{
$storeId = $this->getBackendQuoteSession()->getStoreId();
protected function processCountryOptions(
\Magento\Framework\Data\Form\Element\AbstractElement $countryElement,
$storeId = null
) {
if ($storeId === null) {
$storeId = $this->getBackendQuoteSession()->getStoreId();
}
$options = $this->getCountriesCollection()
->loadByStore($storeId)
->toOptionArray();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Sales\Test\Unit\Block\Adminhtml\Order\Address;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class FormTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Sales\Block\Adminhtml\Order\Address\Form
*/
private $addressBlock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $formFactoryMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $customerFormFactoryMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $coreRegistryMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $countriesCollection;

protected function setUp()
{
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);

$this->formFactoryMock = $this->createMock(\Magento\Framework\Data\FormFactory::class);
$this->customerFormFactoryMock = $this->createMock(\Magento\Customer\Model\Metadata\FormFactory::class);
$this->coreRegistryMock = $this->createMock(\Magento\Framework\Registry::class);
$this->countriesCollection = $this->createMock(
\Magento\Directory\Model\ResourceModel\Country\Collection::class
);

$this->addressBlock = $objectManager->getObject(
\Magento\Sales\Block\Adminhtml\Order\Address\Form::class,
[
'_formFactory' => $this->formFactoryMock,
'_customerFormFactory' => $this->customerFormFactoryMock,
'_coreRegistry' => $this->coreRegistryMock,
'countriesCollection' => $this->countriesCollection,
]
);
}

public function testGetForm()
{
$formMock = $this->createMock(\Magento\Framework\Data\Form::class);
$fieldsetMock = $this->createMock(\Magento\Framework\Data\Form\Element\Fieldset::class);
$addressFormMock = $this->createMock(\Magento\Customer\Model\Metadata\Form::class);
$addressMock = $this->createMock(\Magento\Sales\Model\Order\Address::class);
$selectMock = $this->createMock(\Magento\Framework\Data\Form\Element\Select::class);
$orderMock = $this->createMock(\Magento\Sales\Model\Order::class);

$this->formFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($formMock);
$formMock->expects($this->atLeastOnce())->method('addFieldset')->willReturn($fieldsetMock);
$this->customerFormFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($addressFormMock);
$addressFormMock->expects($this->atLeastOnce())->method('getAttributes')->willReturn([]);
$this->coreRegistryMock->expects($this->atLeastOnce())->method('registry')->willReturn($addressMock);
$formMock->expects($this->atLeastOnce())->method('getElement')->willReturnOnConsecutiveCalls(
$selectMock,
$selectMock,
$selectMock,
$selectMock,
$selectMock,
$selectMock,
$selectMock,
null
);
$addressMock->expects($this->once())->method('getOrder')->willReturn($orderMock);
$orderMock->expects($this->once())->method('getStoreId')->willReturn(5);
$this->countriesCollection->expects($this->atLeastOnce())->method('loadByStore')
->willReturn($this->countriesCollection);

$this->addressBlock->getForm();
}
}

0 comments on commit 5ff7c71

Please sign in to comment.