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

Add Indexable visibility columns #17757

Open
wants to merge 58 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
b3fd2cd
Ensure array return type
diedexx Nov 12, 2021
87c11c3
Allow for deprecating columns
diedexx Nov 12, 2021
2eef6e2
Add method for creating a noindex query for indexables
diedexx Nov 15, 2021
b5bc8db
Rename is_public to is_publicly_viewable and number_of_public_posts t…
diedexx Nov 15, 2021
6c015ba
Use PHP 5.6 syntax
diedexx Nov 16, 2021
3d96968
Add migrations
diedexx Nov 16, 2021
acdf97a
Deprecate is_public instead of immediately replacing it
diedexx Nov 16, 2021
e18c9ac
Keep the method name the same and deprecate
diedexx Nov 16, 2021
58d6a71
Access properties that were renamed earlier
diedexx Nov 16, 2021
b7cfa04
Make the homepage get a number_of_publicly_viewable_posts and is_publ…
diedexx Nov 16, 2021
c2d121e
Use new column name
diedexx Nov 16, 2021
38b552d
Add deprecation tags
diedexx Nov 16, 2021
2fdce2f
Fix cs
diedexx Nov 16, 2021
3a18f72
Mark enabled date archives as publicly viewable
diedexx Nov 26, 2021
5e89640
Delegate logic to central helper
diedexx Nov 26, 2021
0a38f49
Make global namespace usage explicit
diedexx Nov 26, 2021
81e7421
Flip argument order
diedexx Nov 26, 2021
1564f53
Allow for considering empty archives as indexed
diedexx Nov 26, 2021
ecae28e
Update deperatation based on the expected release version
diedexx Nov 26, 2021
ea0a46e
Prevent new integrators from accessing is_public
diedexx Nov 26, 2021
6ccacd5
Update tests
diedexx Nov 26, 2021
ccf7f9b
Remove resolved todo comment
diedexx Nov 26, 2021
af7b219
Rebuild date archive indexable when disabling date archives
diedexx Nov 26, 2021
510f9de
Fix cs
diedexx Nov 26, 2021
ed46abb
Prevent deprecation warnings when (re)indexing
diedexx Nov 26, 2021
ff247f9
Include password protected posts in aggegrate queries
diedexx Nov 30, 2021
ca85a07
Keep the most recent last modified date.
diedexx Nov 30, 2021
faf1180
Merge branch 'trunk' of https://github.com/Yoast/wordpress-seo into F…
diedexx Nov 30, 2021
f6a8adf
Adhere to naming conventions
diedexx Dec 2, 2021
274df53
Don't hardcode the deprecation version number
diedexx Dec 2, 2021
d51829e
Update deprecation versions and descriptions
diedexx Dec 2, 2021
5c1193a
Rename migration
diedexx Dec 2, 2021
661e9a3
Merge branch 'trunk' of https://github.com/Yoast/wordpress-seo into F…
diedexx Dec 3, 2021
82f8a78
Fix cs
diedexx Dec 3, 2021
66d6e4d
Update tests
diedexx Dec 3, 2021
cf56df4
Fill WP 5.7 function
diedexx Dec 3, 2021
68aba31
Mock calls to newly introduced functions
diedexx Dec 3, 2021
3329a1b
Polyfill WP 5.7 function
diedexx Dec 3, 2021
e906ace
Lower error threshold
diedexx Dec 3, 2021
29739ee
Remove unused function that never made it into trunk
diedexx Dec 3, 2021
66c9433
Remove test double funtion that was removed in its parent
diedexx Dec 6, 2021
9eb9263
Make global namespace explicit
diedexx Dec 7, 2021
0c9ac1a
Ensure that post_types is an array
diedexx Dec 7, 2021
2059186
Automatically update date-archive indexables
diedexx Dec 7, 2021
b95492e
Use the type of the originally requested property in case of replaced…
diedexx Dec 10, 2021
101edcf
Merge branch 'trunk' of https://github.com/Yoast/wordpress-seo into F…
diedexx Dec 10, 2021
5d095a5
Fix CS warnings and errors
diedexx Dec 10, 2021
d8f754f
Fix tests
diedexx Dec 10, 2021
f613dfc
Clarify that the comment is about a function
diedexx Dec 17, 2021
3e7e755
Add instructions to remove related code
diedexx Dec 17, 2021
c24488e
Reduce risk of using the same builder version twice.
diedexx Dec 17, 2021
4ed8b38
Update post relation indexables when a post is set to private
diedexx Dec 17, 2021
275c423
Fix cs
diedexx Dec 18, 2021
08c1f5f
Fix precedence issues in query
diedexx Dec 19, 2021
e1c5055
Merge branch 'trunk' of https://github.com/Yoast/wordpress-seo into F…
diedexx Dec 20, 2021
6cf15bf
Increase threhshold
diedexx Dec 20, 2021
bad2929
Exclude password protected posts from the publicly_viewable_count
diedexx Dec 21, 2021
148d47c
Merge branch 'trunk' of github.com:Yoast/wordpress-seo into FIX-22-nu…
Dec 30, 2021
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
Prev Previous commit
Next Next commit
Update tests
  • Loading branch information
diedexx committed Nov 26, 2021
commit 6ccacd5ac3752ea22851fced77d48c77d8914e0e
115 changes: 44 additions & 71 deletions tests/unit/builders/indexable-author-builder-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
/**
* Class Indexable_Author_Test.
*
* @group indexables
* @group builders
* @group indexables
* @group builders
*
* @coversDefaultClass \Yoast\WP\SEO\Builders\Indexable_Author_Builder
* @covers \Yoast\WP\SEO\Builders\Indexable_Author_Builder
Expand Down Expand Up @@ -54,7 +54,7 @@ class Indexable_Author_Builder_Test extends TestCase {
/**
* The wpdb instance
*
* @var wpdb|Mockery\MockInterface
* @var \wpdb|Mockery\MockInterface
*/
protected $wpdb;

Expand Down Expand Up @@ -95,7 +95,6 @@ protected function set_up() {
$this->indexable_mock->orm->expects( 'set' )->with( 'twitter_image_source', null );

$this->indexable_mock->orm->expects( 'set' )->with( 'is_public', null );
$this->indexable_mock->orm->expects( 'set' )->with( 'has_public_posts', true );

$this->indexable_mock->orm->expects( 'get' )->with( 'is_robots_noindex' )->andReturn( 0 );

Expand All @@ -104,9 +103,8 @@ protected function set_up() {

$this->author_archive = Mockery::mock( Author_Archive_Helper::class );
$this->author_archive
->expects( 'author_has_public_posts' )
->with( 1 )
->andReturn( true );
->expects( 'get_author_archive_post_types' )
->andReturn( [ 'post', 'my-cpt' ] );

$this->versions = Mockery::mock( Indexable_Builder_Versions::class );
$this->versions
Expand All @@ -115,9 +113,35 @@ protected function set_up() {
->andReturn( 2 );

$this->post_helper = Mockery::mock( Post_Helper::class );
$this->post_helper->expects( 'get_public_post_statuses' )->once()->andReturn( [ 'publish' ] );

$this->wpdb = Mockery::mock( 'wpdb' );
$this->wpdb->posts = 'wp_posts';

$this->wpdb->expects( 'prepare' )->with(
"
SELECT
COUNT(p.ID) as number_of_public_posts,
MAX(p.post_modified_gmt) AS most_recent_last_modified,
MIN(p.post_date_gmt) AS first_published_at
FROM {$this->wpdb->posts} AS p
WHERE p.post_status IN (%s)
AND p.post_password = ''
AND p.post_author = %d
AND p.post_type IN (%s, %s)
", ['publish', 1, 'post', 'my-cpt']
)->andReturn( 'PREPARED_QUERY' );
$this->wpdb->expects( 'get_row' )->with( 'PREPARED_QUERY' )->andReturn(
(object) [
'number_of_public_posts' => '7',
'most_recent_last_modified' => '1234-12-12 23:59:59',
'first_published_at'=>'1234-12-12 00:00:00',
]
);

Monkey\Functions\expect( '_deprecated_argument' );
Monkey\Functions\expect( 'esc_html' );

$this->instance = new Indexable_Author_Builder( $this->author_archive, $this->versions, $this->post_helper, $this->wpdb );
}

Expand All @@ -137,39 +161,22 @@ public function test_build() {
$this->indexable_mock->orm->expects( 'set' )->with( 'is_robots_noindex', true );
$this->indexable_mock->orm->expects( 'set' )->with( 'version', 2 );

$this->indexable_mock->orm->expects( 'get' )->twice()->with( 'object_id' )->andReturn( 1 );
$this->indexable_mock->orm->expects( 'get' )->once()->with( 'open_graph_image' );
$this->indexable_mock->orm->expects( 'get' )->twice()->with( 'open_graph_image_id' );
$this->indexable_mock->orm->expects( 'get' )->twice()->with( 'open_graph_image_source' );
$this->indexable_mock->orm->expects( 'get' )->twice()->with( 'twitter_image' );
$this->indexable_mock->orm->expects( 'get' )->times( 3 )->with( 'twitter_image_id' );
$this->indexable_mock->orm->expects( 'get' )->with( 'object_id' );
$this->indexable_mock->orm->expects( 'get' )->once()->with( 'object_last_modified' );

$this->indexable_mock->orm->expects( 'set' )->with( 'open_graph_image', 'avatar_image.jpg' );
$this->indexable_mock->orm->expects( 'set' )->with( 'open_graph_image_source', 'gravatar-image' );
$this->indexable_mock->orm->expects( 'set' )->with( 'twitter_image', 'avatar_image.jpg' );
$this->indexable_mock->orm->expects( 'set' )->with( 'twitter_image_source', 'gravatar-image' );

$this->post_helper->expects( 'get_public_post_statuses' )->once()->andReturn( [ 'publish' ] );

$this->wpdb->expects( 'prepare' )->once()->with(
"
SELECT MAX(p.post_modified_gmt) AS last_modified, MIN(p.post_date_gmt) AS published_at
FROM {$this->wpdb->posts} AS p
WHERE p.post_status IN (%s)
AND p.post_password = ''
AND p.post_author = %d
",
[ 'publish', 1 ]
)->andReturn( 'PREPARED_QUERY' );
$this->wpdb->expects( 'get_row' )->once()->with( 'PREPARED_QUERY' )->andReturn(
(object) [
'last_modified' => '1234-12-12 00:00:00',
'published_at' => '1234-12-12 00:00:00',
]
);

$this->indexable_mock->orm->expects( 'set' )->with( 'object_published_at', '1234-12-12 00:00:00' );
$this->indexable_mock->orm->expects( 'set' )->with( 'object_last_modified', '1234-12-12 00:00:00' );
$this->indexable_mock->orm->expects( 'set' )->with( 'object_last_modified', '1234-12-12 23:59:59' );
$this->indexable_mock->orm->expects( 'set' )->with( 'number_of_publicly_viewable_posts', '7' );

Monkey\Functions\expect( 'get_avatar_url' )
->once()
Expand All @@ -193,39 +200,22 @@ public function test_build_without_alternative_image() {
$this->indexable_mock->orm->expects( 'set' )->with( 'is_robots_noindex', true );
$this->indexable_mock->orm->expects( 'set' )->with( 'version', 2 );

$this->indexable_mock->orm->expects( 'get' )->twice()->with( 'object_id' )->andReturn( 1 );
$this->indexable_mock->orm->expects( 'get' )->once()->with( 'open_graph_image' );
$this->indexable_mock->orm->expects( 'get' )->once()->with( 'open_graph_image_id' );
$this->indexable_mock->orm->expects( 'get' )->once()->with( 'open_graph_image_source' );
$this->indexable_mock->orm->expects( 'get' )->once()->with( 'twitter_image' );
$this->indexable_mock->orm->expects( 'get' )->twice()->with( 'twitter_image_id' );
$this->indexable_mock->orm->expects( 'get' )->twice()->with( 'object_id' );

$this->post_helper->expects( 'get_public_post_statuses' )->once()->andReturn( [ 'publish' ] );

$this->wpdb->expects( 'prepare' )->once()->with(
"
SELECT MAX(p.post_modified_gmt) AS last_modified, MIN(p.post_date_gmt) AS published_at
FROM {$this->wpdb->posts} AS p
WHERE p.post_status IN (%s)
AND p.post_password = ''
AND p.post_author = %d
",
[ 'publish', 1 ]
)->andReturn( 'PREPARED_QUERY' );
$this->wpdb->expects( 'get_row' )->once()->with( 'PREPARED_QUERY' )->andReturn(
(object) [
'last_modified' => '1234-12-12 00:00:00',
'published_at' => '1234-12-12 00:00:00',
]
);
$this->indexable_mock->orm->expects( 'get' )->once()->with( 'object_last_modified' );

$this->indexable_mock->orm->expects( 'set' )->with( 'object_published_at', '1234-12-12 00:00:00' );
$this->indexable_mock->orm->expects( 'set' )->with( 'object_last_modified', '1234-12-12 00:00:00' );
$this->indexable_mock->orm->expects( 'set' )->with( 'object_last_modified', '1234-12-12 23:59:59' );
$this->indexable_mock->orm->expects( 'set' )->with( 'number_of_publicly_viewable_posts', '7' );

Monkey\Functions\expect( 'get_avatar_url' )
->once()
->with(
$this->indexable_mock->object_id,
1,
[
'size' => 500,
'scheme' => 'https',
Expand All @@ -252,39 +242,22 @@ public function test_build_with_undefined_author_meta() {
$this->indexable_mock->orm->expects( 'set' )->with( 'is_robots_noindex', false );
$this->indexable_mock->orm->expects( 'set' )->with( 'version', 2 );

$this->indexable_mock->orm->expects( 'get' )->twice()->with( 'object_id' )->andReturn( 1 );
$this->indexable_mock->orm->expects( 'get' )->once()->with( 'open_graph_image' );
$this->indexable_mock->orm->expects( 'get' )->twice()->with( 'open_graph_image_id' );
$this->indexable_mock->orm->expects( 'get' )->twice()->with( 'open_graph_image_source' );
$this->indexable_mock->orm->expects( 'get' )->twice()->with( 'twitter_image' );
$this->indexable_mock->orm->expects( 'get' )->times( 3 )->with( 'twitter_image_id' );
$this->indexable_mock->orm->expects( 'get' )->with( 'object_id' );
$this->indexable_mock->orm->expects( 'get' )->once()->with( 'object_last_modified' );

$this->indexable_mock->orm->expects( 'set' )->with( 'open_graph_image', 'avatar_image.jpg' );
$this->indexable_mock->orm->expects( 'set' )->with( 'open_graph_image_source', 'gravatar-image' );
$this->indexable_mock->orm->expects( 'set' )->with( 'twitter_image', 'avatar_image.jpg' );
$this->indexable_mock->orm->expects( 'set' )->with( 'twitter_image_source', 'gravatar-image' );

$this->post_helper->expects( 'get_public_post_statuses' )->once()->andReturn( [ 'publish' ] );

$this->wpdb->expects( 'prepare' )->once()->with(
"
SELECT MAX(p.post_modified_gmt) AS last_modified, MIN(p.post_date_gmt) AS published_at
FROM {$this->wpdb->posts} AS p
WHERE p.post_status IN (%s)
AND p.post_password = ''
AND p.post_author = %d
",
[ 'publish', 1 ]
)->andReturn( 'PREPARED_QUERY' );
$this->wpdb->expects( 'get_row' )->once()->with( 'PREPARED_QUERY' )->andReturn(
(object) [
'last_modified' => '1234-12-12 00:00:00',
'published_at' => '1234-12-12 00:00:00',
]
);

$this->indexable_mock->orm->expects( 'set' )->with( 'object_published_at', '1234-12-12 00:00:00' );
$this->indexable_mock->orm->expects( 'set' )->with( 'object_last_modified', '1234-12-12 00:00:00' );
$this->indexable_mock->orm->expects( 'set' )->with( 'object_last_modified', '1234-12-12 23:59:59' );
$this->indexable_mock->orm->expects( 'set' )->with( 'number_of_publicly_viewable_posts', '7' );

Monkey\Functions\expect( 'get_avatar_url' )
->once()
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/builders/indexable-date-archive-builder-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function test_build() {
$options_mock->expects( 'get' )->with( 'title-archive-wpseo' )->andReturn( 'date_archive_title' );
$options_mock->expects( 'get' )->with( 'metadesc-archive-wpseo' )->andReturn( 'date_archive_meta_description' );
$options_mock->expects( 'get' )->with( 'noindex-archive-wpseo' )->andReturn( false );
$options_mock->expects( 'get' )->with( 'disable-date' )->andReturn( false );

$indexable_mock = Mockery::mock( Indexable::class );
$indexable_mock->orm = Mockery::mock( ORM::class );
Expand All @@ -48,6 +49,10 @@ public function test_build() {
$indexable_mock->orm->expects( 'set' )->with( 'blog_id', 1 );
$indexable_mock->orm->expects( 'set' )->with( 'permalink', null );
$indexable_mock->orm->expects( 'set' )->with( 'version', 1 );
$indexable_mock->orm->expects( 'set' )->with( 'is_publicly_viewable', 1 );

Functions\expect( '_deprecated_argument' );
Functions\expect( 'esc_html' );

$builder = new Indexable_Date_Archive_Builder( $options_mock, new Indexable_Builder_Versions() );
$builder->build( $indexable_mock );
Expand Down
56 changes: 39 additions & 17 deletions tests/unit/builders/indexable-home-page-builder-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Brain\Monkey;
use Mockery;
use wpdb;
use WPSEO_Utils;
use Yoast\WP\Lib\ORM;
use Yoast\WP\SEO\Builders\Indexable_Home_Page_Builder;
Expand All @@ -20,13 +21,13 @@
/**
* Class Indexable_Author_Test.
*
* @group indexables
* @group builders
* @group indexables
* @group builders
*
* @coversDefaultClass \Yoast\WP\SEO\Builders\Indexable_Author_Builder
* @covers \Yoast\WP\SEO\Builders\Indexable_Home_Page_Builder
*
* @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded -- 5 words is fine.
* @phpcs :disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded -- 5 words is fine.
*/
class Indexable_Home_Page_Builder_Test extends TestCase {

Expand Down Expand Up @@ -142,13 +143,13 @@ protected function set_up() {
$this->indexable_mock->orm->expects( 'set' )->with( 'open_graph_description', 'home_og_description' );
$this->indexable_mock->orm->expects( 'set' )->with( 'open_graph_image_source', null );
$this->indexable_mock->orm->expects( 'set' )->with( 'open_graph_image_meta', null );
$this->indexable_mock->orm->expects( 'set' )->with( 'is_publicly_viewable', 1 );
$this->indexable_mock->orm->expects( 'set' )->with( 'version', 2 );

// Mock offsetExists.
$this->indexable_mock->orm->expects( 'offsetExists' )->with( 'description' )->andReturn( true );

// Mock Indexable ORM getters.
$this->indexable_mock->orm->expects( 'get' )->with( 'description' )->andReturn( 'home_meta_description' );
$this->indexable_mock->orm->expects( 'get' )->with( 'open_graph_image' )->andReturn( 'home_og_image' );
$this->indexable_mock->orm->expects( 'get' )->with( 'open_graph_image_id' )->andReturn( 1337 )->twice();

Expand Down Expand Up @@ -200,6 +201,7 @@ public function test_build() {
$this->options_mock->expects( 'get' )->with( 'metadesc-home-wpseo' )->andReturn( 'home_meta_description' );

$this->indexable_mock->orm->expects( 'set' )->with( 'description', 'home_meta_description' );
$this->indexable_mock->orm->expects( 'get' )->with( 'description' )->andReturn( 'home_meta_description' );

Monkey\Functions\expect( 'get_current_blog_id' )->once()->andReturn( 1 );
$this->indexable_mock->orm->expects( 'set' )->with( 'blog_id', 1 );
Expand All @@ -208,7 +210,10 @@ public function test_build() {

$this->wpdb->expects( 'prepare' )->once()->with(
"
SELECT MAX(p.post_modified_gmt) AS last_modified, MIN(p.post_date_gmt) AS published_at
SELECT
COUNT(p.ID) as number_of_public_posts,
MAX(p.post_modified_gmt) AS most_recent_last_modified,
MIN(p.post_date_gmt) AS first_published_at
FROM {$this->wpdb->posts} AS p
WHERE p.post_status IN (%s)
AND p.post_password = ''
Expand All @@ -218,13 +223,15 @@ public function test_build() {
)->andReturn( 'PREPARED_QUERY' );
$this->wpdb->expects( 'get_row' )->once()->with( 'PREPARED_QUERY' )->andReturn(
(object) [
'last_modified' => '1234-12-12 00:00:00',
'published_at' => '1234-12-12 00:00:00',
'number_of_public_posts' => 20,
'most_recent_last_modified' => '1234-12-12 23:59:59',
'first_published_at' => '1234-12-12 00:00:00',
]
);

$this->indexable_mock->orm->expects( 'set' )->with( 'object_published_at', '1234-12-12 00:00:00' );
$this->indexable_mock->orm->expects( 'set' )->with( 'object_last_modified', '1234-12-12 00:00:00' );
$this->indexable_mock->orm->expects( 'set' )->with( 'object_last_modified', '1234-12-12 23:59:59' );
$this->indexable_mock->orm->expects( 'set' )->with( 'number_of_publicly_viewable_posts', 20 );

$this->instance->build( $this->indexable_mock );
}
Expand All @@ -242,8 +249,12 @@ public function test_build_with_fallback_description() {

// When no meta description is stored in the WP_Options...
$this->options_mock->expects( 'get' )->with( 'metadesc-home-wpseo' )->andReturn( false );

// We expect the description to be `false` in the ORM layer.
$this->indexable_mock->orm->expects( 'set' )->with( 'description', false );
$this->indexable_mock->orm->expects( 'set' )->once()->with( 'description', false );
$this->indexable_mock->orm->expects( 'get' )->with( 'description' )->andReturn( false );
// Brainmonkey makes get_bloginfo( 'description' ) return 'description'.
$this->indexable_mock->orm->expects( 'set' )->once()->with( 'description', 'description' );

Monkey\Functions\expect( 'get_current_blog_id' )->once()->andReturn( 1 );
$this->indexable_mock->orm->expects( 'set' )->with( 'blog_id', 1 );
Expand All @@ -252,7 +263,10 @@ public function test_build_with_fallback_description() {

$this->wpdb->expects( 'prepare' )->once()->with(
"
SELECT MAX(p.post_modified_gmt) AS last_modified, MIN(p.post_date_gmt) AS published_at
SELECT
COUNT(p.ID) as number_of_public_posts,
MAX(p.post_modified_gmt) AS most_recent_last_modified,
MIN(p.post_date_gmt) AS first_published_at
FROM {$this->wpdb->posts} AS p
WHERE p.post_status IN (%s)
AND p.post_password = ''
Expand All @@ -262,13 +276,15 @@ public function test_build_with_fallback_description() {
)->andReturn( 'PREPARED_QUERY' );
$this->wpdb->expects( 'get_row' )->once()->with( 'PREPARED_QUERY' )->andReturn(
(object) [
'last_modified' => '1234-12-12 00:00:00',
'published_at' => '1234-12-12 00:00:00',
'number_of_public_posts' => 20,
'most_recent_last_modified' => '1234-12-12 23:59:59',
'first_published_at' => '1234-12-12 00:00:00',
]
);

$this->indexable_mock->orm->expects( 'set' )->with( 'object_published_at', '1234-12-12 00:00:00' );
$this->indexable_mock->orm->expects( 'set' )->with( 'object_last_modified', '1234-12-12 00:00:00' );
$this->indexable_mock->orm->expects( 'set' )->with( 'object_last_modified', '1234-12-12 23:59:59' );
$this->indexable_mock->orm->expects( 'set' )->with( 'number_of_publicly_viewable_posts', 20 );

$this->instance->build( $this->indexable_mock );
}
Expand All @@ -280,6 +296,7 @@ public function test_build_open_graph_image_meta_data() {
$this->options_mock->expects( 'get' )->with( 'metadesc-home-wpseo' )->andReturn( 'home_meta_description' );

$this->indexable_mock->orm->expects( 'set' )->with( 'description', 'home_meta_description' );
$this->indexable_mock->orm->expects( 'get' )->with( 'description' )->andReturn( 'home_meta_description' );

// Transform the image meta mock to JSON, since we expect that to be stored in the DB.
$image_meta_mock_json = WPSEO_Utils::format_json_encode( $this->image_meta_mock );
Expand All @@ -295,7 +312,10 @@ public function test_build_open_graph_image_meta_data() {

$this->wpdb->expects( 'prepare' )->once()->with(
"
SELECT MAX(p.post_modified_gmt) AS last_modified, MIN(p.post_date_gmt) AS published_at
SELECT
COUNT(p.ID) as number_of_public_posts,
MAX(p.post_modified_gmt) AS most_recent_last_modified,
MIN(p.post_date_gmt) AS first_published_at
FROM {$this->wpdb->posts} AS p
WHERE p.post_status IN (%s)
AND p.post_password = ''
Expand All @@ -305,13 +325,15 @@ public function test_build_open_graph_image_meta_data() {
)->andReturn( 'PREPARED_QUERY' );
$this->wpdb->expects( 'get_row' )->once()->with( 'PREPARED_QUERY' )->andReturn(
(object) [
'last_modified' => '1234-12-12 00:00:00',
'published_at' => '1234-12-12 00:00:00',
'number_of_public_posts' => 20,
'most_recent_last_modified' => '1234-12-12 23:59:59',
'first_published_at' => '1234-12-12 00:00:00',
]
);

$this->indexable_mock->orm->expects( 'set' )->with( 'object_published_at', '1234-12-12 00:00:00' );
$this->indexable_mock->orm->expects( 'set' )->with( 'object_last_modified', '1234-12-12 00:00:00' );
$this->indexable_mock->orm->expects( 'set' )->with( 'object_last_modified', '1234-12-12 23:59:59' );
$this->indexable_mock->orm->expects( 'set' )->with( 'number_of_publicly_viewable_posts', 20 );

$this->instance->build( $this->indexable_mock );
}
Expand Down
Loading