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..d4401088952 --- /dev/null +++ b/tests/unit/Varien/Data/Form/Filter/DateTest.php @@ -0,0 +1,53 @@ +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'); + } catch (Throwable $e) { + // 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 new file mode 100644 index 00000000000..152cfad883a --- /dev/null +++ b/tests/unit/Varien/Data/Form/Filter/DatetimeTest.php @@ -0,0 +1,52 @@ +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'); + } catch (Throwable $e) { + // PHP7: bcsub(): bcmath function argument is not well-formed + // PHP8: bcsub(): Argument #1 ($num1) is not well-formed + $this->assertStringStartsWith('bcsub():', $e->getMessage()); + } + } +}