|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Sales\Test\Unit\Block\Adminhtml\Order\Address; |
| 8 | + |
| 9 | +/** |
| 10 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
| 11 | + */ |
| 12 | +class FormTest extends \PHPUnit\Framework\TestCase |
| 13 | +{ |
| 14 | + /** |
| 15 | + * @var \Magento\Sales\Block\Adminhtml\Order\Address\Form |
| 16 | + */ |
| 17 | + private $addressBlock; |
| 18 | + |
| 19 | + /** |
| 20 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 21 | + */ |
| 22 | + private $formFactoryMock; |
| 23 | + |
| 24 | + /** |
| 25 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 26 | + */ |
| 27 | + private $customerFormFactoryMock; |
| 28 | + |
| 29 | + /** |
| 30 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 31 | + */ |
| 32 | + private $coreRegistryMock; |
| 33 | + |
| 34 | + /** |
| 35 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 36 | + */ |
| 37 | + private $countriesCollection; |
| 38 | + |
| 39 | + protected function setUp() |
| 40 | + { |
| 41 | + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); |
| 42 | + |
| 43 | + $this->formFactoryMock = $this->createMock(\Magento\Framework\Data\FormFactory::class); |
| 44 | + $this->customerFormFactoryMock = $this->createMock(\Magento\Customer\Model\Metadata\FormFactory::class); |
| 45 | + $this->coreRegistryMock = $this->createMock(\Magento\Framework\Registry::class); |
| 46 | + $this->countriesCollection = $this->createMock( |
| 47 | + \Magento\Directory\Model\ResourceModel\Country\Collection::class |
| 48 | + ); |
| 49 | + |
| 50 | + $this->addressBlock = $objectManager->getObject( |
| 51 | + \Magento\Sales\Block\Adminhtml\Order\Address\Form::class, |
| 52 | + [ |
| 53 | + '_formFactory' => $this->formFactoryMock, |
| 54 | + '_customerFormFactory' => $this->customerFormFactoryMock, |
| 55 | + '_coreRegistry' => $this->coreRegistryMock, |
| 56 | + 'countriesCollection' => $this->countriesCollection, |
| 57 | + ] |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + public function testGetForm() |
| 62 | + { |
| 63 | + $formMock = $this->createMock(\Magento\Framework\Data\Form::class); |
| 64 | + $fieldsetMock = $this->createMock(\Magento\Framework\Data\Form\Element\Fieldset::class); |
| 65 | + $addressFormMock = $this->createMock(\Magento\Customer\Model\Metadata\Form::class); |
| 66 | + $addressMock = $this->createMock(\Magento\Sales\Model\Order\Address::class); |
| 67 | + $selectMock = $this->createMock(\Magento\Framework\Data\Form\Element\Select::class); |
| 68 | + $orderMock = $this->createMock(\Magento\Sales\Model\Order::class); |
| 69 | + |
| 70 | + $this->formFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($formMock); |
| 71 | + $formMock->expects($this->atLeastOnce())->method('addFieldset')->willReturn($fieldsetMock); |
| 72 | + $this->customerFormFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($addressFormMock); |
| 73 | + $addressFormMock->expects($this->atLeastOnce())->method('getAttributes')->willReturn([]); |
| 74 | + $this->coreRegistryMock->expects($this->atLeastOnce())->method('registry')->willReturn($addressMock); |
| 75 | + $formMock->expects($this->atLeastOnce())->method('getElement')->willReturnOnConsecutiveCalls( |
| 76 | + $selectMock, |
| 77 | + $selectMock, |
| 78 | + $selectMock, |
| 79 | + $selectMock, |
| 80 | + $selectMock, |
| 81 | + $selectMock, |
| 82 | + $selectMock, |
| 83 | + null |
| 84 | + ); |
| 85 | + $addressMock->expects($this->once())->method('getOrder')->willReturn($orderMock); |
| 86 | + $orderMock->expects($this->once())->method('getStoreId')->willReturn(5); |
| 87 | + $this->countriesCollection->expects($this->atLeastOnce())->method('loadByStore') |
| 88 | + ->willReturn($this->countriesCollection); |
| 89 | + |
| 90 | + $this->addressBlock->getForm(); |
| 91 | + } |
| 92 | +} |
0 commit comments