test(wpmc S3): current_town fallback + filter + memoization coverage
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -65,4 +65,68 @@ final class HelpersTest extends TestCase
|
|||||||
|
|
||||||
self::assertSame('tyumen', Helpers::current_town());
|
self::assertSame('tyumen', Helpers::current_town());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_current_town_returns_null_when_uri_does_not_match_and_no_filter(): void
|
||||||
|
{
|
||||||
|
$_SERVER['REQUEST_URI'] = '/some-random-page/';
|
||||||
|
|
||||||
|
\Brain\Monkey\Functions\expect('get_terms')
|
||||||
|
->andReturn([10 => 'spb', 11 => 'tyumen']);
|
||||||
|
|
||||||
|
self::assertNull(Helpers::current_town());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_current_town_uses_main_town_slug_filter_when_uri_has_no_match(): void
|
||||||
|
{
|
||||||
|
$_SERVER['REQUEST_URI'] = '/';
|
||||||
|
|
||||||
|
\Brain\Monkey\Functions\expect('get_terms')
|
||||||
|
->andReturn([10 => 'spb', 11 => 'tyumen']);
|
||||||
|
\Brain\Monkey\Filters\expectApplied('wpmc_main_town_slug')
|
||||||
|
->once()
|
||||||
|
->with(null)
|
||||||
|
->andReturn('spb');
|
||||||
|
|
||||||
|
self::assertSame('spb', Helpers::current_town());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_current_town_uri_match_wins_over_main_town_filter(): void
|
||||||
|
{
|
||||||
|
$_SERVER['REQUEST_URI'] = '/tyumen/';
|
||||||
|
|
||||||
|
\Brain\Monkey\Functions\expect('get_terms')
|
||||||
|
->andReturn([10 => 'spb', 11 => 'tyumen']);
|
||||||
|
// main_town filter should not be consulted when URI matches.
|
||||||
|
\Brain\Monkey\Filters\expectApplied('wpmc_main_town_slug')->never();
|
||||||
|
|
||||||
|
self::assertSame('tyumen', Helpers::current_town());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_current_town_slug_filter_overrides_final_value(): void
|
||||||
|
{
|
||||||
|
$_SERVER['REQUEST_URI'] = '/';
|
||||||
|
|
||||||
|
\Brain\Monkey\Functions\expect('get_terms')
|
||||||
|
->andReturn([]);
|
||||||
|
\Brain\Monkey\Filters\expectApplied('wpmc_current_town_slug')
|
||||||
|
->once()
|
||||||
|
->andReturn('override-slug');
|
||||||
|
|
||||||
|
self::assertSame('override-slug', Helpers::current_town());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_current_town_memoizes_within_request(): void
|
||||||
|
{
|
||||||
|
$_SERVER['REQUEST_URI'] = '/tyumen/';
|
||||||
|
|
||||||
|
\Brain\Monkey\Functions\expect('get_terms')
|
||||||
|
->once()
|
||||||
|
->andReturn([10 => 'spb', 11 => 'tyumen']);
|
||||||
|
|
||||||
|
Helpers::current_town();
|
||||||
|
Helpers::current_town();
|
||||||
|
Helpers::current_town();
|
||||||
|
|
||||||
|
self::assertTrue(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user