Files
opensourcepos/tests/Helpers/LocaleHelperTest.php
T
objecttothisandClaude Sonnet 5 af48fa4357 fix(tests): standardize DB bootstrap/OSPOS mocking, fix stale-prefix bug (#4771)
Adds DatabaseBootstrapTrait and OsposConfigFixtureTrait to replace
duplicated per-file setUp()/tearDown() bootstrap and OSPOS config mock
boilerplate across test classes, bringing them in line with the
ItemsControllerTest gold-standard shape.

Fixes the real root cause of tabular_helperTest's suite-order-dependent
failure: dropAllForeignKeyConstraints()/foreignKeyExists()/
dropColumnIfExists() temporarily blank the shared connection's DBPrefix
via overridePrefix() but never restored it if the query between the two
calls threw (e.g. migration_helperTest's mocked-failure tests) -
permanently corrupting prefixed table lookups for the rest of the
process. Wrapped each in try/finally. Also widens executeScript() to
accept an explicit connection so migration SQL can't silently run
against the wrong DB group.

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-23 10:10:37 +04:00

61 lines
1.5 KiB
PHP

<?php
namespace Tests\Helpers;
use CodeIgniter\Test\CIUnitTestCase;
use Tests\Support\OsposConfigFixtureTrait;
class LocaleHelperTest extends CIUnitTestCase
{
use OsposConfigFixtureTrait;
protected function setUp(): void
{
parent::setUp();
require_once __DIR__ . '/../../app/Helpers/locale_helper.php';
$this->injectOsposSettings(['dateformat' => 'Y-m-d']);
}
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'));
}
}