Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions includes/MslsOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ public function get_alternate_links() {
return apply_filters( self::MSLS_ALTERNATE_LINKS_DEFAULT_HOOK, $default );
}

$default = apply_filters( self::MSLS_ALTERNATE_LINKS_DEFAULT_HOOK, $default );
if ( '' !== $default ) {
array_unshift( $arr, $default );
}
Comment thread
apermo marked this conversation as resolved.

$arr = (array) apply_filters( self::MSLS_ALTERNATE_LINKS_ARR_HOOK, $arr );

return implode( PHP_EOL, $arr );
Expand Down
51 changes: 51 additions & 0 deletions tests/phpunit/TestMslsOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,57 @@ public function test_get_alternate_links_two_url(): void {
Functions\expect( 'get_queried_object_id' )->once()->andReturn( 42 );
Functions\expect( 'get_option' )->once()->andReturn( array() );

Filters\expectApplied( 'msls_output_get_alternate_links_default' )->once();
Filters\expectApplied( 'msls_output_get_alternate_links_arr' )->once();

$expected =
'<link rel="alternate" href="https://example.de/" hreflang="x-default" />' . PHP_EOL .
'<link rel="alternate" href="https://example.de/" hreflang="de" />' . PHP_EOL .
'<link rel="alternate" href="https://example.it/" hreflang="it" />';

$test = $this->MslsOutputFactory();

$this->assertEquals( $expected, $test->get_alternate_links() );
}

public function test_get_alternate_links_x_default_suppressed(): void {
$blogs = array();

$a = \Mockery::mock( MslsBlog::class );
$a->shouldReceive( 'get_alpha2' )->andReturn( 'de' );
$a->shouldReceive( 'get_language' )->andReturn( 'de_DE' );
$a->shouldReceive( 'get_url' )->andReturn( 'https://example.de/' );
$a->shouldReceive( 'get_description' )->andReturn( 'Deutsch' );

$blogs[] = $a;

$b = \Mockery::mock( MslsBlog::class );
$b->shouldReceive( 'get_alpha2' )->andReturn( 'it' );
$b->shouldReceive( 'get_language' )->andReturn( 'it_IT' );
$b->shouldReceive( 'get_url' )->andReturn( 'https://example.it/' );
$b->shouldReceive( 'get_description' )->andReturn( 'Italiano' );

$blogs[] = $b;

$collection = \Mockery::mock( MslsBlogCollection::class );
$collection->shouldReceive( 'get_objects' )->andReturn( $blogs );

Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection );
Functions\expect( 'is_admin' )->once()->andReturn( false );
Functions\expect( 'is_front_page' )->once()->andReturn( false );
Functions\expect( 'is_search' )->once()->andReturn( false );
Functions\expect( 'is_404' )->once()->andReturn( false );
Functions\expect( 'is_category' )->once()->andReturn( false );
Functions\expect( 'is_tag' )->once()->andReturn( false );
Functions\expect( 'is_tax' )->once()->andReturn( false );
Functions\expect( 'is_date' )->once()->andReturn( false );
Functions\expect( 'is_author' )->once()->andReturn( false );
Functions\expect( 'is_post_type_archive' )->once()->andReturn( false );
Functions\expect( 'get_queried_object_id' )->once()->andReturn( 42 );
Functions\expect( 'get_option' )->once()->andReturn( array() );

// Returning an empty string from the filter opts out of x-default.
Filters\expectApplied( 'msls_output_get_alternate_links_default' )->once()->andReturn( '' );
Filters\expectApplied( 'msls_output_get_alternate_links_arr' )->once();

$expected =
Expand Down