justReturn([11 => $town_slug]); \Brain\Monkey\Functions\when('get_field')->alias(function ($name) use ($main) { if ($name === 'main_town_slug') return $main; return false; // page_no_rep empty, page_unic empty }); } public function test_add_town_prefix_no_change_when_current_town_equals_main(): void { $this->set_routing_context('spb', 'spb'); self::assertSame('/about/', LinkFilter::add_town_prefix('/about/')); } public function test_add_town_prefix_no_change_when_current_town_is_null(): void { $_SERVER['REQUEST_URI'] = '/random/'; $_SERVER['HTTP_HOST'] = 'site.com'; \Brain\Monkey\Functions\when('get_terms')->justReturn([10 => 'spb']); \Brain\Monkey\Functions\when('get_field')->justReturn(false); self::assertSame('/about/', LinkFilter::add_town_prefix('/about/')); } public function test_add_town_prefix_prepends_town_to_path_only_url(): void { $this->set_routing_context(); self::assertSame('/tyumen/about/', LinkFilter::add_town_prefix('/about/')); } public function test_add_town_prefix_skips_path_already_prefixed(): void { $this->set_routing_context(); self::assertSame('/tyumen/about/', LinkFilter::add_town_prefix('/tyumen/about/')); self::assertSame('/tyumen', LinkFilter::add_town_prefix('/tyumen')); } public function test_add_town_prefix_full_url_same_host(): void { $this->set_routing_context(); self::assertSame( 'https://site.com/tyumen/about/', LinkFilter::add_town_prefix('https://site.com/about/') ); self::assertSame( 'https://site.com/tyumen/', LinkFilter::add_town_prefix('https://site.com/') ); } public function test_add_town_prefix_full_url_already_prefixed_no_double_prefix(): void { $this->set_routing_context(); self::assertSame( 'https://site.com/tyumen/about/', LinkFilter::add_town_prefix('https://site.com/tyumen/about/') ); } public function test_add_town_prefix_external_host_no_change(): void { $this->set_routing_context(); self::assertSame( 'https://external.com/foo/', LinkFilter::add_town_prefix('https://external.com/foo/') ); } public function test_add_town_prefix_non_http_scheme_no_change(): void { $this->set_routing_context(); self::assertSame('mailto:x@y.com', LinkFilter::add_town_prefix('mailto:x@y.com')); self::assertSame('tel:+79991234567', LinkFilter::add_town_prefix('tel:+79991234567')); } public function test_add_town_prefix_respects_page_no_rep_exclusions(): void { $_SERVER['REQUEST_URI'] = '/tyumen/'; $_SERVER['HTTP_HOST'] = 'site.com'; \Brain\Monkey\Functions\when('get_terms')->justReturn([11 => 'tyumen']); \Brain\Monkey\Functions\when('get_field')->alias(function ($name) { if ($name === 'main_town_slug') return 'spb'; if ($name === 'page_no_rep') return [['link' => '/privacy/']]; return false; }); self::assertSame('/privacy/', LinkFilter::add_town_prefix('/privacy/')); } public function test_add_town_prefix_returns_unchanged_when_bypassed(): void { $this->set_routing_context(); $result = \WPMultiCity\Helpers::without_url_filters(function () { return LinkFilter::add_town_prefix('/about/'); }); self::assertSame('/about/', $result); } public function test_filter_acf_load_value_returns_array_unchanged(): void { $this->set_routing_context(); self::assertSame( ['a', 'b'], LinkFilter::filter_acf_load_value(['a', 'b']) ); } }