Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevented output of empty skip link markup. #337

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/api/html/accessibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* @since 1.5.0
*
* @return void
* @return null|bool Returns false when no skip links, otherwise null.
*/
function beans_build_skip_links() {
$skip_links = array();
Expand Down Expand Up @@ -49,6 +49,10 @@ function beans_build_skip_links() {
*/
$skip_links = (array) apply_filters( 'beans_skip_links_list', $skip_links );

if ( empty( $skip_links ) ) {
return false;
}

beans_output_skip_links( $skip_links );
}

Expand Down
42 changes: 42 additions & 0 deletions tests/phpunit/integration/api/html/beansBuildSkipLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,46 @@ function( $default_layout ) {

$this->assertContains( $this->format_the_html( $expected ), $this->format_the_html( $actual ) );
}

/**
* Test beans_build_skip_links() should return false when no skip links because beans_skip_links_list filter unsets the array.
*/
public function test_should_return_false_when_filter_unsets_the_array_of_skip_links() {
add_filter(
'beans_default_layout',
function( $default_layout ) {
return 'c_sp';
}
);

$this->assertEquals( beans_get_layout(), 'c_sp' );

add_filter(
'beans_skip_links_list',
function( $skip_links ) {
unset( $skip_links['beans-content'], $skip_links['beans-primary-sidebar'] );
return $skip_links;
}
);

$this->assertFalse( beans_build_skip_links() );
}

/**
* Test beans_build_skip_links() should return false when beans_skip_links_list filter returns null.
*/
public function test_should_return_false_when_filter_returns_null() {
add_filter(
'beans_default_layout',
function( $default_layout ) {
return 'c';
}
);

$this->assertEquals( beans_get_layout(), 'c' );

add_filter( 'beans_skip_links_list', '__return_null' );
$this->assertFalse( beans_build_skip_links() );
}

}
22 changes: 21 additions & 1 deletion tests/phpunit/unit/api/html/beansBuildSkipLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function test_should_call_beans_has_primary_sidebar_and_beans_has_seconda
/**
* Test beans_build_skip_links() should not call beans_has_primary_sidebar() or beans_has_secondary_sidebar() when the layout is full-width.
*/
public function test_should_not_call_beans_has_primary_sidebar_or_beans_has_secondary_sidebara_when_fullwith_layout() {
public function test_should_not_call_beans_has_primary_sidebar_or_beans_has_secondary_sidebar_when_full_width_layout() {
Monkey\Functions\expect( 'beans_get_layout' )->once()->andReturn( 'c' );
Monkey\Functions\expect( 'has_nav_menu' )
->once()
Expand All @@ -66,4 +66,24 @@ public function test_should_not_call_beans_has_primary_sidebar_or_beans_has_seco
$this->assertNull( beans_build_skip_links() );
}

/**
* Test beans_build_skip_links() should not call beans_output_skip_links() when there are no skip links.
*/
public function test_should_not_call_beans_output_skip_links_when_no_skip_links() {
Monkey\Functions\expect( 'beans_get_layout' )->once()->andReturn( 'c' );
Monkey\Functions\expect( 'has_nav_menu' )
->once()
->with( 'primary' )
->andReturn( false );
Monkey\Functions\expect( 'beans_has_primary_sidebar' )->never();
Monkey\Functions\expect( 'beans_has_secondary_sidebar' )->never();

Monkey\Filters\expectApplied( 'beans_skip_links_list' )
->once()
->andReturn( null );

Monkey\Functions\expect( 'beans_output_skip_links' )->never();

$this->assertFalse( beans_build_skip_links() );
}
}