feat(wpmc S4): Helpers::page_unic_swap with per-request cache
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user