Skip to content
New issue

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

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

Already on GitHub? # to your account

Added unittest for date and datetime #3833

Merged
merged 2 commits into from
Feb 17, 2024
Merged
Changes from 1 commit
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
77 changes: 77 additions & 0 deletions dev/tests/unit/Varien/Data/Form/FilterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?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')
);

Flyingmana marked this conversation as resolved.
Show resolved Hide resolved
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