From 22b845d1891a59f73d2063af094a23ef3b9aa7ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AE=E3=81=B6?= Date: Wed, 31 Aug 2022 14:59:58 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E3=83=9D=E3=82=A4=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=81=AB=E6=9C=80=E5=A4=A7=E9=95=B7=E3=83=81=E3=82=A7=E3=83=83?= =?UTF-8?q?=E3=82=AF=E3=82=92=E5=85=A5=E3=82=8C=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Form/Type/Admin/CustomerType.php | 12 ++---------- src/Eccube/Form/Type/Admin/OrderType.php | 8 +------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/Eccube/Form/Type/Admin/CustomerType.php b/src/Eccube/Form/Type/Admin/CustomerType.php index 567af1500bd..b919e234a13 100644 --- a/src/Eccube/Form/Type/Admin/CustomerType.php +++ b/src/Eccube/Form/Type/Admin/CustomerType.php @@ -25,6 +25,7 @@ use Eccube\Form\Type\PostalType; use Eccube\Form\Type\RepeatedPasswordType; use Eccube\Form\Validator\Email; +use Eccube\Form\Type\PriceType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\BirthdayType; use Symfony\Component\Form\Extension\Core\Type\EmailType; @@ -134,16 +135,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ]) ->add( 'point', - NumberType::class, - [ - 'required' => false, - 'constraints' => [ - new Assert\Regex([ - 'pattern' => "/^\d+$/u", - 'message' => 'form_error.numeric_only', - ]), - ], - ] + PriceType::class ) ->add('note', TextareaType::class, [ 'required' => false, diff --git a/src/Eccube/Form/Type/Admin/OrderType.php b/src/Eccube/Form/Type/Admin/OrderType.php index c9e26d50857..f2b11b1e017 100644 --- a/src/Eccube/Form/Type/Admin/OrderType.php +++ b/src/Eccube/Form/Type/Admin/OrderType.php @@ -182,14 +182,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) ->add('charge', PriceType::class, [ 'required' => false, ]) - ->add('use_point', NumberType::class, [ + ->add('use_point', PriceType::class, [ 'required' => true, - 'constraints' => [ - new Assert\Regex([ - 'pattern' => "/^\d+$/u", - 'message' => 'form_error.numeric_only', - ]), - ], ]) ->add('note', TextareaType::class, [ 'required' => false, From 835af3443d0313d398f6a7b53b5e52462d20bbb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AE=E3=81=B6?= Date: Wed, 31 Aug 2022 15:29:17 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=81=AE?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Entity/Customer.php | 2 +- src/Eccube/Form/Type/Admin/CustomerType.php | 12 +++++- src/Eccube/Form/Type/Admin/OrderType.php | 12 +++++- .../Form/Type/Admin/CustomerTypeTest.php | 42 +++++++++++++++++++ .../Tests/Form/Type/Admin/OrderTypeTest.php | 17 ++++++++ 5 files changed, 81 insertions(+), 4 deletions(-) diff --git a/src/Eccube/Entity/Customer.php b/src/Eccube/Entity/Customer.php index 611414b58d4..0ac158b80d1 100644 --- a/src/Eccube/Entity/Customer.php +++ b/src/Eccube/Entity/Customer.php @@ -196,7 +196,7 @@ class Customer extends \Eccube\Entity\AbstractEntity implements UserInterface, \ /** * @var string * - * @ORM\Column(name="point", type="decimal", precision=12, scale=0, options={"unsigned":false,"default":0}) + * @ORM\Column(name="point", type="decimal", precision=12, scale=0, options={"unsigned":true,"default":0}) */ private $point = '0'; diff --git a/src/Eccube/Form/Type/Admin/CustomerType.php b/src/Eccube/Form/Type/Admin/CustomerType.php index b919e234a13..b1e48ae07e4 100644 --- a/src/Eccube/Form/Type/Admin/CustomerType.php +++ b/src/Eccube/Form/Type/Admin/CustomerType.php @@ -25,7 +25,6 @@ use Eccube\Form\Type\PostalType; use Eccube\Form\Type\RepeatedPasswordType; use Eccube\Form\Validator\Email; -use Eccube\Form\Type\PriceType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\BirthdayType; use Symfony\Component\Form\Extension\Core\Type\EmailType; @@ -135,7 +134,16 @@ public function buildForm(FormBuilderInterface $builder, array $options) ]) ->add( 'point', - PriceType::class + NumberType::class, + [ + 'required' => false, + 'constraints' => [ + new Assert\NotBlank(), + new Assert\Range([ + 'min' => "-".$this->eccubeConfig['eccube_price_max'], + 'max' => $this->eccubeConfig['eccube_price_max']]) + ], + ] ) ->add('note', TextareaType::class, [ 'required' => false, diff --git a/src/Eccube/Form/Type/Admin/OrderType.php b/src/Eccube/Form/Type/Admin/OrderType.php index f2b11b1e017..d98a637be29 100644 --- a/src/Eccube/Form/Type/Admin/OrderType.php +++ b/src/Eccube/Form/Type/Admin/OrderType.php @@ -182,8 +182,18 @@ public function buildForm(FormBuilderInterface $builder, array $options) ->add('charge', PriceType::class, [ 'required' => false, ]) - ->add('use_point', PriceType::class, [ + ->add('use_point', NumberType::class, [ 'required' => true, + 'constraints' => [ + new Assert\Regex([ + 'pattern' => "/^\d+$/u", + 'message' => 'form_error.numeric_only', + ]), + new Assert\Range([ + 'min' => 0, + 'max' => $this->eccubeConfig['eccube_price_max'] + ]), + ], ]) ->add('note', TextareaType::class, [ 'required' => false, diff --git a/tests/Eccube/Tests/Form/Type/Admin/CustomerTypeTest.php b/tests/Eccube/Tests/Form/Type/Admin/CustomerTypeTest.php index e88476a7ad2..1c2fc57c434 100644 --- a/tests/Eccube/Tests/Form/Type/Admin/CustomerTypeTest.php +++ b/tests/Eccube/Tests/Form/Type/Admin/CustomerTypeTest.php @@ -48,6 +48,7 @@ class CustomerTypeTest extends \Eccube\Tests\Form\Type\AbstractTypeTestCase ], 'status' => 1, 'note' => 'note', + 'point' => '0', ]; protected function setUp(): void @@ -284,4 +285,45 @@ public function testInvalidNoteBlank() $this->form->submit($this->formData); $this->assertTrue($this->form->isValid()); } + + + public function testInvalidPointPlus() + { + $this->formData['point'] = '123'; + + $this->form->submit($this->formData); + $this->assertTrue($this->form->isValid()); + } + + public function testInvalidPointMinus() + { + $this->formData['point'] = '-123'; + + $this->form->submit($this->formData); + $this->assertTrue($this->form->isValid()); + } + + public function testInvalidPointBlank() + { + $this->formData['point'] = ''; + + $this->form->submit($this->formData); + $this->assertFalse($this->form->isValid()); + } + + public function testInvalidPointMin() + { + $this->formData['point'] = '-1234567890123'; + + $this->form->submit($this->formData); + $this->assertFalse($this->form->isValid()); + } + + public function testInvalidPointMax() + { + $this->formData['point'] = '1234567890123'; + + $this->form->submit($this->formData); + $this->assertFalse($this->form->isValid()); + } } diff --git a/tests/Eccube/Tests/Form/Type/Admin/OrderTypeTest.php b/tests/Eccube/Tests/Form/Type/Admin/OrderTypeTest.php index 25b64734287..901d1116958 100644 --- a/tests/Eccube/Tests/Form/Type/Admin/OrderTypeTest.php +++ b/tests/Eccube/Tests/Form/Type/Admin/OrderTypeTest.php @@ -41,6 +41,7 @@ class OrderTypeTest extends \Eccube\Tests\Form\Type\AbstractTypeTestCase 'phone_number' => '012-345-6789', 'email' => 'default@example.com', 'discount' => '1', + 'use_point' => '', 'delivery_fee_total' => '1', 'charge' => '1', 'Payment' => '1', // dtb_payment? @@ -176,4 +177,20 @@ public function testInvalidPostalCodeToLong() $this->form->submit($this->formData); $this->assertFalse($this->form['postal_code']->isValid()); } + + + public function testInValidUsePointHasMinus() + { + $this->formData['use_point'] = '-12345'; + + $this->form->submit($this->formData); + $this->assertFalse($this->form['use_point']->isValid()); + } + + public function testInvalidUsePointToLong() + { + $this->formData['use_point'] = '1234567890123'; + $this->form->submit($this->formData); + $this->assertFalse($this->form['use_point']->isValid()); + } } From e3ea3c1abb8451e8c6b3f9bdfe112fe5dfb25064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AE=E3=81=B6?= Date: Wed, 31 Aug 2022 15:38:33 +0900 Subject: [PATCH 3/3] miss --- src/Eccube/Entity/Customer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Eccube/Entity/Customer.php b/src/Eccube/Entity/Customer.php index 0ac158b80d1..611414b58d4 100644 --- a/src/Eccube/Entity/Customer.php +++ b/src/Eccube/Entity/Customer.php @@ -196,7 +196,7 @@ class Customer extends \Eccube\Entity\AbstractEntity implements UserInterface, \ /** * @var string * - * @ORM\Column(name="point", type="decimal", precision=12, scale=0, options={"unsigned":true,"default":0}) + * @ORM\Column(name="point", type="decimal", precision=12, scale=0, options={"unsigned":false,"default":0}) */ private $point = '0';