-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix: Check if the shipping address isset #841
- Loading branch information
1 parent
edfeaba
commit ec8d37b
Showing
2 changed files
with
118 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
106 changes: 106 additions & 0 deletions
106
Test/Integration/Service/Order/TransactionPart/LimitStreetLengthTest.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,106 @@ | ||
<?php | ||
/* | ||
* Copyright Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\Payment\Test\Integration\Service\Order\TransactionPart; | ||
|
||
use Magento\Sales\Api\Data\OrderInterface; | ||
use Mollie\Payment\Model\Client\Orders; | ||
use Mollie\Payment\Service\Order\TransactionPart\LimitStreetLength; | ||
use Mollie\Payment\Test\Integration\IntegrationTestCase; | ||
|
||
class LimitStreetLengthTest extends IntegrationTestCase | ||
{ | ||
public function testLimitsTheAddressForOrdersApi(): void | ||
{ | ||
/** @var LimitStreetLength $instance */ | ||
$instance = $this->objectManager->create(LimitStreetLength::class); | ||
|
||
$transaction = [ | ||
'billingAddress' => [ | ||
'streetAndNumber' => 'a super long steet name that exceeds the maximum of 100 characters and should be truncated when its too long', | ||
], | ||
'shippingAddress' => [ | ||
'streetAndNumber' => 'a super long steet name that exceeds the maximum of 100 characters and should be truncated when its too long', | ||
], | ||
]; | ||
|
||
$result = $instance->process( | ||
$this->objectManager->create(OrderInterface::class), | ||
Orders::CHECKOUT_TYPE, | ||
$transaction | ||
); | ||
|
||
$this->assertEquals( | ||
'a super long steet name that exceeds the maximum of 100 characters and should be truncated when its ', | ||
$result['billingAddress']['streetAndNumber'] | ||
); | ||
|
||
$this->assertEquals( | ||
'a super long steet name that exceeds the maximum of 100 characters and should be truncated when its ', | ||
$result['shippingAddress']['streetAndNumber'] | ||
); | ||
|
||
$this->assertArrayHasKey('metadata', $result); | ||
$this->assertArrayHasKey('street_truncated', $result['metadata']); | ||
$this->assertTrue($result['metadata']['street_truncated']); | ||
} | ||
|
||
public function testHandlesVirtualProducts(): void | ||
{ | ||
/** @var LimitStreetLength $instance */ | ||
$instance = $this->objectManager->create(LimitStreetLength::class); | ||
|
||
$transaction = [ | ||
'billingAddress' => [ | ||
'streetAndNumber' => 'a super long steet name that exceeds the maximum of 100 characters and should be truncated when its too long', | ||
], | ||
// Omit the shipping address as that's not relevant for virtual products | ||
]; | ||
|
||
$result = $instance->process( | ||
$this->objectManager->create(OrderInterface::class), | ||
Orders::CHECKOUT_TYPE, | ||
$transaction | ||
); | ||
|
||
$this->assertEquals( | ||
'a super long steet name that exceeds the maximum of 100 characters and should be truncated when its ', | ||
$result['billingAddress']['streetAndNumber'] | ||
); | ||
|
||
$this->assertArrayHasKey('metadata', $result); | ||
$this->assertArrayHasKey('street_truncated', $result['metadata']); | ||
$this->assertTrue($result['metadata']['street_truncated']); | ||
} | ||
|
||
public function testDoesNotMarkAsTruncatedWhenNotTruncated(): void | ||
{ | ||
/** @var LimitStreetLength $instance */ | ||
$instance = $this->objectManager->create(LimitStreetLength::class); | ||
|
||
$transaction = [ | ||
'metadata' => [], | ||
'billingAddress' => [ | ||
'streetAndNumber' => 'a short street name', | ||
], | ||
]; | ||
|
||
$result = $instance->process( | ||
$this->objectManager->create(OrderInterface::class), | ||
Orders::CHECKOUT_TYPE, | ||
$transaction | ||
); | ||
|
||
$this->assertEquals( | ||
'a short street name', | ||
$result['billingAddress']['streetAndNumber'] | ||
); | ||
|
||
$this->assertArrayNotHasKey('street_truncated', $result['metadata']); | ||
} | ||
} |