Skip to content
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
2 changes: 1 addition & 1 deletion src/presentations/indexable-post-type-presentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public function generate_open_graph_article_publisher() {
* @return string The open graph article published time.
*/
public function generate_open_graph_article_published_time() {
if ( $this->model->object_sub_type !== 'post' ) {
if ( $this->model->object_sub_type !== 'post' && $this->model->object_sub_type !== 'page' ) {
/**
* Filter: 'wpseo_opengraph_show_publish_date' - Allow showing publication date for other post types.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function test_generate_open_graph_article_published_time_post() {
}

/**
* Tests that no published time is returned for a page.
* Tests that the published time is returned for a page.
*
* @covers ::generate_open_graph_article_published_time
*
Expand All @@ -63,26 +63,51 @@ public function test_generate_open_graph_article_published_time_post() {
public function test_generate_open_graph_article_published_time_page() {
$this->indexable->object_sub_type = 'page';

$source = (object) [ 'post_date_gmt' => '2019-10-08T12:26:31+00:00' ];
$this->instance->expects( 'generate_source' )->once()->andReturn( $source );

$this->date
->expects( 'format' )
->with( '2019-10-08T12:26:31+00:00' )
->once()
->andReturn( '2019-10-08T12:26:31+00:00' );

$actual = $this->instance->generate_open_graph_article_published_time();
$expected = '2019-10-08T12:26:31+00:00';

$this->assertEquals( $expected, $actual );
}

/**
* Tests that no published time is returned for a custom post type.
*
* @covers ::generate_open_graph_article_published_time
*
* @return void
*/
public function test_generate_open_graph_article_published_time_custom_post_type() {
$this->indexable->object_sub_type = 'book';

$this->instance->expects( 'generate_source' )->andReturn( (object) [] );

$this->post
->expects( 'get_post_type' )
->once()
->andReturn( 'page' );
->andReturn( 'book' );

$actual = $this->instance->generate_open_graph_article_published_time();
$this->assertEmpty( $actual );
}

/**
* Tests that a published time is returned for a page when the publish date is enabled with the wpseo_opengraph_show_publish_date filter.
* Tests that a published time is returned for a custom post type when the publish date is enabled with the wpseo_opengraph_show_publish_date filter.
*
* @covers ::generate_open_graph_article_published_time
*
* @return void
*/
public function test_generate_open_graph_article_published_time_page_enabled() {
$this->indexable->object_sub_type = 'page';
public function test_generate_open_graph_article_published_time_custom_post_type_enabled() {
$this->indexable->object_sub_type = 'book';

$source = (object) [ 'post_date_gmt' => '2019-10-08T12:26:31+00:00' ];
$this->instance->expects( 'generate_source' )->once()->andReturn( $source );
Expand All @@ -96,7 +121,7 @@ public function test_generate_open_graph_article_published_time_page_enabled() {
$this->post
->expects( 'get_post_type' )
->once()
->andReturn( 'page' );
->andReturn( 'book' );

Monkey\Filters\expectApplied( 'wpseo_opengraph_show_publish_date' )
->once()
Expand Down
Loading