From 9078004b6a2a01f0ceb1ccfcf13da97674f3ac2c Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Thu, 25 Jul 2019 19:14:44 +0300 Subject: [PATCH] graphQl-784: removed validation, added the text convert instead --- .../Model/Cart/QuoteAddressFactory.php | 8 ++--- .../Customer/SetBillingAddressOnCartTest.php | 21 +++++++++-- .../Customer/SetShippingAddressOnCartTest.php | 35 +++++++++++-------- .../Guest/SetBillingAddressOnCartTest.php | 25 ++++++++++--- .../Guest/SetShippingAddressOnCartTest.php | 10 ++++-- 5 files changed, 69 insertions(+), 30 deletions(-) diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/QuoteAddressFactory.php b/app/code/Magento/QuoteGraphQl/Model/Cart/QuoteAddressFactory.php index af45831e61028..3ab93e2f0a19d 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/QuoteAddressFactory.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/QuoteAddressFactory.php @@ -60,12 +60,10 @@ public function __construct( */ public function createBasedOnInputData(array $addressInput): QuoteAddress { - $addressInput['country_id'] = $addressInput['country_code'] ?? ''; - if ($addressInput['country_id'] && !ctype_upper($addressInput['country_code'])) { - throw new GraphQlInputException( - __('"Country Code" cannot contain lowercase characters.') - ); + if ($addressInput['country_code']) { + $addressInput['country_code'] = strtoupper($addressInput['country_code']); } + $addressInput['country_id'] = $addressInput['country_code'] ?? ''; $maxAllowedLineCount = $this->addressHelper->getStreetLines(); if (is_array($addressInput['street']) && count($addressInput['street']) > $maxAllowedLineCount) { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php index a2b2d2e82e602..011930e723273 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php @@ -642,8 +642,6 @@ public function testSetNewBillingAddressWithRedundantStreetLine() * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php - * @expectedException \Exception - * @expectedExceptionMessage "Country Code" cannot contain lowercase characters. */ public function testSetBillingAddressWithLowerCaseCountry() { @@ -673,12 +671,29 @@ public function testSetBillingAddressWithLowerCaseCountry() cart { billing_address { firstname + lastname + company + street + city + postcode + telephone + country { + code + label + } + __typename } } } } QUERY; - $this->graphQlMutation($query, [], '', $this->getHeaderMap()); + $response = $this->graphQlMutation($query, [], '', $this->getHeaderMap()); + + self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']); + $cartResponse = $response['setBillingAddressOnCart']['cart']; + self::assertArrayHasKey('billing_address', $cartResponse); + $billingAddressResponse = $cartResponse['billing_address']; + $this->assertNewAddressFields($billingAddressResponse); } /** diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php index 9f2bb5e2a35d9..15ee125955062 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php @@ -607,8 +607,6 @@ public function testSetShippingAddressToGuestCart() * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php - * @expectedException \Exception - * @expectedExceptionMessage "Country Code" cannot contain lowercase characters. */ public function testSetShippingAddressWithLowerCaseCountry() { @@ -618,20 +616,18 @@ public function testSetShippingAddressWithLowerCaseCountry() mutation { setShippingAddressesOnCart( input: { - cart_id: "$maskedQuoteId" + cart_id: "{$maskedQuoteId}" shipping_addresses: [ { address: { - firstname: "test firstname" - lastname: "test lastname" - company: "test company" - street: ["test street 1", "test street 2"] - city: "test city" - region: "test region" - postcode: "887766" + firstname: "John" + lastname: "Doe" + street: ["6161 West Centinella Avenue"] + city: "Culver City" + region: "CA" + postcode: "90230" country_code: "us" - telephone: "88776655" - save_in_address_book: false + telephone: "555-555-55-55" } } ] @@ -639,13 +635,24 @@ public function testSetShippingAddressWithLowerCaseCountry() ) { cart { shipping_addresses { - firstname + region { + code + } + country { + code + } } } } } QUERY; - $this->graphQlMutation($query, [], '', $this->getHeaderMap()); + $result = $this->graphQlMutation($query, [], '', $this->getHeaderMap()); + + self::assertCount(1, $result['setShippingAddressesOnCart']['cart']['shipping_addresses']); + $address = reset($result['setShippingAddressesOnCart']['cart']['shipping_addresses']); + + $this->assertEquals('US', $address['country']['code']); + $this->assertEquals('CA', $address['region']['code']); } /** diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php index 796beea877f85..730e65b4ba8aa 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php @@ -459,8 +459,6 @@ public function testSetNewBillingAddressRedundantStreetLine() * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php - * @expectedException \Exception - * @expectedExceptionMessage "Country Code" cannot contain lowercase characters. */ public function testSetBillingAddressWithLowerCaseCountry() { @@ -472,7 +470,7 @@ public function testSetBillingAddressWithLowerCaseCountry() input: { cart_id: "$maskedQuoteId" billing_address: { - address: { + address: { firstname: "test firstname" lastname: "test lastname" company: "test company" @@ -483,19 +481,36 @@ public function testSetBillingAddressWithLowerCaseCountry() country_code: "us" telephone: "88776655" save_in_address_book: false - } + } } } ) { cart { billing_address { firstname + lastname + company + street + city + postcode + telephone + country { + code + label + } + __typename } } } } QUERY; - $this->graphQlMutation($query); + $response = $this->graphQlMutation($query); + + self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']); + $cartResponse = $response['setBillingAddressOnCart']['cart']; + self::assertArrayHasKey('billing_address', $cartResponse); + $billingAddressResponse = $cartResponse['billing_address']; + $this->assertNewAddressFields($billingAddressResponse); } /** diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingAddressOnCartTest.php index 553b498d7b9d5..537c8f09a0a98 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingAddressOnCartTest.php @@ -411,8 +411,6 @@ public function testSetShippingAddressOnNonExistentCart() * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php - * @expectedException \Exception - * @expectedExceptionMessage "Country Code" cannot contain lowercase characters. */ public function testSetShippingAddressWithLowerCaseCountry() { @@ -452,7 +450,13 @@ public function testSetShippingAddressWithLowerCaseCountry() } } QUERY; - $this->graphQlMutation($query); + $result = $this->graphQlMutation($query); + + self::assertCount(1, $result['setShippingAddressesOnCart']['cart']['shipping_addresses']); + $address = reset($result['setShippingAddressesOnCart']['cart']['shipping_addresses']); + + $this->assertEquals('US', $address['country']['code']); + $this->assertEquals('CA', $address['region']['code']); } /**