-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from magento-firedrakes/MAGETWO-44191
[Firedrakes && South] Bugfixes
- Loading branch information
Showing
8 changed files
with
289 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
app/code/Magento/Customer/Test/Unit/Model/CustomerExtractorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Customer\Test\Unit\Model; | ||
|
||
use Magento\Customer\Model\CustomerExtractor; | ||
|
||
class CustomerExtractorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** @var CustomerExtractor */ | ||
protected $customerExtractor; | ||
|
||
/** @var \Magento\Customer\Model\Metadata\FormFactory|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $formFactory; | ||
|
||
/** @var \Magento\Customer\Api\Data\CustomerInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $customerFactory; | ||
|
||
/** @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $storeManager; | ||
|
||
/** @var \Magento\Customer\Api\GroupManagementInterface|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $customerGroupManagement; | ||
|
||
/** @var \Magento\Framework\Api\DataObjectHelper|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $dataObjectHelper; | ||
|
||
/** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $request; | ||
|
||
/** @var \Magento\Customer\Model\Metadata\Form|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $customerForm; | ||
|
||
/** @var \Magento\Customer\Api\Data\CustomerInterface|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $customerData; | ||
|
||
/** @var \Magento\Store\Api\Data\StoreInterface|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $store; | ||
|
||
/** @var \Magento\Customer\Api\Data\GroupInterface|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $customerGroup; | ||
|
||
public function setUp() | ||
{ | ||
$this->formFactory = $this->getMockForAbstractClass( | ||
'Magento\Customer\Model\Metadata\FormFactory', | ||
[], | ||
'', | ||
false, | ||
false, | ||
true, | ||
['create'] | ||
); | ||
$this->customerFactory = $this->getMockForAbstractClass( | ||
'Magento\Customer\Api\Data\CustomerInterfaceFactory', | ||
[], | ||
'', | ||
false, | ||
false, | ||
true, | ||
['create'] | ||
); | ||
$this->storeManager = $this->getMockForAbstractClass( | ||
'Magento\Store\Model\StoreManagerInterface', | ||
[], | ||
'', | ||
false | ||
); | ||
$this->customerGroupManagement = $this->getMockForAbstractClass( | ||
'Magento\Customer\Api\GroupManagementInterface', | ||
[], | ||
'', | ||
false | ||
); | ||
$this->dataObjectHelper = $this->getMock('Magento\Framework\Api\DataObjectHelper', [], [], '', false); | ||
$this->request = $this->getMockForAbstractClass('Magento\Framework\App\RequestInterface', [], '', false); | ||
$this->customerForm = $this->getMock('Magento\Customer\Model\Metadata\Form', [], [], '', false); | ||
$this->customerData = $this->getMockForAbstractClass( | ||
'Magento\Customer\Api\Data\CustomerInterface', | ||
[], | ||
'', | ||
false | ||
); | ||
$this->store = $this->getMockForAbstractClass( | ||
'Magento\Store\Api\Data\StoreInterface', | ||
[], | ||
'', | ||
false | ||
); | ||
$this->customerGroup = $this->getMockForAbstractClass( | ||
'Magento\Customer\Api\Data\GroupInterface', | ||
[], | ||
'', | ||
false | ||
); | ||
$this->customerExtractor = new CustomerExtractor( | ||
$this->formFactory, | ||
$this->customerFactory, | ||
$this->storeManager, | ||
$this->customerGroupManagement, | ||
$this->dataObjectHelper | ||
); | ||
} | ||
|
||
public function testExtract() | ||
{ | ||
$customerData = [ | ||
'firstname' => 'firstname', | ||
'lastname' => 'firstname', | ||
'email' => 'email.example.com', | ||
]; | ||
|
||
$this->formFactory->expects($this->once()) | ||
->method('create') | ||
->with('customer', 'form-code') | ||
->willReturn($this->customerForm); | ||
$this->customerForm->expects($this->once()) | ||
->method('extractData') | ||
->with($this->request) | ||
->willReturn($customerData); | ||
$this->customerForm->expects($this->once()) | ||
->method('getAllowedAttributes') | ||
->willReturn(['group_id' => 'attribute object']); | ||
$this->customerFactory->expects($this->once()) | ||
->method('create') | ||
->willReturn($this->customerData); | ||
$this->dataObjectHelper->expects($this->once()) | ||
->method('populateWithArray') | ||
->with($this->customerData, $customerData, '\Magento\Customer\Api\Data\CustomerInterface') | ||
->willReturn($this->customerData); | ||
$this->storeManager->expects($this->once()) | ||
->method('getStore') | ||
->willReturn($this->store); | ||
$this->store->expects($this->exactly(2)) | ||
->method('getId') | ||
->willReturn(1); | ||
$this->customerGroupManagement->expects($this->once()) | ||
->method('getDefaultGroup') | ||
->with(1) | ||
->willReturn($this->customerGroup); | ||
$this->customerGroup->expects($this->once()) | ||
->method('getId') | ||
->willReturn(1); | ||
$this->customerData->expects($this->once()) | ||
->method('setGroupId') | ||
->with(1); | ||
$this->store->expects($this->once()) | ||
->method('getWebsiteId') | ||
->willReturn(1); | ||
$this->customerData->expects($this->once()) | ||
->method('setWebsiteId') | ||
->with(1); | ||
$this->customerData->expects($this->once()) | ||
->method('setStoreId') | ||
->with(1); | ||
|
||
$this->assertSame($this->customerData, $this->customerExtractor->extract('form-code', $this->request)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
app/code/Magento/Sales/Test/Unit/Block/Order/Create/TotalsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Sales\Test\Unit\Block\Order\Create; | ||
|
||
/** | ||
* Class TotalsTest | ||
*/ | ||
class TotalsTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $shippingAddressMock; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $billingAddressMock; | ||
|
||
/** | ||
* @var \Magento\Sales\Block\Adminhtml\Order\Create\Totals | ||
*/ | ||
protected $totals; | ||
|
||
/** | ||
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager | ||
*/ | ||
protected $helperManager; | ||
|
||
/** | ||
* @var \Magento\Backend\Model\Session\Quote|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $sessionQuoteMock; | ||
|
||
/** | ||
* @var \Magento\Quote\Model\Quote|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $quoteMock; | ||
|
||
/** | ||
* Init | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->helperManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); | ||
$this->sessionQuoteMock = $this->getMockBuilder('Magento\Backend\Model\Session\Quote') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->quoteMock = $this->getMockBuilder('Magento\Quote\Model\Quote') | ||
->disableOriginalConstructor() | ||
->setMethods([ | ||
'setTotalsCollectedFlag', | ||
'collectTotals', | ||
'getTotals', | ||
'isVirtual', | ||
'getBillingAddress', | ||
'getShippingAddress' | ||
]) | ||
->getMock(); | ||
$this->shippingAddressMock = $this->getMockBuilder('Magento\Quote\Model\Quote\Address') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->billingAddressMock = $this->getMockBuilder('Magento\Quote\Model\Quote\Address') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->quoteMock->expects($this->any()) | ||
->method('getBillingAddress') | ||
->willreturn($this->billingAddressMock); | ||
$this->quoteMock->expects($this->any()) | ||
->method('getShippingAddress') | ||
->willreturn($this->shippingAddressMock); | ||
$this->sessionQuoteMock->expects($this->any())->method('getQuote')->willReturn($this->quoteMock); | ||
$this->totals = $this->helperManager->getObject( | ||
'Magento\Sales\Block\Adminhtml\Order\Create\Totals', | ||
['sessionQuote' => $this->sessionQuoteMock] | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider totalsDataProvider | ||
*/ | ||
public function testGetTotals($isVirtual) | ||
{ | ||
$expected = 'expected'; | ||
$this->quoteMock->expects($this->at(0))->method('setTotalsCollectedFlag')->with(false); | ||
$this->quoteMock->expects($this->at(1))->method('collectTotals'); | ||
$this->quoteMock->expects($this->once())->method('isVirtual')->willreturn($isVirtual); | ||
if ($isVirtual) { | ||
$this->billingAddressMock->expects($this->once())->method('getTotals')->willReturn($expected); | ||
} else { | ||
$this->shippingAddressMock->expects($this->once())->method('getTotals')->willReturn($expected); | ||
} | ||
$this->assertEquals($expected, $this->totals->getTotals()); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function totalsDataProvider() | ||
{ | ||
return [ | ||
[true], | ||
[false] | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters