Skip to content

Commit fdadd42

Browse files
committed
Unit tests: Add tests for help_tabs_content()
1 parent a4e79a8 commit fdadd42

3 files changed

Lines changed: 66 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
* Change: Prevent PHP warnings due to missing core-related generated files
7373
* New: Add tests to verify filtered values output nothing when empty
7474
* New: Add test to check that the appropriate number of framework strings are translatable
75+
* New: Add tests for `help_tabs_content()`
7576
* Change: In bootstrap, add backcompat for PHPUnit pre-v6.0
7677
* Fix: Update tests to handle deprecation of core's `print_inline_script()`
7778
* Change: Explicitly define return types for overridden methods

‎TODO.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ The following list comprises ideas, suggestions, and known issues, all of which
55
***This is not a roadmap or a task list.*** Just because something is listed does not necessarily mean it will ever actually get implemented. Some might be bad ideas. Some might be impractical. Some might either not benefit enough users to justify the effort or might negatively impact too many existing users. Or I may not have the time to devote to the task.
66

77
* See if the styles can affect customizer. If so, disable by default (but maybe add a setting to enable for customizer.)
8-
* Unit tests: Add test coverage for: `help_tabs_content()`, `load_config()`, `show_admin_notices()`
8+
* Unit tests: Add test coverage for: `load_config()`, `show_admin_notices()`
99

1010
Feel free to make your own suggestions or champion for something already on the list (via the [plugin's support forum on WordPress.org](https://wordpress.org/support/plugin/add-admin-css/) or on [GitHub](https://github.com/coffee2code/add-admin-css/) as an issue or PR).

‎tests/phpunit/tests/add-admin-css.php‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,70 @@ public function test_options_page_description() {
280280
$this->expectOutputRegex( '~^' . preg_quote( $expected ) . '$~', $this->obj->options_page_description() );
281281
}
282282

283+
/*
284+
* help_tabs_content()
285+
*/
286+
287+
public function test_help_tabs_content_adds_advanced_tips_help_tab() {
288+
// Create a dummy screen with an add_help_tab() method.
289+
$screen = new class {
290+
public $help_tabs = [];
291+
public function add_help_tab( $args ) {
292+
$this->help_tabs[] = $args;
293+
}
294+
};
295+
296+
$this->obj->id_base = 'my_id_base';
297+
$this->obj->options_page = 'my_options_slug';
298+
299+
$this->obj->help_tabs_content( $screen );
300+
301+
$this->assertNotEmpty( $screen->help_tabs, 'No help tabs were added.' );
302+
303+
$tab = $screen->help_tabs[0];
304+
305+
$this->assertArrayHasKey( 'id', $tab );
306+
$this->assertSame(
307+
'c2c-advanced-tips-my_id_base',
308+
$tab['id'],
309+
'Help‐tab ID did not match expected pattern.'
310+
);
311+
312+
$this->assertArrayHasKey( 'title', $tab );
313+
$this->assertSame(
314+
'Advanced Tips',
315+
$tab['title'],
316+
'Help‐tab title should be "Advanced Tips".'
317+
);
318+
}
319+
320+
public function test_help_tabs_content_uses_contextual_help_for_content() {
321+
// Create a dummy screen with an add_help_tab() method.
322+
$screen = new class {
323+
public $help_tabs = [];
324+
public function add_help_tab( $args ) {
325+
$this->help_tabs[] = $args;
326+
}
327+
};
328+
329+
$this->obj->id_base = 'foo';
330+
$this->obj->options_page = 'bar_options';
331+
332+
$expected_content = $this->obj->contextual_help( '', 'bar_options' );
333+
334+
$this->obj->help_tabs_content( $screen );
335+
336+
$this->assertNotEmpty( $screen->help_tabs, 'No help tabs were added.' );
337+
$tab = $screen->help_tabs[0];
338+
339+
$this->assertArrayHasKey( 'content', $tab );
340+
$this->assertSame(
341+
$expected_content,
342+
$tab['content'],
343+
'Help‐tab content should be generated via contextual_help().'
344+
);
345+
}
346+
283347
/**
284348
* @dataProvider get_css_file_links
285349
*/

0 commit comments

Comments
 (0)