Files
opensourcepos/tests/Helpers/LocaleHelperTest.php
objecttothis 09e2c945fb test: replace OsposConfigFixtureTrait with Appconfig model persistence
- Remove OsposConfigFixtureTrait usage across test suite; settings are
  now written through model(Appconfig::class)->batch_save() instead of
  mocking the OSPOS config object directly
- OSPOSRulesTest keeps direct Config\OSPOS injection via
  Factories::injectMock since it tests config-object behavior directly
- CashupControllerTest, ItemKitsControllerTest, GetItemDataRowTest,
  LocaleHelperTest, export_helperTest, tabular_helperTest switch to
  real DB-backed settings via Appconfig model
- GetItemDataRowTest, LocaleHelperTest, export_helperTest,
  tabular_helperTest add DatabaseTestTrait/DatabaseBootstrapTrait and
  migrate/seed config plus resetDatabaseOnce() in setUp()
- export_helperTest consolidates redundant parent::setUp() calls
  scattered across individual test methods into a single call

This aligns tests with how settings are actually read at runtime
(DB-backed Appconfig) rather than relying on a config-mocking fixture
trait, reducing drift between test setup and production behavior.

Signed-off-by: objecttothis <17935339+objecttothis@users.noreply.github.com>
2026-10-23 15:36:11 +04:00

72 lines
1.8 KiB
PHP

<?php
namespace Tests\Helpers;
use App\Models\Appconfig;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\DatabaseTestTrait;
use Tests\Support\DatabaseBootstrapTrait;
class LocaleHelperTest extends CIUnitTestCase
{
use DatabaseTestTrait;
use DatabaseBootstrapTrait;
protected $migrate = true;
protected $migrateOnce = true;
protected $seedOnce = true;
protected $refresh = false;
protected $namespace = null;
protected function setUp(): void
{
$this->resetDatabaseOnce();
parent::setUp();
require_once __DIR__ . '/../../app/Helpers/locale_helper.php';
model(Appconfig::class)->batch_save(['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'));
}
}