diff --git a/src/Eccube/Form/Type/Admin/CustomerType.php b/src/Eccube/Form/Type/Admin/CustomerType.php index 567af1500bd..b1e48ae07e4 100644 --- a/src/Eccube/Form/Type/Admin/CustomerType.php +++ b/src/Eccube/Form/Type/Admin/CustomerType.php @@ -138,10 +138,10 @@ public function buildForm(FormBuilderInterface $builder, array $options) [ 'required' => false, 'constraints' => [ - new Assert\Regex([ - 'pattern' => "/^\d+$/u", - 'message' => 'form_error.numeric_only', - ]), + new Assert\NotBlank(), + new Assert\Range([ + 'min' => "-".$this->eccubeConfig['eccube_price_max'], + 'max' => $this->eccubeConfig['eccube_price_max']]) ], ] ) diff --git a/src/Eccube/Form/Type/Admin/OrderType.php b/src/Eccube/Form/Type/Admin/OrderType.php index c9e26d50857..d98a637be29 100644 --- a/src/Eccube/Form/Type/Admin/OrderType.php +++ b/src/Eccube/Form/Type/Admin/OrderType.php @@ -189,6 +189,10 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'pattern' => "/^\d+$/u", 'message' => 'form_error.numeric_only', ]), + new Assert\Range([ + 'min' => 0, + 'max' => $this->eccubeConfig['eccube_price_max'] + ]), ], ]) ->add('note', TextareaType::class, [ 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()); + } }