-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(PT-13134): Prevent call create order with an empty cart
- Loading branch information
1 parent
dc8aefe
commit afc1e35
Showing
10 changed files
with
194 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
/** | ||
* (c) shopware AG <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SwagPaymentPayPalUnified\Controllers\Frontend\Exceptions; | ||
|
||
use Exception; | ||
|
||
class EmptyCartException extends Exception | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct('Cannot create a PayPal order with an empty cart'); | ||
} | ||
} |
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
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
106 changes: 106 additions & 0 deletions
106
...Frontend/AbstractPayPalPaymentControllerThrowsExceptionOnCreateOrderWithEmptyCartTest.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 | ||
/** | ||
* (c) shopware AG <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SwagPaymentPayPalUnified\Tests\Functional\Controller\Frontend; | ||
|
||
use Enlight_Controller_Action; | ||
use Enlight_Controller_Response_ResponseHttp; | ||
use Generator; | ||
use Shopware_Controllers_Frontend_PaypalUnifiedApm; | ||
use Shopware_Controllers_Frontend_PaypalUnifiedV2; | ||
use Shopware_Controllers_Frontend_PaypalUnifiedV2PayUponInvoice; | ||
use Shopware_Controllers_Widgets_PaypalUnifiedV2AdvancedCreditDebitCard; | ||
use Shopware_Controllers_Widgets_PaypalUnifiedV2SmartPaymentButtons; | ||
use SwagPaymentPayPalUnified\Tests\Functional\AssertLocationTrait; | ||
use SwagPaymentPayPalUnified\Tests\Functional\ContainerTrait; | ||
use SwagPaymentPayPalUnified\Tests\Functional\ShopRegistrationTrait; | ||
use SwagPaymentPayPalUnified\Tests\Unit\PaypalPaymentControllerTestCase; | ||
|
||
class AbstractPayPalPaymentControllerThrowsExceptionOnCreateOrderWithEmptyCartTest extends PaypalPaymentControllerTestCase | ||
{ | ||
use ContainerTrait; | ||
use ShopRegistrationTrait; | ||
use AssertLocationTrait; | ||
|
||
/** | ||
* @dataProvider createPayPalOrderShouldThrowExceptionWithEmptyCartDataProvider | ||
* | ||
* @param class-string<Enlight_Controller_Action> $controllerClass | ||
* @param string $actionName | ||
* | ||
* @return void | ||
*/ | ||
public function testCreatePayPalOrderShouldThrowExceptionWithEmptyCart($controllerClass, $actionName, bool $shouldAssignToView) | ||
{ | ||
$sOrderVariables = [ | ||
'sUserData' => require __DIR__ . '/_fixtures/getUser_result.php', | ||
'sBasket' => ['content' => []], | ||
]; | ||
|
||
$session = $this->getContainer()->get('session'); | ||
$session->set('sOrderVariables', $sOrderVariables); | ||
|
||
$controller = $this->getController( | ||
$controllerClass, | ||
[ | ||
self::SERVICE_DEPENDENCY_PROVIDER => $this->getContainer()->get('paypal_unified.dependency_provider'), | ||
self::SERVICE_ORDER_PARAMETER_FACADE => $this->getContainer()->get('paypal_unified.paypal_order_parameter_facade'), | ||
], | ||
null, | ||
new Enlight_Controller_Response_ResponseHttp() | ||
); | ||
|
||
$controller->$actionName(); | ||
|
||
if ($shouldAssignToView) { | ||
$result = $controller->View()->getAssign('redirectTo'); | ||
|
||
static::assertStringEndsWith('checkout/cart', $result); | ||
|
||
return; | ||
} | ||
|
||
static::assertLocationEndsWith($controller->Response(), 'checkout/cart'); | ||
} | ||
|
||
/** | ||
* @return Generator<array<int,mixed>> | ||
*/ | ||
public function createPayPalOrderShouldThrowExceptionWithEmptyCartDataProvider() | ||
{ | ||
yield 'Shopware_Controllers_Frontend_PaypalUnifiedV2' => [ | ||
Shopware_Controllers_Frontend_PaypalUnifiedV2::class, | ||
'indexAction', | ||
true, | ||
]; | ||
|
||
yield 'Shopware_Controllers_Widgets_PaypalUnifiedV2AdvancedCreditDebitCard' => [ | ||
Shopware_Controllers_Widgets_PaypalUnifiedV2AdvancedCreditDebitCard::class, | ||
'createOrderAction', | ||
true, | ||
]; | ||
|
||
yield 'Shopware_Controllers_Widgets_PaypalUnifiedV2SmartPaymentButtons' => [ | ||
Shopware_Controllers_Widgets_PaypalUnifiedV2SmartPaymentButtons::class, | ||
'createOrderAction', | ||
true, | ||
]; | ||
|
||
yield 'Shopware_Controllers_Frontend_PaypalUnifiedApm' => [ | ||
Shopware_Controllers_Frontend_PaypalUnifiedApm::class, | ||
'indexAction', | ||
false, | ||
]; | ||
|
||
yield 'Shopware_Controllers_Frontend_PaypalUnifiedV2PayUponInvoice' => [ | ||
Shopware_Controllers_Frontend_PaypalUnifiedV2PayUponInvoice::class, | ||
'indexAction', | ||
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