|
1 | 1 | <?php |
2 | 2 | /** |
3 | | - * Copyright © Magento, Inc. All rights reserved. |
4 | | - * See COPYING.txt for license details. |
| 3 | + * Copyright 2019 Adobe |
| 4 | + * All Rights Reserved. |
5 | 5 | */ |
| 6 | + |
6 | 7 | declare(strict_types=1); |
7 | 8 |
|
8 | 9 | namespace Magento\GraphQl\Quote\Guest; |
|
15 | 16 | use Magento\Sales\Model\ResourceModel\Order\CollectionFactory; |
16 | 17 | use Magento\TestFramework\Helper\Bootstrap; |
17 | 18 | use Magento\TestFramework\TestCase\GraphQlAbstract; |
| 19 | +use Magento\TestFramework\Fixture\Config; |
| 20 | +use Magento\TestFramework\Fixture\DataFixture; |
| 21 | +use Magento\Catalog\Test\Fixture\Product as ProductFixture; |
18 | 22 |
|
19 | 23 | /** |
20 | 24 | * End to checkout tests for guest |
@@ -86,6 +90,32 @@ public function testCheckoutWorkflow() |
86 | 90 | $this->placeOrder($cartId); |
87 | 91 | } |
88 | 92 |
|
| 93 | + /** |
| 94 | + * Test checkout workflow with null second street in shipping address |
| 95 | + * Validates that null values in street array are properly filtered and don't cause errors |
| 96 | + */ |
| 97 | + #[ |
| 98 | + Config("checkout/options/guest_checkout", "1", "store", "default"), |
| 99 | + DataFixture( |
| 100 | + ProductFixture::class, |
| 101 | + ['price' => 1, 'name' => 'simple1', 'sku' => 'simple1'], |
| 102 | + 'simple1' |
| 103 | + ) |
| 104 | + ] |
| 105 | + public function testCheckoutWithNullSecondStreetInShippingAddress() |
| 106 | + { |
| 107 | + $cartId = $this->createEmptyCart(); |
| 108 | + $this->setGuestEmailOnCart($cartId); |
| 109 | + $this->addProductToCart($cartId, 1, $this->findProduct()); |
| 110 | + |
| 111 | + $shippingMethod = $this->setAndVerifyShippingAddressWithNullSecondStreet($cartId); |
| 112 | + |
| 113 | + $this->setBillingAddress($cartId); |
| 114 | + $paymentMethod = $this->setShippingMethod($cartId, $shippingMethod); |
| 115 | + $this->setPaymentMethod($cartId, $paymentMethod); |
| 116 | + $this->placeOrder($cartId); |
| 117 | + } |
| 118 | + |
89 | 119 | /** |
90 | 120 | * @return string |
91 | 121 | */ |
@@ -397,6 +427,92 @@ private function placeOrder(string $cartId): void |
397 | 427 | self::assertNotEmpty($response['placeOrder']['order']['order_number']); |
398 | 428 | } |
399 | 429 |
|
| 430 | + /** |
| 431 | + * Set shipping address with null second street in address |
| 432 | + * |
| 433 | + * @param string $cartId |
| 434 | + * @return array |
| 435 | + */ |
| 436 | + private function setAndVerifyShippingAddressWithNullSecondStreet(string $cartId): array |
| 437 | + { |
| 438 | + $query = <<<QUERY |
| 439 | + mutation { |
| 440 | + setShippingAddressesOnCart( |
| 441 | + input: { |
| 442 | + cart_id: "$cartId" |
| 443 | + shipping_addresses: [ |
| 444 | + { |
| 445 | + address: { |
| 446 | + firstname: "B" |
| 447 | + lastname: "C" |
| 448 | + street: ["Lorem ipsum dolor sit ame", null] |
| 449 | + city: "PARIS" |
| 450 | + postcode: "56590" |
| 451 | + country_code: "FR" |
| 452 | + telephone: "0601020304" |
| 453 | + save_in_address_book: false |
| 454 | + } |
| 455 | + } |
| 456 | + ] |
| 457 | + } |
| 458 | + ) { |
| 459 | + cart { |
| 460 | + shipping_addresses { |
| 461 | + firstname |
| 462 | + lastname |
| 463 | + company |
| 464 | + street |
| 465 | + city |
| 466 | + postcode |
| 467 | + country { |
| 468 | + code |
| 469 | + label |
| 470 | + } |
| 471 | + telephone |
| 472 | + available_shipping_methods { |
| 473 | + carrier_code |
| 474 | + method_code |
| 475 | + amount { |
| 476 | + value |
| 477 | + } |
| 478 | + } |
| 479 | + } |
| 480 | + } |
| 481 | + } |
| 482 | + } |
| 483 | + QUERY; |
| 484 | + |
| 485 | + $response = $this->graphQlMutation($query); |
| 486 | + |
| 487 | + $this->assertArrayHasKey('setShippingAddressesOnCart', $response); |
| 488 | + $this->assertArrayHasKey('cart', $response['setShippingAddressesOnCart']); |
| 489 | + $this->assertArrayHasKey('shipping_addresses', $response['setShippingAddressesOnCart']['cart']); |
| 490 | + $this->assertCount(1, $response['setShippingAddressesOnCart']['cart']['shipping_addresses']); |
| 491 | + |
| 492 | + $shippingAddress = current($response['setShippingAddressesOnCart']['cart']['shipping_addresses']); |
| 493 | + |
| 494 | + $this->assertEquals('B', $shippingAddress['firstname']); |
| 495 | + $this->assertEquals('C', $shippingAddress['lastname']); |
| 496 | + $this->assertNull($shippingAddress['company']); |
| 497 | + $this->assertEquals(['Lorem ipsum dolor sit ame'], $shippingAddress['street']); |
| 498 | + $this->assertEquals('PARIS', $shippingAddress['city']); |
| 499 | + $this->assertEquals('56590', $shippingAddress['postcode']); |
| 500 | + $this->assertEquals('FR', $shippingAddress['country']['code']); |
| 501 | + $this->assertEquals('FR', $shippingAddress['country']['label']); |
| 502 | + $this->assertEquals('0601020304', $shippingAddress['telephone']); |
| 503 | + |
| 504 | + $this->assertArrayHasKey('available_shipping_methods', $shippingAddress); |
| 505 | + $this->assertGreaterThan(0, count($shippingAddress['available_shipping_methods'])); |
| 506 | + |
| 507 | + $availableShippingMethod = current($shippingAddress['available_shipping_methods']); |
| 508 | + $this->assertArrayHasKey('carrier_code', $availableShippingMethod); |
| 509 | + $this->assertNotEmpty($availableShippingMethod['carrier_code']); |
| 510 | + $this->assertArrayHasKey('method_code', $availableShippingMethod); |
| 511 | + $this->assertNotEmpty($availableShippingMethod['method_code']); |
| 512 | + |
| 513 | + return $availableShippingMethod; |
| 514 | + } |
| 515 | + |
400 | 516 | protected function tearDown(): void |
401 | 517 | { |
402 | 518 | $this->deleteQuote(); |
|
0 commit comments