-
Notifications
You must be signed in to change notification settings - Fork 968
Open graph article modified and publish time presenters and presentations #13652
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
Merged
igorschoester
merged 11 commits into
feature/indexables-frontend
from
open-graph-article-modified-and-publish-time
Oct 16, 2019
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
367a5ef
Add article published time presenter and presentations
IreneStr 0fb8b2e
Add article-modified-time-presenter and its tests
IreneStr 371130d
Fix docs
IreneStr fefb0c1
Fix test name and docs
IreneStr fb465eb
Add article modified time presentation and its tests
IreneStr d8a4292
Merge branch 'feature/indexables-frontend' into open-graph-article-mo…
IreneStr 1c684fb
Use correct name for the post type helper
IreneStr 9c85d44
Merge branch 'feature/indexables-frontend' into open-graph-article-mo…
IreneStr 5b72088
Merge branch 'feature/indexables-frontend' into open-graph-article-mo…
IreneStr 5fd604c
Rename group open-graph to opengraph
IreneStr 7881ffd
Add slash before mysql2date
IreneStr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/presenters/open-graph/article-modified-time-presenter.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?php | ||
| /** | ||
| * Presenter class for the OpenGraph article modified time. | ||
| * | ||
| * @package Yoast\YoastSEO\Presenters\Open_Graph | ||
| */ | ||
|
|
||
| namespace Yoast\WP\Free\Presenters\Open_Graph; | ||
|
|
||
| use Yoast\WP\Free\Presentations\Indexable_Presentation; | ||
| use Yoast\WP\Free\Presenters\Abstract_Indexable_Presenter; | ||
|
|
||
| /** | ||
| * Class Article_Modified_Time_Presenter | ||
| */ | ||
| class Article_Modified_Time_Presenter extends Abstract_Indexable_Presenter { | ||
| /** | ||
| * Returns the article modified time tag. | ||
| * | ||
| * @param Indexable_Presentation $presentation The presentation of an indexable. | ||
| * | ||
| * @return string The article modified time tag. | ||
| */ | ||
| public function present( Indexable_Presentation $presentation ) { | ||
| $modified_time = $presentation->og_article_modified_time; | ||
|
|
||
| if ( is_string( $modified_time ) && $modified_time !== '' ) { | ||
| return sprintf( '<meta property="article:modified_time" content="%s" />', \esc_attr( $modified_time ) ); | ||
| } | ||
|
|
||
| return ''; | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
src/presenters/open-graph/article-published-time-presenter.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?php | ||
| /** | ||
| * Presenter class for the OpenGraph article published time. | ||
| * | ||
| * @package Yoast\YoastSEO\Presenters\Open_Graph | ||
| */ | ||
|
|
||
| namespace Yoast\WP\Free\Presenters\Open_Graph; | ||
|
|
||
| use Yoast\WP\Free\Presentations\Indexable_Presentation; | ||
| use Yoast\WP\Free\Presenters\Abstract_Indexable_Presenter; | ||
|
|
||
| /** | ||
| * Class Article_Published_Time_Presenter | ||
| */ | ||
| class Article_Published_Time_Presenter extends Abstract_Indexable_Presenter { | ||
| /** | ||
| * Returns the article published time tag. | ||
| * | ||
| * @param Indexable_Presentation $presentation The presentation of an indexable. | ||
| * | ||
| * @return string The article published time tag. | ||
| */ | ||
| public function present( Indexable_Presentation $presentation ) { | ||
| $published_time = $presentation->og_article_published_time; | ||
|
|
||
| if ( is_string( $published_time ) && $published_time !== '' ) { | ||
| return sprintf( '<meta property="article:published_time" content="%s" />', \esc_attr( $published_time ) ); | ||
| } | ||
|
|
||
| return ''; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
tests/presentations/indexable-post-type-presentation/og-article-modified-time-test.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| <?php | ||
|
|
||
| namespace Yoast\WP\Free\Tests\Presentations\Indexable_Post_Type_Presentation; | ||
|
|
||
| use Yoast\WP\Free\Tests\TestCase; | ||
|
|
||
| /** | ||
| * Class OG_Article_Modified_Time_Test | ||
| * | ||
| * @coversDefaultClass \Yoast\WP\Free\Presentations\Indexable_Post_Type_Presentation | ||
| * | ||
| * @group presentations | ||
| * @group opengraph | ||
| */ | ||
| class OG_Article_Modified_Time_Test extends TestCase { | ||
|
IreneStr marked this conversation as resolved.
|
||
| use Presentation_Instance_Builder; | ||
|
|
||
| /** | ||
| * Sets up the test class. | ||
| */ | ||
| public function setUp() { | ||
| parent::setUp(); | ||
|
|
||
| $this->setInstance(); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that no modified time is returned if it is the same as the published time | ||
| * | ||
| * @covers ::generate_og_article_modified_time | ||
| */ | ||
| public function test_generate_og_article_modified_time_same_as_published_time() { | ||
| $this->context->post = (object) [ | ||
| 'post_date_gmt' => '2019-10-08T12:26:31+00:00', | ||
| 'post_modified_gmt' => '2019-10-08T12:26:31+00:00', | ||
| ]; | ||
| $actual = $this->instance->generate_og_article_modified_time(); | ||
| $this->assertEmpty( $actual ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that the modified time is returned if it differs from the published time. | ||
| * | ||
| * @covers ::generate_og_article_modified_time | ||
| */ | ||
| public function test_generate_og_article_modified_time_differs_from_published_time() { | ||
| $this->context->post = (object) [ | ||
| 'post_date_gmt' => '2019-10-08T12:26:31+00:00', | ||
| 'post_modified_gmt' => '2019-11-09T12:34:56+00:00', | ||
| ]; | ||
|
|
||
| $actual = $this->instance->generate_og_article_modified_time(); | ||
| $expected = '2019-11-09T12:34:56+00:00'; | ||
| $this->assertEquals( $expected, $actual ); | ||
| } | ||
|
|
||
| } | ||
82 changes: 82 additions & 0 deletions
82
tests/presentations/indexable-post-type-presentation/og-article-published-time-test.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| <?php | ||
|
|
||
| namespace Yoast\WP\Free\Tests\Presentations\Indexable_Post_Type_Presentation; | ||
|
|
||
| use Yoast\WP\Free\Tests\TestCase; | ||
| use Brain\Monkey; | ||
|
|
||
| /** | ||
| * Class OG_Article_Published_Time_Test | ||
| * | ||
| * @coversDefaultClass \Yoast\WP\Free\Presentations\Indexable_Post_Type_Presentation | ||
| * | ||
| * @group presentations | ||
| * @group opengraph | ||
| */ | ||
| class OG_Article_Published_Time_Test extends TestCase { | ||
| use Presentation_Instance_Builder; | ||
|
|
||
| /** | ||
| * Sets up the test class. | ||
| */ | ||
| public function setUp() { | ||
| parent::setUp(); | ||
|
|
||
| $this->setInstance(); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that the published time is returned for a post. | ||
| * | ||
| * @covers ::generate_og_article_published_time | ||
| */ | ||
| public function test_generate_og_article_published_time_post() { | ||
| $this->indexable->object_sub_type = 'post'; | ||
| $this->context->post = (object) [ 'post_date_gmt' => '2019-10-08T12:26:31+00:00' ]; | ||
| $actual = $this->instance->generate_og_article_published_time(); | ||
| $expected = '2019-10-08T12:26:31+00:00'; | ||
|
|
||
| $this->assertEquals( $expected, $actual ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that no published time is returned for a page. | ||
| * | ||
| * @covers ::generate_og_article_published_time | ||
| */ | ||
| public function test_generate_og_article_published_time_page() { | ||
| $this->indexable->object_sub_type = 'page'; | ||
|
|
||
| $this->post_type_helper | ||
| ->expects( 'get_post_type' ) | ||
| ->once() | ||
| ->andReturn( 'page' ); | ||
|
|
||
| $actual = $this->instance->generate_og_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. | ||
| * | ||
| * @covers ::generate_og_article_published_time | ||
| */ | ||
| public function test_generate_og_article_published_time_page_enabled() { | ||
| $this->context->post = (object) [ 'post_date_gmt' => '2019-10-08T12:26:31+00:00' ]; | ||
| $this->indexable->object_sub_type = 'page'; | ||
|
|
||
| $this->post_type_helper | ||
| ->expects( 'get_post_type' ) | ||
| ->once() | ||
| ->andReturn( 'page' ); | ||
|
|
||
| Monkey\Filters\expectApplied( 'wpseo_opengraph_show_publish_date' ) | ||
| ->once() | ||
| ->andReturn( true ); | ||
|
|
||
|
|
||
| $actual = $this->instance->generate_og_article_published_time(); | ||
| $expected = '2019-10-08T12:26:31+00:00'; | ||
| $this->assertEquals( $expected, $actual ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.