ae70b42dcb
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
106 lines
3.3 KiB
PHP
106 lines
3.3 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Cf7stg\Tests;
|
|
|
|
use Cf7stg\Settings;
|
|
|
|
final class SettingsCounterTest extends Cf7stgTestCase
|
|
{
|
|
public function test_default_counters_are_zero(): void
|
|
{
|
|
$c = Settings::get_drop_counters();
|
|
self::assertSame(0, $c['total']);
|
|
self::assertSame(0, $c['real_today']);
|
|
self::assertSame(0, $c['dry_today']);
|
|
}
|
|
|
|
public function test_increment_real_counter(): void
|
|
{
|
|
Settings::increment_drop_counter('real');
|
|
$c = Settings::get_drop_counters();
|
|
self::assertSame(1, $c['total']);
|
|
self::assertSame(1, $c['real_today']);
|
|
self::assertSame(0, $c['dry_today']);
|
|
}
|
|
|
|
public function test_increment_dry_run_counter(): void
|
|
{
|
|
Settings::increment_drop_counter('dry_run');
|
|
Settings::increment_drop_counter('dry_run');
|
|
$c = Settings::get_drop_counters();
|
|
self::assertSame(2, $c['total']);
|
|
self::assertSame(0, $c['real_today']);
|
|
self::assertSame(2, $c['dry_today']);
|
|
}
|
|
|
|
public function test_rolling_today_to_yesterday_on_date_change(): void
|
|
{
|
|
$yesterday = date('Y-m-d', strtotime('-1 day'));
|
|
update_option(Settings::OPT_DROP_COUNTERS, [
|
|
'total' => 5,
|
|
'real_today' => 5,
|
|
'real_yesterday' => 0,
|
|
'dry_today' => 0,
|
|
'dry_yesterday' => 0,
|
|
'today_date' => $yesterday,
|
|
'reset_at' => $yesterday,
|
|
]);
|
|
|
|
Settings::increment_drop_counter('real');
|
|
$c = Settings::get_drop_counters();
|
|
self::assertSame(date('Y-m-d'), $c['today_date']);
|
|
self::assertSame(5, $c['real_yesterday']);
|
|
self::assertSame(1, $c['real_today']);
|
|
self::assertSame(6, $c['total']);
|
|
}
|
|
|
|
public function test_reset_counters_zeroes_and_updates_reset_at(): void
|
|
{
|
|
Settings::increment_drop_counter('real');
|
|
Settings::increment_drop_counter('dry_run');
|
|
Settings::reset_drop_counters();
|
|
$c = Settings::get_drop_counters();
|
|
self::assertSame(0, $c['total']);
|
|
self::assertSame(0, $c['real_today']);
|
|
self::assertSame(0, $c['dry_today']);
|
|
self::assertSame(date('Y-m-d'), $c['reset_at']);
|
|
}
|
|
|
|
public function test_get_dry_run_drop_default_true_when_unset(): void
|
|
{
|
|
self::assertTrue(Settings::is_dry_run_drop());
|
|
}
|
|
|
|
public function test_get_dry_run_drop_false_when_disabled(): void
|
|
{
|
|
update_option(Settings::OPT_DRY_RUN_DROP, false);
|
|
self::assertFalse(Settings::is_dry_run_drop());
|
|
}
|
|
|
|
public function test_get_drop_score_threshold_default_minus_5(): void
|
|
{
|
|
self::assertSame(-5, Settings::get_drop_score_threshold());
|
|
}
|
|
|
|
public function test_get_hard_drop_enabled_default_true(): void
|
|
{
|
|
self::assertTrue(Settings::is_hard_drop_enabled());
|
|
}
|
|
|
|
public function test_invalid_counters_option_resets_to_defaults(): void
|
|
{
|
|
update_option(Settings::OPT_DROP_COUNTERS, 'broken-string');
|
|
$c = Settings::get_drop_counters();
|
|
self::assertSame(0, $c['total']);
|
|
self::assertArrayHasKey('today_date', $c);
|
|
}
|
|
|
|
public function test_increment_with_invalid_mode_is_noop(): void
|
|
{
|
|
Settings::increment_drop_counter('garbage');
|
|
$c = Settings::get_drop_counters();
|
|
self::assertSame(0, $c['total']);
|
|
}
|
|
}
|