Skip to content

Commit

Permalink
Added unit and integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
christophherr committed Oct 20, 2018
1 parent 04c4720 commit 93670d0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
6 changes: 3 additions & 3 deletions 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 @@ -47,10 +47,10 @@ function beans_build_skip_links() {
* @type string Anchor text.
* }
*/
$skip_links = apply_filters( 'beans_skip_links_list', $skip_links );
$skip_links = (array) apply_filters( 'beans_skip_links_list', $skip_links );

if ( empty( $skip_links ) ) {
return;
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_fullwith_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() );
}
}

0 comments on commit 93670d0

Please sign in to comment.