-
Notifications
You must be signed in to change notification settings - Fork 60
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 #68 from FatchipRobert/MAG2-2-Unit-tests
MAG2-2 Final checkin of the unit tests
- Loading branch information
Showing
18 changed files
with
1,760 additions
and
12 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?php | ||
|
||
/** | ||
* PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* PAYONE Magento 2 Connector is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* PHP version 5 | ||
* | ||
* @category Payone | ||
* @package Payone_Magento2_Plugin | ||
* @author FATCHIP GmbH <[email protected]> | ||
* @copyright 2003 - 2017 Payone GmbH | ||
* @license <http://www.gnu.org/licenses/> GNU Lesser General Public License | ||
* @link http://www.payone.de | ||
*/ | ||
|
||
namespace Payone\Core\Test\Unit\Model\Api; | ||
|
||
use Payone\Core\Model\Api\Invoice as ClassToTest; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use Payone\Core\Helper\Toolkit; | ||
use Payone\Core\Model\Api\Request\Authorization; | ||
use Magento\Sales\Model\Order; | ||
use Magento\Sales\Model\Order\Item; | ||
|
||
class InvoiceTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var ClassToTest | ||
*/ | ||
private $classToTest; | ||
|
||
/** | ||
* @var Toolkit | ||
*/ | ||
private $toolkitHelper; | ||
|
||
protected function setUp() | ||
{ | ||
$objectManager = new ObjectManager($this); | ||
|
||
$this->toolkitHelper = $this->getMockBuilder(Toolkit::class)->disableOriginalConstructor()->getMock(); | ||
$this->toolkitHelper->method('getInvoiceAppendix')->willReturn('invoice appendix'); | ||
$this->toolkitHelper->method('getConfigParam')->willReturn('sku'); | ||
$this->toolkitHelper->expects($this->any()) | ||
->method('formatNumber') | ||
->willReturnMap([ | ||
[100, 2, '100.00'], | ||
[5, 2, '5.00'], | ||
[-5, 2, '-5.00'], | ||
[90, 2, '90.00'], | ||
[105, 2, '105.00'], | ||
]); | ||
|
||
$this->classToTest = $objectManager->getObject(ClassToTest::class, [ | ||
'toolkitHelper' => $this->toolkitHelper | ||
]); | ||
} | ||
|
||
/** | ||
* Returns item mock object | ||
* | ||
* @return \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private function getItemMock() | ||
{ | ||
$item = $this->getMockBuilder(Item::class)->disableOriginalConstructor()->getMock(); | ||
$item->method('isDummy')->willReturn(false); | ||
$item->method('getProductId')->willReturn('12345'); | ||
$item->method('getQtyOrdered')->willReturn('1'); | ||
$item->method('getSku')->willReturn('test_123'); | ||
$item->method('getPriceInclTax')->willReturn('100'); | ||
$item->method('getName')->willReturn('Test product'); | ||
$item->method('getTaxPercent')->willReturn('19'); | ||
return $item; | ||
} | ||
|
||
public function testAddProductInfo() | ||
{ | ||
$authorization = $this->getMockBuilder(Authorization::class)->disableOriginalConstructor()->getMock(); | ||
|
||
$items = [$this->getItemMock()]; | ||
|
||
$expected = 90; | ||
|
||
$order = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); | ||
$order->method('getAllItems')->willReturn($items); | ||
$order->method('getBaseShippingInclTax')->willReturn(-5); | ||
$order->method('getBaseDiscountAmount')->willReturn(-5); | ||
$order->method('getCouponCode')->willReturn('test'); | ||
$order->method('getGrandTotal')->willReturn($expected); | ||
|
||
$result = $this->classToTest->addProductInfo($authorization, $order, false); | ||
$this->assertEquals($expected, $result); | ||
} | ||
|
||
public function testAddProductInfoSurcharge() | ||
{ | ||
$authorization = $this->getMockBuilder(Authorization::class)->disableOriginalConstructor()->getMock(); | ||
|
||
$items = [$this->getItemMock()]; | ||
|
||
$expected = 100; | ||
|
||
$order = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); | ||
$order->method('getAllItems')->willReturn($items); | ||
$order->method('getBaseShippingInclTax')->willReturn(5); | ||
$order->method('getBaseDiscountAmount')->willReturn(-5); | ||
$order->method('getCouponCode')->willReturn('test'); | ||
$order->method('getGrandTotal')->willReturn($expected); | ||
|
||
$positions = ['12345' => ['amount' => '1']]; | ||
|
||
$result = $this->classToTest->addProductInfo($authorization, $order, $positions); | ||
$this->assertEquals($expected, $result); | ||
} | ||
} |
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,204 @@ | ||
<?php | ||
|
||
/** | ||
* PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* PAYONE Magento 2 Connector is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* PHP version 5 | ||
* | ||
* @category Payone | ||
* @package Payone_Magento2_Plugin | ||
* @author FATCHIP GmbH <[email protected]> | ||
* @copyright 2003 - 2017 Payone GmbH | ||
* @license <http://www.gnu.org/licenses/> GNU Lesser General Public License | ||
* @link http://www.payone.de | ||
*/ | ||
|
||
namespace Payone\Core\Test\Unit\Model\Api\Request; | ||
|
||
use Magento\Quote\Model\Quote\Address; | ||
use Payone\Core\Model\Api\Request\Addresscheck as ClassToTest; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use Payone\Core\Helper\Api; | ||
use Payone\Core\Model\ResourceModel\CheckedAddresses; | ||
use Payone\Core\Helper\Shop; | ||
|
||
class AddresscheckTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var ClassToTest | ||
*/ | ||
private $classToTest; | ||
|
||
/** | ||
* @var Api|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $apiHelper; | ||
|
||
/** | ||
* @var CheckedAddresses|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $addressesChecked; | ||
|
||
/** | ||
* @var Shop|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $shopHelper; | ||
|
||
protected function setUp() | ||
{ | ||
$objectManager = new ObjectManager($this); | ||
|
||
$this->apiHelper = $this->getMockBuilder(Api::class)->disableOriginalConstructor()->getMock(); | ||
|
||
$this->addressesChecked = $this->getMockBuilder(CheckedAddresses::class)->disableOriginalConstructor()->getMock(); | ||
$this->shopHelper = $this->getMockBuilder(Shop::class)->disableOriginalConstructor()->getMock(); | ||
|
||
$this->classToTest = $objectManager->getObject(ClassToTest::class, [ | ||
'apiHelper' => $this->apiHelper, | ||
'shopHelper' => $this->shopHelper, | ||
'addressesChecked' => $this->addressesChecked | ||
]); | ||
} | ||
|
||
public function testSendRequestTrueNotEnabled() | ||
{ | ||
$address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock(); | ||
|
||
$this->shopHelper->method('getConfigParam')->willReturn(false); | ||
|
||
$result = $this->classToTest->sendRequest($address, true); | ||
$this->assertTrue($result); | ||
} | ||
|
||
public function testSendRequestTrueNoBilling() | ||
{ | ||
$address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock(); | ||
|
||
$this->shopHelper->expects($this->any()) | ||
->method('getConfigParam') | ||
->willReturnMap([ | ||
['enabled', 'address_check', 'payone_protect', null, true], | ||
['check_billing', 'address_check', 'payone_protect', null, 'NO'] | ||
]); | ||
|
||
$result = $this->classToTest->sendRequest($address, true); | ||
$this->assertTrue($result); | ||
} | ||
|
||
public function testSendRequestTrueNoShipping() | ||
{ | ||
$address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock(); | ||
|
||
$this->shopHelper->expects($this->any()) | ||
->method('getConfigParam') | ||
->willReturnMap([ | ||
['enabled', 'address_check', 'payone_protect', null, true], | ||
['check_shipping', 'address_check', 'payone_protect', null, 'NO'] | ||
]); | ||
|
||
$result = $this->classToTest->sendRequest($address, false); | ||
$this->assertTrue($result); | ||
} | ||
|
||
public function testSendRequestInvalidTypePE() | ||
{ | ||
$address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock(); | ||
$address->method('getCountryId')->willReturn('FR'); | ||
|
||
$this->shopHelper->expects($this->any()) | ||
->method('getConfigParam') | ||
->willReturnMap([ | ||
['enabled', 'address_check', 'payone_protect', null, true], | ||
['check_shipping', 'address_check', 'payone_protect', null, 'PE'] | ||
]); | ||
|
||
$result = $this->classToTest->sendRequest($address, false); | ||
$expected = ['wrongCountry' => true]; | ||
$this->assertEquals($expected, $result); | ||
} | ||
|
||
public function testSendRequestInvalidTypeBA() | ||
{ | ||
$address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock(); | ||
$address->method('getCountryId')->willReturn('XY'); | ||
|
||
$this->shopHelper->expects($this->any()) | ||
->method('getConfigParam') | ||
->willReturnMap([ | ||
['enabled', 'address_check', 'payone_protect', null, true], | ||
['check_shipping', 'address_check', 'payone_protect', null, 'BA'] | ||
]); | ||
|
||
$result = $this->classToTest->sendRequest($address, false); | ||
$expected = ['wrongCountry' => true]; | ||
$this->assertEquals($expected, $result); | ||
} | ||
|
||
public function testSendRequestNotChecked() | ||
{ | ||
$address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock(); | ||
$address->method('getCountryId')->willReturn('DE'); | ||
$address->method('getFirstname')->willReturn('Paul'); | ||
$address->method('getLastname')->willReturn('Paytest'); | ||
$address->method('getCompany')->willReturn('Testcompany Ltd.'); | ||
$address->method('getStreet')->willReturn(['Teststr. 5', '1st floor']); | ||
$address->method('getPostcode')->willReturn('12345'); | ||
$address->method('getCity')->willReturn('Berlin'); | ||
$address->method('getRegionCode')->willReturn('Berlin'); | ||
|
||
$this->shopHelper->expects($this->any()) | ||
->method('getConfigParam') | ||
->willReturnMap([ | ||
['enabled', 'address_check', 'payone_protect', null, true], | ||
['check_shipping', 'address_check', 'payone_protect', null, 'PE'], | ||
['mode', 'address_check', 'payone_protect', null, 'test'], | ||
['aid', 'global', 'payone_general', null, 'PE'] | ||
]); | ||
|
||
$this->addressesChecked->method('wasAddressCheckedBefore')->willReturn(false); | ||
|
||
$response = ['status' => 'VALID']; | ||
$this->apiHelper->method('sendApiRequest')->willReturn($response); | ||
|
||
$result = $this->classToTest->sendRequest($address, false); | ||
$this->assertEquals($response, $result); | ||
} | ||
|
||
public function testSendRequestChecked() | ||
{ | ||
$address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock(); | ||
$address->method('getCountryId')->willReturn('DE'); | ||
$address->method('getFirstname')->willReturn('Paul'); | ||
$address->method('getLastname')->willReturn('Paytest'); | ||
$address->method('getCompany')->willReturn('Testcompany Ltd.'); | ||
$address->method('getStreet')->willReturn(['Teststr. 5', '1st floor']); | ||
$address->method('getPostcode')->willReturn('12345'); | ||
$address->method('getCity')->willReturn('Berlin'); | ||
$address->method('getRegionCode')->willReturn('Berlin'); | ||
|
||
$this->shopHelper->expects($this->any()) | ||
->method('getConfigParam') | ||
->willReturnMap([ | ||
['enabled', 'address_check', 'payone_protect', null, true], | ||
['check_shipping', 'address_check', 'payone_protect', null, 'PE'], | ||
['mode', 'address_check', 'payone_protect', null, 'test'], | ||
['aid', 'global', 'payone_general', null, 'PE'] | ||
]); | ||
|
||
$this->addressesChecked->method('wasAddressCheckedBefore')->willReturn(true); | ||
|
||
$result = $this->classToTest->sendRequest($address, false); | ||
$this->assertTrue($result); | ||
} | ||
} |
Oops, something went wrong.