From 9e545b37faaa584fb4aa4fe4ff7eac908e9fdaef Mon Sep 17 00:00:00 2001 From: Flyingmana Date: Thu, 15 Feb 2024 00:51:13 +0100 Subject: [PATCH 1/2] add unittest for data and datetime --- .../unit/Varien/Data/Form/FilterTest.php | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 dev/tests/unit/Varien/Data/Form/FilterTest.php diff --git a/dev/tests/unit/Varien/Data/Form/FilterTest.php b/dev/tests/unit/Varien/Data/Form/FilterTest.php new file mode 100644 index 00000000000..c02fe3503a6 --- /dev/null +++ b/dev/tests/unit/Varien/Data/Form/FilterTest.php @@ -0,0 +1,77 @@ +assertEquals( + '', + $subject->inputFilter('') + ); + $this->assertEquals( + null, + $subject->inputFilter(null) + ); + $this->assertEquals( + '1990-05-18', + $subject->inputFilter('1990-05-18') + ); + $this->assertEquals( + '0090-05-18', + $subject->inputFilter('90-05-18') + ); + $this->assertEquals( + '1990-05-08', + $subject->inputFilter('1990-5-8') + ); + + try { + $subject->inputFilter('1990-18-18'); + $this->fail('expected a ValueError'); // ValueError: bcsub(): Argument #1 ($num1) is not well-formed + } catch (\ValueError $e) { + $this->assertStringContainsString('bcsub', $e->getMessage()); + } + } + + public function testDateTimeFilter() + { + $subject = new \Varien_Data_Form_Filter_Datetime(null, 'en_US'); + + $this->assertEquals( + '', + $subject->inputFilter('') + ); + $this->assertEquals( + null, + $subject->inputFilter(null) + ); + $this->assertEquals( + '1990-05-18 00:00:00', + $subject->inputFilter('1990-05-18') + ); + $this->assertEquals( + '0090-05-18 00:00:00', + $subject->inputFilter('90-05-18') + ); + $this->assertEquals( + '1990-05-08 00:00:00', + $subject->inputFilter('1990-5-8') + ); + + try { + $subject->inputFilter('1990-18-18'); + $this->fail('expected a ValueError'); // ValueError: bcsub(): Argument #1 ($num1) is not well-formed + } catch (\ValueError $e) { + $this->assertStringContainsString('bcsub', $e->getMessage()); + } + } +} From f71c3e002eff4100a181a19992c9f8c3d200c00a Mon Sep 17 00:00:00 2001 From: Daniel Fahlke Date: Thu, 15 Feb 2024 21:36:55 +0100 Subject: [PATCH 2/2] ad one more testcase to dev/tests/unit/Varien/Data/Form/FilterTest.php Co-authored-by: Ng Kiat Siong --- dev/tests/unit/Varien/Data/Form/FilterTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dev/tests/unit/Varien/Data/Form/FilterTest.php b/dev/tests/unit/Varien/Data/Form/FilterTest.php index c02fe3503a6..1d74b5654e8 100644 --- a/dev/tests/unit/Varien/Data/Form/FilterTest.php +++ b/dev/tests/unit/Varien/Data/Form/FilterTest.php @@ -33,7 +33,11 @@ public function testDateFilter() '1990-05-08', $subject->inputFilter('1990-5-8') ); - + $this->assertEquals( + '1970-01-01', + $subject->inputFilter('1970-01-01') + ); + try { $subject->inputFilter('1990-18-18'); $this->fail('expected a ValueError'); // ValueError: bcsub(): Argument #1 ($num1) is not well-formed