This repository has been archived by the owner on Aug 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLGMAGTWOS-539: Prevent selection of billing address for Pay After De…
…livery
- Loading branch information
1 parent
453306f
commit ce1790f
Showing
13 changed files
with
342 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace MultiSafepay\Connect\Helper; | ||
|
||
class AddressHelper | ||
{ | ||
/** | ||
* @param $address | ||
* @return bool|string | ||
*/ | ||
public function serializeAddress($address) | ||
{ | ||
return serialize([ | ||
'street' => $address->getStreet(), | ||
'city' => $address->getCity(), | ||
'postcode' => $address->getPostcode() | ||
]); | ||
} | ||
|
||
/** | ||
* @param $shippingAddress | ||
* @param $billingAddress | ||
* @return bool | ||
*/ | ||
public function isSameAddress($shippingAddress, $billingAddress): bool | ||
{ | ||
return $this->serializeAddress($shippingAddress) === $this->serializeAddress($billingAddress); | ||
} | ||
} |
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,121 @@ | ||
<?php | ||
|
||
namespace MultiSafepay\Connect\Test\Integration\Helper; | ||
|
||
use Magento\Sales\Model\Order\Address; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\ObjectManager; | ||
use MultiSafepay\Connect\Helper\AddressHelper; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class AddressHelperTest extends TestCase | ||
{ | ||
/** | ||
* @var \Magento\Framework\App\ObjectManager | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @var AddressHelper | ||
*/ | ||
private $addressHelperInstance; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->objectManager = ObjectManager::getInstance(); | ||
$this->addressHelperInstance = $this->objectManager->get(AddressHelper::class); | ||
} | ||
|
||
/** | ||
* @return Address | ||
*/ | ||
private function getShippingAddress(): Address | ||
{ | ||
/** @var $address Address */ | ||
$address = Bootstrap::getObjectManager()->create(Address::class); | ||
|
||
$address->setRegion('NL') | ||
->setPostcode('1033SC') | ||
->setFirstname('MultiSafepayFirstName') | ||
->setLastname('MultiSafepayLastName') | ||
->setStreet('Kraanspoor 39') | ||
->setCity('Amsterdam') | ||
->setEmail('test@example.com') | ||
->setTelephone('0208500500') | ||
->setCountryId('NL') | ||
->setAddressType('shipping') | ||
->save(); | ||
|
||
return $address; | ||
} | ||
|
||
/** | ||
* @return Address | ||
*/ | ||
private function getBillingAddress(): Address | ||
{ | ||
/** @var $address Address */ | ||
$address = Bootstrap::getObjectManager()->create(Address::class); | ||
|
||
$address->setRegion('CA') | ||
->setPostcode('90210') | ||
->setFirstname('TestFirstName') | ||
->setLastname('TestLastName') | ||
->setStreet('teststreet 50') | ||
->setCity('Beverly Hills') | ||
->setEmail('admin@example.com') | ||
->setTelephone('1111111111') | ||
->setCountryId('US') | ||
->setAddressType('billing') | ||
->save(); | ||
|
||
return $address; | ||
} | ||
|
||
/** | ||
* @param $string | ||
* @return bool | ||
*/ | ||
private function isSerialized($string): bool | ||
{ | ||
return unserialize($string) !== false; | ||
} | ||
|
||
public function testSerializeAddressShouldReturnSerializedAddress() | ||
{ | ||
$address = $this->getShippingAddress(); | ||
|
||
$result = $this->addressHelperInstance->serializeAddress($address); | ||
|
||
$this->assertInternalType('string', $result); | ||
$this->assertTrue($this->isSerialized($result)); | ||
} | ||
|
||
public function testIsSameAddressShouldReturnFalseIfDifferentBillingAndShipping() | ||
{ | ||
$shippingAddress = $this->getShippingAddress(); | ||
$billingAddress = $this->getBillingAddress(); | ||
|
||
$result = $this->addressHelperInstance->isSameAddress($shippingAddress, $billingAddress); | ||
|
||
$this->assertFalse($result); | ||
} | ||
|
||
public function testIsSameAddressShouldReturnTrueIfSameBillingAndShipping() | ||
{ | ||
$shippingAddress = $this->getShippingAddress(); | ||
$billingAddress = $this->getBillingAddress() | ||
->setStreet('Kraanspoor 39') | ||
->setPostcode('1033SC') | ||
->setCity('Amsterdam'); | ||
|
||
$result = $this->addressHelperInstance->isSameAddress($shippingAddress, $billingAddress); | ||
|
||
$this->assertTrue($result); | ||
} | ||
} |
151 changes: 151 additions & 0 deletions
151
Test/Integration/Model/Gateways/BetaalnaontvangstTest.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,151 @@ | ||
<?php | ||
|
||
|
||
namespace MultiSafepay\Connect\Test\Integration\Model\Gateways; | ||
|
||
use Magento\CatalogInventory\Api\StockRegistryInterface; | ||
use Magento\Checkout\Model\Session; | ||
use Magento\Directory\Model\CurrencyFactory; | ||
use Magento\Framework\Api\AttributeValueFactory; | ||
use Magento\Framework\Api\ExtensionAttributesFactory; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\App\ProductMetadataInterface; | ||
use Magento\Framework\App\RequestInterface; | ||
use Magento\Framework\Data\Collection\AbstractDb; | ||
use Magento\Framework\DataObjectFactory; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\Locale\Resolver; | ||
use Magento\Framework\Model\Context; | ||
use Magento\Framework\Model\ResourceModel\AbstractResource; | ||
use Magento\Framework\Module\ModuleListInterface; | ||
use Magento\Framework\Registry; | ||
use Magento\Framework\Stdlib\DateTime\TimezoneInterface; | ||
use Magento\Framework\UrlInterface; | ||
use Magento\Payment\Helper\Data; | ||
use Magento\Payment\Model\Method\Logger; | ||
use Magento\Quote\Model\Quote; | ||
use Magento\Quote\Model\Quote\Address; | ||
use Magento\Sales\Api\InvoiceRepositoryInterface; | ||
use Magento\Sales\Api\OrderRepositoryInterface; | ||
use Magento\Sales\Api\TransactionRepositoryInterface; | ||
use Magento\Sales\Model\Order\Email\Sender\InvoiceSender; | ||
use Magento\Sales\Model\Order\StatusResolver; | ||
use Magento\Sales\Model\OrderNotifier; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Magento\TestFramework\ObjectManager; | ||
use MultiSafepay\Connect\Helper\AddressHelper; | ||
use MultiSafepay\Connect\Helper\Data as HelperData; | ||
use MultiSafepay\Connect\Helper\RefundHelper; | ||
use MultiSafepay\Connect\Model\Api\MspClient; | ||
use MultiSafepay\Connect\Model\Config\Source\Creditcards; | ||
use MultiSafepay\Connect\Model\GatewayRestrictions; | ||
use MultiSafepay\Connect\Model\Gateways\Betaalnaontvangst; | ||
use MultiSafepay\Connect\Model\MultisafepayTokenizationFactory; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class BetaalnaontvangstTest extends TestCase | ||
{ | ||
/** | ||
* @var \Magento\Framework\App\ObjectManager | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @var Betaalnaontvangst | ||
*/ | ||
private $payAfterInstance; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->objectManager = ObjectManager::getInstance(); | ||
|
||
$checkoutSession = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(); | ||
$checkoutSession->method('getQuote')->willReturn($this->createQuote()); | ||
|
||
$this->payAfterInstance = $this->getMockBuilder(Betaalnaontvangst::class)->setConstructorArgs( | ||
[ | ||
$this->objectManager->create(Context::class), | ||
$this->objectManager->create(Registry::class), | ||
$this->objectManager->create(ExtensionAttributesFactory::class), | ||
$this->objectManager->create(AttributeValueFactory::class), | ||
$this->objectManager->create(Data::class), | ||
$this->objectManager->create(ScopeConfigInterface::class), | ||
$this->objectManager->create(Logger::class), | ||
$this->objectManager->create(ModuleListInterface::class), | ||
$this->objectManager->create(TimezoneInterface::class), | ||
$this->objectManager->create(StoreManagerInterface::class), | ||
$checkoutSession, | ||
$this->objectManager->create(UrlInterface::class), | ||
$this->objectManager->create(RequestInterface::class), | ||
$this->objectManager->create(StockRegistryInterface::class), | ||
$this->objectManager->create(InvoiceSender::class), | ||
$this->objectManager->create(ProductMetadataInterface::class), | ||
$this->objectManager->create(InvoiceRepositoryInterface::class), | ||
$this->objectManager->create(TransactionRepositoryInterface::class), | ||
$this->objectManager->create(Resolver::class), | ||
$this->objectManager->create(OrderRepositoryInterface::class), | ||
$this->objectManager->create(OrderNotifier::class), | ||
$this->objectManager->create(StatusResolver::class), | ||
$this->objectManager->create(CurrencyFactory::class), | ||
$this->objectManager->create(MultisafepayTokenizationFactory::class), | ||
$this->objectManager->create(MspClient::class), | ||
$this->objectManager->create(HelperData::class), | ||
$this->objectManager->create(Creditcards::class), | ||
$this->objectManager->create(\Magento\Customer\Model\Session::class), | ||
$this->objectManager->create(RefundHelper::class), | ||
$this->objectManager->create(AddressHelper::class), | ||
$this->objectManager->create(GatewayRestrictions::class), | ||
$this->objectManager->create(DataObjectFactory::class), | ||
$this->getMockBuilder(AbstractResource::class)->disableOriginalConstructor()->getMock(), | ||
$this->getMockBuilder(AbstractDb::class)->disableOriginalConstructor()->getMock(), | ||
] | ||
)->setMethodsExcept(['validate'])->getMock(); | ||
} | ||
|
||
/** | ||
* @return Quote | ||
*/ | ||
protected function createQuote(): Quote | ||
{ | ||
/** @var Address $quoteShippingAddress */ | ||
$quoteShippingAddress = $this->objectManager->create(Address::class); | ||
$quoteShippingAddress->setStreet('Kraanspoor 39') | ||
->setPostcode('1033SC') | ||
->setCity('Amsterdam'); | ||
|
||
/** @var Address $quoteBillingAddress */ | ||
$quoteBillingAddress = $this->objectManager->create(Address::class); | ||
$quoteBillingAddress->setStreet('teststreet 50') | ||
->setPostcode('90210') | ||
->setCity('Beverly Hills'); | ||
|
||
/** @var Quote $quote */ | ||
$quote = $this->objectManager->create(Quote::class); | ||
$quote->setStoreId(1) | ||
->setIsActive(true) | ||
->setIsMultiShipping(false) | ||
->setShippingAddress($quoteShippingAddress) | ||
->setBillingAddress($quoteBillingAddress) | ||
->setCheckoutMethod('customer') | ||
->setReservedOrderId('test_order_1') | ||
->setCustomerEmail('test@example.com') | ||
->setQuoteCurrencyCode('EUR'); | ||
|
||
return $quote; | ||
} | ||
|
||
/** | ||
* @throws LocalizedException | ||
*/ | ||
public function testValidateShouldThrowErrorIfDifferentShippingAndBilling() | ||
{ | ||
$this->expectException(LocalizedException::class); | ||
$this->expectExceptionMessage('This gateway does not allow a different billing and shipping address'); | ||
$this->payAfterInstance->validate(); | ||
} | ||
} |
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
Oops, something went wrong.