File tree Expand file tree Collapse file tree 3 files changed +66
-4
lines changed
Expand file tree Collapse file tree 3 files changed +66
-4
lines changed Original file line number Diff line number Diff line change 1212 *
1313 * @since 1.5.0
1414 *
15- * @return void
15+ * @return null|bool Returns false when no skip links, otherwise null.
1616 */
1717function beans_build_skip_links () {
1818 $ skip_links = array ();
@@ -47,10 +47,10 @@ function beans_build_skip_links() {
4747 * @type string Anchor text.
4848 * }
4949 */
50- $ skip_links = apply_filters ( 'beans_skip_links_list ' , $ skip_links );
50+ $ skip_links = ( array ) apply_filters ( 'beans_skip_links_list ' , $ skip_links );
5151
5252 if ( empty ( $ skip_links ) ) {
53- return ;
53+ return false ;
5454 }
5555
5656 beans_output_skip_links ( $ skip_links );
Original file line number Diff line number Diff line change @@ -265,4 +265,46 @@ function( $default_layout ) {
265265
266266 $ this ->assertContains ( $ this ->format_the_html ( $ expected ), $ this ->format_the_html ( $ actual ) );
267267 }
268+
269+ /**
270+ * Test beans_build_skip_links() should return false when no skip links because beans_skip_links_list filter unsets the array.
271+ */
272+ public function test_should_return_false_when_filter_unsets_the_array_of_skip_links () {
273+ add_filter (
274+ 'beans_default_layout ' ,
275+ function ( $ default_layout ) {
276+ return 'c_sp ' ;
277+ }
278+ );
279+
280+ $ this ->assertEquals ( beans_get_layout (), 'c_sp ' );
281+
282+ add_filter (
283+ 'beans_skip_links_list ' ,
284+ function ( $ skip_links ) {
285+ unset( $ skip_links ['beans-content ' ], $ skip_links ['beans-primary-sidebar ' ] );
286+ return $ skip_links ;
287+ }
288+ );
289+
290+ $ this ->assertFalse ( beans_build_skip_links () );
291+ }
292+
293+ /**
294+ * Test beans_build_skip_links() should return false when beans_skip_links_list filter returns null.
295+ */
296+ public function test_should_return_false_when_filter_returns_null () {
297+ add_filter (
298+ 'beans_default_layout ' ,
299+ function ( $ default_layout ) {
300+ return 'c ' ;
301+ }
302+ );
303+
304+ $ this ->assertEquals ( beans_get_layout (), 'c ' );
305+
306+ add_filter ( 'beans_skip_links_list ' , '__return_null ' );
307+ $ this ->assertFalse ( beans_build_skip_links () );
308+ }
309+
268310}
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ public function test_should_call_beans_has_primary_sidebar_and_beans_has_seconda
5050 /**
5151 * Test beans_build_skip_links() should not call beans_has_primary_sidebar() or beans_has_secondary_sidebar() when the layout is full-width.
5252 */
53- public function test_should_not_call_beans_has_primary_sidebar_or_beans_has_secondary_sidebara_when_fullwith_layout () {
53+ public function test_should_not_call_beans_has_primary_sidebar_or_beans_has_secondary_sidebar_when_full_width_layout () {
5454 Monkey \Functions \expect ( 'beans_get_layout ' )->once ()->andReturn ( 'c ' );
5555 Monkey \Functions \expect ( 'has_nav_menu ' )
5656 ->once ()
@@ -66,4 +66,24 @@ public function test_should_not_call_beans_has_primary_sidebar_or_beans_has_seco
6666 $ this ->assertNull ( beans_build_skip_links () );
6767 }
6868
69+ /**
70+ * Test beans_build_skip_links() should not call beans_output_skip_links() when there are no skip links.
71+ */
72+ public function test_should_not_call_beans_output_skip_links_when_no_skip_links () {
73+ Monkey \Functions \expect ( 'beans_get_layout ' )->once ()->andReturn ( 'c ' );
74+ Monkey \Functions \expect ( 'has_nav_menu ' )
75+ ->once ()
76+ ->with ( 'primary ' )
77+ ->andReturn ( false );
78+ Monkey \Functions \expect ( 'beans_has_primary_sidebar ' )->never ();
79+ Monkey \Functions \expect ( 'beans_has_secondary_sidebar ' )->never ();
80+
81+ Monkey \Filters \expectApplied ( 'beans_skip_links_list ' )
82+ ->once ()
83+ ->andReturn ( null );
84+
85+ Monkey \Functions \expect ( 'beans_output_skip_links ' )->never ();
86+
87+ $ this ->assertFalse ( beans_build_skip_links () );
88+ }
6989}
You can’t perform that action at this time.
0 commit comments