test(wpmc S4): Router root URL index_town_alt fallback + no-data behaviors
This commit is contained in:
@@ -120,4 +120,50 @@ final class RouterTest extends TestCase
|
||||
self::assertTrue($GLOBALS['wp_query']->is_front_page);
|
||||
self::assertTrue($GLOBALS['wp_query']->is_page);
|
||||
}
|
||||
|
||||
public function test_route_falls_back_to_index_town_alt_option(): void
|
||||
{
|
||||
\Brain\Monkey\Functions\when('is_admin')->justReturn(false);
|
||||
$_SERVER['REQUEST_URI'] = '/tyumen/';
|
||||
\Brain\Monkey\Functions\when('get_terms')->justReturn([11 => 'tyumen']);
|
||||
|
||||
$term = new \WP_Term();
|
||||
$term->term_id = 11;
|
||||
\Brain\Monkey\Functions\when('get_term_by')->justReturn($term);
|
||||
|
||||
\Brain\Monkey\Functions\when('get_field')->alias(function ($name, $where = null) {
|
||||
if ($name === 'main_town_slug') return 'spb';
|
||||
if ($name === 'page_no_rep') return false;
|
||||
if ($name === 'main_page_alt') return 0;
|
||||
if ($name === 'index_town_alt') return 777;
|
||||
return false;
|
||||
});
|
||||
\Brain\Monkey\Functions\when('get_post')->justReturn((object) ['ID' => 777]);
|
||||
\Brain\Monkey\Functions\when('status_header')->justReturn(null);
|
||||
|
||||
Router::route();
|
||||
|
||||
self::assertSame(777, $GLOBALS['wp_query']->constructor_args['page_id']);
|
||||
}
|
||||
|
||||
public function test_route_does_not_install_query_when_neither_main_nor_fallback_set(): void
|
||||
{
|
||||
\Brain\Monkey\Functions\expect('get_post')->never();
|
||||
\Brain\Monkey\Functions\when('is_admin')->justReturn(false);
|
||||
$_SERVER['REQUEST_URI'] = '/tyumen/';
|
||||
\Brain\Monkey\Functions\when('get_terms')->justReturn([11 => 'tyumen']);
|
||||
|
||||
$term = new \WP_Term();
|
||||
$term->term_id = 11;
|
||||
\Brain\Monkey\Functions\when('get_term_by')->justReturn($term);
|
||||
|
||||
\Brain\Monkey\Functions\when('get_field')->alias(function ($name) {
|
||||
if ($name === 'main_town_slug') return 'spb';
|
||||
return false;
|
||||
});
|
||||
|
||||
Router::route();
|
||||
|
||||
self::assertArrayNotHasKey('wp_query', $GLOBALS);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user