From 41afedae7eff707a22fb2722867591715da60ae2 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Thu, 19 Sep 2024 03:43:00 +0200 Subject: [PATCH 1/3] Backport PR 3833 --- .../unit/Varien/Data/Form/Filter/DateTest.php | 52 +++++++++++++++++++ .../Varien/Data/Form/Filter/DatetimeTest.php | 51 ++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 tests/unit/Varien/Data/Form/Filter/DateTest.php create mode 100644 tests/unit/Varien/Data/Form/Filter/DatetimeTest.php diff --git a/tests/unit/Varien/Data/Form/Filter/DateTest.php b/tests/unit/Varien/Data/Form/Filter/DateTest.php new file mode 100644 index 00000000000..0c54d004a50 --- /dev/null +++ b/tests/unit/Varien/Data/Form/Filter/DateTest.php @@ -0,0 +1,52 @@ +subject = new Varien_Data_Form_Filter_Date(null, 'en_US'); + } + + /** + * @group Varien_Data + */ + public function testInputFilter(): void + { + $this->assertEquals('', $this->subject->inputFilter('')); + $this->assertEquals(null, $this->subject->inputFilter(null)); + $this->assertEquals('1990-05-18', $this->subject->inputFilter('1990-05-18')); + $this->assertEquals('0090-05-18', $this->subject->inputFilter('90-05-18')); + $this->assertEquals('1990-05-08', $this->subject->inputFilter('1990-5-8')); + $this->assertEquals('1970-01-01', $this->subject->inputFilter('1970-01-01')); + + try { + $this->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()); + } + } +} diff --git a/tests/unit/Varien/Data/Form/Filter/DatetimeTest.php b/tests/unit/Varien/Data/Form/Filter/DatetimeTest.php new file mode 100644 index 00000000000..80ec884e9c4 --- /dev/null +++ b/tests/unit/Varien/Data/Form/Filter/DatetimeTest.php @@ -0,0 +1,51 @@ +subject = new Varien_Data_Form_Filter_Datetime(null, 'en_US'); + } + + /** + * @group Varien_Data + */ + public function testInputFilter(): void + { + $this->assertEquals('', $this->subject->inputFilter('')); + $this->assertEquals(null, $this->subject->inputFilter(null)); + $this->assertEquals('1990-05-18 00:00:00', $this->subject->inputFilter('1990-05-18')); + $this->assertEquals('0090-05-18 00:00:00', $this->subject->inputFilter('90-05-18')); + $this->assertEquals('1990-05-08 00:00:00', $this->subject->inputFilter('1990-5-8')); + + try { + $this->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 e8ef466b5a9794dfef5c9df6f69bec6745721588 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Thu, 19 Sep 2024 05:11:09 +0200 Subject: [PATCH 2/3] Updated tests --- tests/unit/Varien/Data/Form/Filter/DateTest.php | 9 +++++---- tests/unit/Varien/Data/Form/Filter/DatetimeTest.php | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/unit/Varien/Data/Form/Filter/DateTest.php b/tests/unit/Varien/Data/Form/Filter/DateTest.php index 0c54d004a50..ecf6a4a1de3 100644 --- a/tests/unit/Varien/Data/Form/Filter/DateTest.php +++ b/tests/unit/Varien/Data/Form/Filter/DateTest.php @@ -18,7 +18,7 @@ namespace OpenMage\Tests\Unit\Varien\Data\Form\Filter; use PHPUnit\Framework\TestCase; -use ValueError; +use Throwable; use Varien_Data_Form_Filter_Date; class DateTest extends TestCase @@ -44,9 +44,10 @@ public function testInputFilter(): void try { $this->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()); + } catch (Throwable $e) { + // PHP7: bcsub(): Argument #1 ($num1) is not well-formed + // PHP8: bcsub(): bcmath function argument is not well-formed + $this->assertStringStartsWith('bcsub():', $e->getMessage()); } } } diff --git a/tests/unit/Varien/Data/Form/Filter/DatetimeTest.php b/tests/unit/Varien/Data/Form/Filter/DatetimeTest.php index 80ec884e9c4..6c6b899a754 100644 --- a/tests/unit/Varien/Data/Form/Filter/DatetimeTest.php +++ b/tests/unit/Varien/Data/Form/Filter/DatetimeTest.php @@ -18,7 +18,7 @@ namespace OpenMage\Tests\Unit\Varien\Data\Form\Filter; use PHPUnit\Framework\TestCase; -use ValueError; +use Throwable; use Varien_Data_Form_Filter_Datetime; class DatetimeTest extends TestCase @@ -43,9 +43,10 @@ public function testInputFilter(): void try { $this->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()); + } catch (Throwable $e) { + // PHP7: bcsub(): Argument #1 ($num1) is not well-formed + // PHP8: bcsub(): bcmath function argument is not well-formed + $this->assertStringStartsWith('bcsub():', $e->getMessage()); } } } From f6183f5122297f957b3f45faf89553ced6b36ae9 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Thu, 19 Sep 2024 05:15:25 +0200 Subject: [PATCH 3/3] Typo --- tests/unit/Varien/Data/Form/Filter/DateTest.php | 4 ++-- tests/unit/Varien/Data/Form/Filter/DatetimeTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/Varien/Data/Form/Filter/DateTest.php b/tests/unit/Varien/Data/Form/Filter/DateTest.php index ecf6a4a1de3..d4401088952 100644 --- a/tests/unit/Varien/Data/Form/Filter/DateTest.php +++ b/tests/unit/Varien/Data/Form/Filter/DateTest.php @@ -45,8 +45,8 @@ public function testInputFilter(): void try { $this->subject->inputFilter('1990-18-18'); } catch (Throwable $e) { - // PHP7: bcsub(): Argument #1 ($num1) is not well-formed - // PHP8: bcsub(): bcmath function argument is not well-formed + // PHP7: bcsub(): bcmath function argument is not well-formed + // PHP8: bcsub(): Argument #1 ($num1) is not well-formed $this->assertStringStartsWith('bcsub():', $e->getMessage()); } } diff --git a/tests/unit/Varien/Data/Form/Filter/DatetimeTest.php b/tests/unit/Varien/Data/Form/Filter/DatetimeTest.php index 6c6b899a754..152cfad883a 100644 --- a/tests/unit/Varien/Data/Form/Filter/DatetimeTest.php +++ b/tests/unit/Varien/Data/Form/Filter/DatetimeTest.php @@ -44,8 +44,8 @@ public function testInputFilter(): void try { $this->subject->inputFilter('1990-18-18'); } catch (Throwable $e) { - // PHP7: bcsub(): Argument #1 ($num1) is not well-formed - // PHP8: bcsub(): bcmath function argument is not well-formed + // PHP7: bcsub(): bcmath function argument is not well-formed + // PHP8: bcsub(): Argument #1 ($num1) is not well-formed $this->assertStringStartsWith('bcsub():', $e->getMessage()); } }