From 0c6070fd9e6d576f1d3c23b1a7b67274fa4b56ce Mon Sep 17 00:00:00 2001
From: Amr Ezzat <3mr3zzat@gmail.com>
Date: Fri, 27 Dec 2019 16:56:31 +0200
Subject: [PATCH 1/3] Add Validation on Customer Gender
---
.../validation/customer/UpdateCustomerRequest.xml | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/src/Resources/config/validation/customer/UpdateCustomerRequest.xml b/src/Resources/config/validation/customer/UpdateCustomerRequest.xml
index d126e047e..4a31b9e14 100644
--- a/src/Resources/config/validation/customer/UpdateCustomerRequest.xml
+++ b/src/Resources/config/validation/customer/UpdateCustomerRequest.xml
@@ -37,6 +37,16 @@
+
+
+
+
+
+
From 185c7d881456981294005f55542d2c9793ed22e0 Mon Sep 17 00:00:00 2001
From: Amr Ezzat <3mr3zzat@gmail.com>
Date: Mon, 30 Dec 2019 22:54:22 +0200
Subject: [PATCH 2/3] Add Validation Message Translation
---
.../config/validation/customer/UpdateCustomerRequest.xml | 2 +-
src/Resources/translations/validators.en.yml | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/Resources/config/validation/customer/UpdateCustomerRequest.xml b/src/Resources/config/validation/customer/UpdateCustomerRequest.xml
index 4a31b9e14..616226e9b 100644
--- a/src/Resources/config/validation/customer/UpdateCustomerRequest.xml
+++ b/src/Resources/config/validation/customer/UpdateCustomerRequest.xml
@@ -43,7 +43,7 @@
m
f
-
+
diff --git a/src/Resources/translations/validators.en.yml b/src/Resources/translations/validators.en.yml
index bdcd2d6d4..19cbe2460 100644
--- a/src/Resources/translations/validators.en.yml
+++ b/src/Resources/translations/validators.en.yml
@@ -34,3 +34,5 @@ sylius:
verification_token:
not_blank: Please provide a token.
not_exists: The token does not exist.
+ gender:
+ not_valid: Please enter a valid gender
From 9dc55c2f967ecb7aef5c1108e00e6219e06c033c Mon Sep 17 00:00:00 2001
From: Amr Ezzat <3mr3zzat@gmail.com>
Date: Mon, 30 Dec 2019 22:55:21 +0200
Subject: [PATCH 3/3] Add Tests
---
.../Customer/UpdateCustomerApiTest.php | 24 +++++++++++++++++++
.../customer/validation_empty_data.json | 3 ++-
.../validation_gender_not_valid_response.json | 9 +++++++
3 files changed, 35 insertions(+), 1 deletion(-)
create mode 100644 tests/Responses/Expected/customer/validation_gender_not_valid_response.json
diff --git a/tests/Controller/Customer/UpdateCustomerApiTest.php b/tests/Controller/Customer/UpdateCustomerApiTest.php
index 542337454..e443f3254 100644
--- a/tests/Controller/Customer/UpdateCustomerApiTest.php
+++ b/tests/Controller/Customer/UpdateCustomerApiTest.php
@@ -131,4 +131,28 @@ public function it_does_not_allow_to_update_customer_without_passing_required_da
$response = $this->client->getResponse();
$this->assertResponse($response, 'customer/validation_empty_data', Response::HTTP_BAD_REQUEST);
}
+
+ /**
+ * @test
+ */
+ public function it_does_not_allow_to_update_customer_without_entering_valid_gender(): void
+ {
+ $this->loadFixturesFromFiles(['channel.yml', 'customer.yml']);
+ $this->logInUser('oliver@queen.com', '123password');
+
+ $data =
+ <<client->request('PUT', '/shop-api/me', [], [], self::CONTENT_TYPE_HEADER, $data);
+ $response = $this->client->getResponse();
+ $this->assertResponse($response, 'customer/validation_gender_not_valid_response', Response::HTTP_BAD_REQUEST);
+ }
}
diff --git a/tests/Responses/Expected/customer/validation_empty_data.json b/tests/Responses/Expected/customer/validation_empty_data.json
index 1f2ccf71d..a169ca026 100644
--- a/tests/Responses/Expected/customer/validation_empty_data.json
+++ b/tests/Responses/Expected/customer/validation_empty_data.json
@@ -11,7 +11,8 @@
"Last name must be at least 2 characters long."
],
"gender": [
- "Please choose your gender."
+ "Please choose your gender.",
+ "Please enter a valid gender"
]
}
}
diff --git a/tests/Responses/Expected/customer/validation_gender_not_valid_response.json b/tests/Responses/Expected/customer/validation_gender_not_valid_response.json
new file mode 100644
index 000000000..8856339ae
--- /dev/null
+++ b/tests/Responses/Expected/customer/validation_gender_not_valid_response.json
@@ -0,0 +1,9 @@
+{
+ "code": 400,
+ "message": "Validation failed",
+ "errors": {
+ "gender": [
+ "Please enter a valid gender"
+ ]
+ }
+}