feat(wpmc S4): Helpers::page_unic_swap with per-request cache

This commit is contained in:
Vladimir Bryzgalov
2026-05-16 19:22:37 +05:00
parent d122bfacb5
commit d724089b2d
2 changed files with 78 additions and 0 deletions
+46
View File
@@ -265,4 +265,50 @@ final class HelpersTest extends TestCase
self::assertFalse(Helpers::is_routable_path());
}
public function test_page_unic_swap_returns_clone_id_when_row_matches(): void
{
$term = new \WP_Term();
$term->term_id = 11;
$term->slug = 'tyumen';
\Brain\Monkey\Functions\when('get_term_by')->justReturn($term);
\Brain\Monkey\Functions\expect('get_field')
->once()
->with('page_unic', 'option')
->andReturn([
['town' => 10, 'page_old' => 5, 'page_new' => 50],
['town' => 11, 'page_old' => 7, 'page_new' => 70],
]);
self::assertSame(70, Helpers::page_unic_swap(7, 'tyumen'));
}
public function test_page_unic_swap_returns_null_when_no_row_matches(): void
{
$term = new \WP_Term();
$term->term_id = 11;
$term->slug = 'tyumen';
\Brain\Monkey\Functions\when('get_term_by')->justReturn($term);
\Brain\Monkey\Functions\expect('get_field')
->once()
->andReturn([['town' => 10, 'page_old' => 5, 'page_new' => 50]]);
self::assertNull(Helpers::page_unic_swap(7, 'tyumen'));
}
public function test_page_unic_swap_caches_within_request(): void
{
$term = new \WP_Term();
$term->term_id = 11;
\Brain\Monkey\Functions\when('get_term_by')->justReturn($term);
\Brain\Monkey\Functions\expect('get_field')
->once()
->andReturn([['town' => 11, 'page_old' => 7, 'page_new' => 70]]);
Helpers::page_unic_swap(7, 'tyumen');
Helpers::page_unic_swap(7, 'tyumen');
Helpers::page_unic_swap(7, 'tyumen');
self::assertTrue(true);
}
}