Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unittest for date and datetime #3833

Merged
merged 2 commits into from
Feb 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions dev/tests/unit/Varien/Data/Form/FilterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);

namespace Varien\Data\Form;

use Mage_Core_Helper_String;
use PHPUnit\Framework\TestCase;

class FilterTest extends TestCase
{

public function testDateFilter()
{
$subject = new \Varien_Data_Form_Filter_Date(null, 'en_US');

$this->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')
);
$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
} 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());
}
}
}
Loading