|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * (c) shopware AG <[email protected]> |
| 4 | + * |
| 5 | + * For the full copyright and license information, please view the LICENSE |
| 6 | + * file that was distributed with this source code. |
| 7 | + */ |
| 8 | + |
| 9 | +namespace SwagPaymentPayPalUnified\Tests\Functional\Controller\Frontend; |
| 10 | + |
| 11 | +use Enlight_Controller_Action; |
| 12 | +use Enlight_Controller_Response_ResponseHttp; |
| 13 | +use Generator; |
| 14 | +use Shopware_Controllers_Frontend_PaypalUnifiedApm; |
| 15 | +use Shopware_Controllers_Frontend_PaypalUnifiedV2; |
| 16 | +use Shopware_Controllers_Frontend_PaypalUnifiedV2PayUponInvoice; |
| 17 | +use Shopware_Controllers_Widgets_PaypalUnifiedV2AdvancedCreditDebitCard; |
| 18 | +use Shopware_Controllers_Widgets_PaypalUnifiedV2SmartPaymentButtons; |
| 19 | +use SwagPaymentPayPalUnified\Tests\Functional\AssertLocationTrait; |
| 20 | +use SwagPaymentPayPalUnified\Tests\Functional\ContainerTrait; |
| 21 | +use SwagPaymentPayPalUnified\Tests\Functional\ShopRegistrationTrait; |
| 22 | +use SwagPaymentPayPalUnified\Tests\Unit\PaypalPaymentControllerTestCase; |
| 23 | + |
| 24 | +class AbstractPayPalPaymentControllerThrowsExceptionOnCreateOrderWithEmptyCartTest extends PaypalPaymentControllerTestCase |
| 25 | +{ |
| 26 | + use ContainerTrait; |
| 27 | + use ShopRegistrationTrait; |
| 28 | + use AssertLocationTrait; |
| 29 | + |
| 30 | + /** |
| 31 | + * @dataProvider createPayPalOrderShouldThrowExceptionWithEmptyCartDataProvider |
| 32 | + * |
| 33 | + * @param class-string<Enlight_Controller_Action> $controllerClass |
| 34 | + * @param string $actionName |
| 35 | + * |
| 36 | + * @return void |
| 37 | + */ |
| 38 | + public function testCreatePayPalOrderShouldThrowExceptionWithEmptyCart($controllerClass, $actionName, bool $shouldAssignToView) |
| 39 | + { |
| 40 | + $sOrderVariables = [ |
| 41 | + 'sUserData' => require __DIR__ . '/_fixtures/getUser_result.php', |
| 42 | + 'sBasket' => ['content' => []], |
| 43 | + ]; |
| 44 | + |
| 45 | + $session = $this->getContainer()->get('session'); |
| 46 | + $session->offsetSet('sOrderVariables', $sOrderVariables); |
| 47 | + |
| 48 | + $controller = $this->getController( |
| 49 | + $controllerClass, |
| 50 | + [ |
| 51 | + self::SERVICE_DEPENDENCY_PROVIDER => $this->getContainer()->get('paypal_unified.dependency_provider'), |
| 52 | + self::SERVICE_ORDER_PARAMETER_FACADE => $this->getContainer()->get('paypal_unified.paypal_order_parameter_facade'), |
| 53 | + ], |
| 54 | + null, |
| 55 | + new Enlight_Controller_Response_ResponseHttp() |
| 56 | + ); |
| 57 | + |
| 58 | + $controller->$actionName(); |
| 59 | + |
| 60 | + if ($shouldAssignToView) { |
| 61 | + $result = $controller->View()->getAssign('redirectTo'); |
| 62 | + |
| 63 | + static::assertStringEndsWith('checkout/cart', $result); |
| 64 | + |
| 65 | + return; |
| 66 | + } |
| 67 | + |
| 68 | + static::assertLocationEndsWith($controller->Response(), 'checkout/cart'); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * @return Generator<array<int,mixed>> |
| 73 | + */ |
| 74 | + public function createPayPalOrderShouldThrowExceptionWithEmptyCartDataProvider() |
| 75 | + { |
| 76 | + yield 'Shopware_Controllers_Frontend_PaypalUnifiedV2' => [ |
| 77 | + Shopware_Controllers_Frontend_PaypalUnifiedV2::class, |
| 78 | + 'indexAction', |
| 79 | + true, |
| 80 | + ]; |
| 81 | + |
| 82 | + yield 'Shopware_Controllers_Widgets_PaypalUnifiedV2AdvancedCreditDebitCard' => [ |
| 83 | + Shopware_Controllers_Widgets_PaypalUnifiedV2AdvancedCreditDebitCard::class, |
| 84 | + 'createOrderAction', |
| 85 | + true, |
| 86 | + ]; |
| 87 | + |
| 88 | + yield 'Shopware_Controllers_Widgets_PaypalUnifiedV2SmartPaymentButtons' => [ |
| 89 | + Shopware_Controllers_Widgets_PaypalUnifiedV2SmartPaymentButtons::class, |
| 90 | + 'createOrderAction', |
| 91 | + true, |
| 92 | + ]; |
| 93 | + |
| 94 | + yield 'Shopware_Controllers_Frontend_PaypalUnifiedApm' => [ |
| 95 | + Shopware_Controllers_Frontend_PaypalUnifiedApm::class, |
| 96 | + 'indexAction', |
| 97 | + false, |
| 98 | + ]; |
| 99 | + |
| 100 | + yield 'Shopware_Controllers_Frontend_PaypalUnifiedV2PayUponInvoice' => [ |
| 101 | + Shopware_Controllers_Frontend_PaypalUnifiedV2PayUponInvoice::class, |
| 102 | + 'indexAction', |
| 103 | + false, |
| 104 | + ]; |
| 105 | + } |
| 106 | +} |
0 commit comments