Skip to content

Commit b9b1859

Browse files
committed
test(admin): cover translation picker page url helpers
Adds 9 cases against MslsTranslationPickerPage's static helpers: - page_slug() composes msls-translation-picker-<post_type> - parent_slug() returns 'edit.php' for 'post', edit.php?post_type=X otherwise, and '' for empty input - url() routes through admin_url + add_query_arg - save_per_page_option() sanitises ints, falls back to PER_PAGE_DEFAULT for non-positive values, and is a no-op for unrelated options
1 parent ecdad06 commit b9b1859

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php declare( strict_types=1 );
2+
3+
namespace lloc\MslsTests;
4+
5+
use Brain\Monkey\Functions;
6+
use lloc\Msls\MslsTranslationPickerPage;
7+
8+
final class TestMslsTranslationPickerPage extends MslsUnitTestCase {
9+
10+
public function test_page_slug_includes_post_type(): void {
11+
$this->assertSame( 'msls-translation-picker-post', MslsTranslationPickerPage::page_slug( 'post' ) );
12+
$this->assertSame( 'msls-translation-picker-page', MslsTranslationPickerPage::page_slug( 'page' ) );
13+
$this->assertSame( 'msls-translation-picker-event', MslsTranslationPickerPage::page_slug( 'event' ) );
14+
}
15+
16+
public function test_parent_slug_for_built_in_post(): void {
17+
$this->assertSame( 'edit.php', MslsTranslationPickerPage::parent_slug( 'post' ) );
18+
}
19+
20+
public function test_parent_slug_for_other_post_types(): void {
21+
$this->assertSame( 'edit.php?post_type=page', MslsTranslationPickerPage::parent_slug( 'page' ) );
22+
$this->assertSame( 'edit.php?post_type=event', MslsTranslationPickerPage::parent_slug( 'event' ) );
23+
}
24+
25+
public function test_parent_slug_for_empty_post_type(): void {
26+
$this->assertSame( '', MslsTranslationPickerPage::parent_slug( '' ) );
27+
}
28+
29+
public function test_url_uses_admin_url_and_query_arg(): void {
30+
Functions\expect( 'admin_url' )
31+
->once()
32+
->with( 'edit.php' )
33+
->andReturn( 'https://example.tld/wp-admin/edit.php' );
34+
35+
Functions\expect( 'add_query_arg' )
36+
->once()
37+
->andReturnUsing(
38+
function ( $args, $url ) {
39+
return $url . '?' . http_build_query( $args );
40+
}
41+
);
42+
43+
$result = MslsTranslationPickerPage::url( 'post' );
44+
45+
$this->assertSame(
46+
'https://example.tld/wp-admin/edit.php?page=msls-translation-picker-post',
47+
$result
48+
);
49+
}
50+
51+
public function test_url_for_non_post_post_type_routes_through_typed_parent(): void {
52+
Functions\expect( 'admin_url' )
53+
->once()
54+
->with( 'edit.php?post_type=page' )
55+
->andReturn( 'https://example.tld/wp-admin/edit.php?post_type=page' );
56+
57+
Functions\expect( 'add_query_arg' )
58+
->once()
59+
->andReturnUsing(
60+
function ( $args, $url ) {
61+
return $url . '&' . http_build_query( $args );
62+
}
63+
);
64+
65+
$result = MslsTranslationPickerPage::url( 'page' );
66+
67+
$this->assertSame(
68+
'https://example.tld/wp-admin/edit.php?post_type=page&page=msls-translation-picker-page',
69+
$result
70+
);
71+
}
72+
73+
public function test_save_per_page_option_returns_int_for_picker_option(): void {
74+
$this->assertSame(
75+
42,
76+
MslsTranslationPickerPage::save_per_page_option( false, 'msls_tp_per_page', '42' )
77+
);
78+
}
79+
80+
public function test_save_per_page_option_falls_back_for_non_positive(): void {
81+
$this->assertSame(
82+
MslsTranslationPickerPage::PER_PAGE_DEFAULT,
83+
MslsTranslationPickerPage::save_per_page_option( false, 'msls_tp_per_page', '0' )
84+
);
85+
}
86+
87+
public function test_save_per_page_option_passes_through_other_options(): void {
88+
$this->assertFalse(
89+
MslsTranslationPickerPage::save_per_page_option( false, 'unrelated_option', '5' )
90+
);
91+
}
92+
}

0 commit comments

Comments
 (0)