Files
opensourcepos/tests/Helpers/LocaleHelperTest.php
T
BudsieBuds 35fc07e201 refactor(tests): normalize test namespaces to PSR-4 and clean up composer dependencies (#4758)
- Rename tests/helpers/ to tests/Helpers/ and add Tests\Helpers namespace
- Move CI3SecretConverterTest into tests/Libraries/ to eliminate duplicate case-conflict directory
- Map Config\ in composer.json PSR-4 autoloading
- Remove obsolete PHP 7 polyfill (random_compat) and redundant laminas-escaper
- Clean up unused dev dependencies (fakerphp, vfsstream, predis) and update tooling
- Safeguard table prefix restoration in migration_helper and reset config mock in LocaleHelperTest
2026-10-21 19:01:03 +04:00

68 lines
1.6 KiB
PHP

<?php
namespace Tests\Helpers;
use CodeIgniter\Config\Factories;
use CodeIgniter\Test\CIUnitTestCase;
use Config\OSPOS;
class LocaleHelperTest extends CIUnitTestCase
{
protected function setUp(): void
{
parent::setUp();
require_once __DIR__ . '/../../app/Helpers/locale_helper.php';
$config = new OSPOS();
$config->settings = ['dateformat' => 'Y-m-d'];
Factories::injectMock('config', OSPOS::class, $config);
}
protected function tearDown(): void
{
Factories::reset();
parent::tearDown();
}
public function testValidDateReturnsTrue(): void
{
$this->assertTrue(isValidDate('2024-06-10'));
}
public function testInvalidDateFormatReturnsFalse(): void
{
$this->assertFalse(isValidDate('10/06/2024'));
}
public function testImpossibleDateReturnsFalse(): void
{
$this->assertFalse(isValidDate('2024-13-01'));
}
public function testPhpDateOverflowReturnsFalse(): void
{
// PHP silently overflows Feb 30 → Mar 1; the format()===candidate check catches this
$this->assertFalse(isValidDate('2024-02-30'));
}
public function testEmptyStringReturnsFalse(): void
{
$this->assertFalse(isValidDate(''));
}
public function testLeapDayValidReturnsTrue(): void
{
$this->assertTrue(isValidDate('2024-02-29'));
}
public function testLeapDayInvalidYearReturnsFalse(): void
{
$this->assertFalse(isValidDate('2023-02-29'));
}
public function testPartialDateReturnsFalse(): void
{
$this->assertFalse(isValidDate('2024-06'));
}
}