Skip to content

Commit

Permalink
Merge pull request #21109 from Yoast/add-upgrade-routine-integration-…
Browse files Browse the repository at this point in the history
…tests

Add upgrade routine integration tests
  • Loading branch information
thijsoo committed Mar 6, 2024
2 parents 03e8ea6 + 6116fd1 commit 7fc2d47
Show file tree
Hide file tree
Showing 4 changed files with 969 additions and 18 deletions.
18 changes: 9 additions & 9 deletions inc/class-upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ private function upgrade_33() {
*
* @return void
*/
private function upgrade_36() {
protected function upgrade_36() {
global $wpdb;

// Between 3.2 and 3.4 the sitemap options were saved with autoloading enabled.
Expand Down Expand Up @@ -358,7 +358,7 @@ private function upgrade_47() {
*
* @return void
*/
private function upgrade_49() {
protected function upgrade_49() {
global $wpdb;

/*
Expand Down Expand Up @@ -423,7 +423,7 @@ public function remove_about_notice( $notifications ) {
*
* @return void
*/
private function upgrade_50() {
protected function upgrade_50() {
global $wpdb;

// Deletes the post meta value, which might created in the RC.
Expand Down Expand Up @@ -560,7 +560,7 @@ private function upgrade_73() {
*
* @return void
*/
private function upgrade_74() {
protected function upgrade_74() {
$this->remove_sitemap_validators();
}

Expand Down Expand Up @@ -612,7 +612,7 @@ private function upgrade_772() {
*
* @return void
*/
private function upgrade_90() {
protected function upgrade_90() {
global $wpdb;

// Invalidate all sitemap cache transients.
Expand Down Expand Up @@ -1588,7 +1588,7 @@ public function remove_indexable_rows_for_non_public_taxonomies() {
*
* @return void
*/
private function deduplicate_unindexed_indexable_rows() {
protected function deduplicate_unindexed_indexable_rows() {
global $wpdb;

// If migrations haven't been completed successfully the following may give false errors. So suppress them.
Expand Down Expand Up @@ -1650,7 +1650,7 @@ private function deduplicate_unindexed_indexable_rows() {
*
* @return void
*/
private function clean_unindexed_indexable_rows_with_no_object_id() {
protected function clean_unindexed_indexable_rows_with_no_object_id() {
global $wpdb;

// If migrations haven't been completed successfully the following may give false errors. So suppress them.
Expand Down Expand Up @@ -1678,7 +1678,7 @@ private function clean_unindexed_indexable_rows_with_no_object_id() {
*
* @return void
*/
private function remove_indexable_rows_for_disabled_authors_archive() {
protected function remove_indexable_rows_for_disabled_authors_archive() {
global $wpdb;

if ( ! YoastSEO()->helpers->author_archive->are_disabled() ) {
Expand Down Expand Up @@ -1712,7 +1712,7 @@ private function remove_indexable_rows_for_disabled_authors_archive() {
*
* @return string The query that removes all but one duplicate for each object of the object type.
*/
private function get_indexable_deduplication_query_for_type( $object_type, $duplicates, $wpdb ) {
protected function get_indexable_deduplication_query_for_type( $object_type, $duplicates, $wpdb ) {
$indexable_table = Model::get_table_name( 'Indexable' );

$filtered_duplicates = array_filter(
Expand Down
10 changes: 5 additions & 5 deletions inc/sitemaps/class-sitemaps-cache-validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ public static function cleanup_database( $type = null, $validator = null ) {
}

/*
* Add slashes to the LIKE "_" single character wildcard.
*
* We can't use `esc_like` here because we need the % in the query.
*/
* Add slashes to the LIKE "_" single character wildcard.
*
* We can't use `esc_like` here because we need the % in the query.
*/
$where = [];
$where[] = sprintf( "option_name LIKE '%s'", addcslashes( '_transient_' . $like, '_' ) );
$where[] = sprintf( "option_name LIKE '%s'", addcslashes( '_transient_timeout_' . $like, '_' ) );
Expand All @@ -194,7 +194,7 @@ public static function cleanup_database( $type = null, $validator = null ) {
$wpdb->query(
$wpdb->prepare(
//phpcs:disable WordPress.DB.PreparedSQLPlaceholders -- %i placeholder is still not recognized.
'DELETE FROM %i WHERE ' . implode( ' OR', array_fill( 0, count( $where ), '%s' ) ),
'DELETE FROM %i WHERE ' . implode( ' OR ', array_fill( 0, count( $where ), '%s' ) ),
array_merge( [ $wpdb->options ], $where )
)
);
Expand Down
119 changes: 115 additions & 4 deletions tests/WP/Doubles/Inc/Upgrade_Double.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function cleanup_option_data( $option_name ) {
*
* @param string $option_name Option to retrieve.
*
* @return array|mixed The content of the option if exists, otherwise an empty array.
* @return array<int|bool|float|string|array[]> The content of the option if exists, otherwise an empty array.
*/
public function get_option_from_database( $option_name ) {
return parent::get_option_from_database( $option_name );
Expand All @@ -41,9 +41,9 @@ public function get_option_from_database( $option_name ) {
/**
* Test double. Saves an option setting to where it should be stored.
*
* @param array $source_data The option containing the value to be migrated.
* @param string $source_setting Name of the key in the "from" option.
* @param string|null $target_setting Name of the key in the "to" option.
* @param array<int|bool|float|string|array[]> $source_data The option containing the value to be migrated.
* @param string $source_setting Name of the key in the "from" option.
* @param string|null $target_setting Name of the key in the "to" option.
*
* @return void
*/
Expand All @@ -61,4 +61,115 @@ public function save_option_setting( $source_data, $source_setting, $target_sett
public function finish_up( $previous_version = null ) {
parent::finish_up( $previous_version );
}

/**
* Test double. Upgrades the plugin to version 3.6.
*
* @return void
*/
public function upgrade_36() {
parent::upgrade_36();
}

/**
* Test double. Upgrades the plugin to version 4.9.
*
* @return void
*/
public function upgrade_49() {
parent::upgrade_49();
}

/**
* Test double. Upgrades the plugin to version 5.0.
*
* @return void
*/
public function upgrade_50() {
parent::upgrade_50();
}

/**
* Test double. Upgrades the plugin to version 7.4.
*
* @return void
*/
public function upgrade_74() {
parent::upgrade_74();
}

/**
* Test double. Upgrades the plugin to version 9.0.
*
* @return void
*/
public function upgrade_90() {
parent::upgrade_90();
}

/**
* Test double. Upgrades the plugin to version 14.1.
*
* @return void
*/
public function clean_up_private_taxonomies_for_141() {
parent::clean_up_private_taxonomies_for_141();
}

/**
* Test double. Removes all the indexables for non-public post types.
*
* @return void
*/
public function remove_indexable_rows_for_non_public_post_types() {
parent::remove_indexable_rows_for_non_public_post_types();
}

/**
* Test double. Removes all the indexables for non-public taxonomies.
*
* @return void
*/
public function remove_indexable_rows_for_non_public_taxonomies() {
parent::remove_indexable_rows_for_non_public_taxonomies();
}

/**
* Test double. Removes all the indexables duplicates.
*
* @return void
*/
public function deduplicate_unindexed_indexable_rows() {
parent::deduplicate_unindexed_indexable_rows();
}

/**
* Test double. Removes all the indexables referring to unindexed elements with no id.
*
* @return void
*/
public function clean_unindexed_indexable_rows_with_no_object_id() {
parent::clean_unindexed_indexable_rows_with_no_object_id();
}

/**
* Test double. Removes all the user indexables when the author archive is disabled.
*
* @return void
*/
public function remove_indexable_rows_for_disabled_authors_archive() {
parent::remove_indexable_rows_for_disabled_authors_archive();
}

/**
* Test double. Gets the indexable deduplication query for a specific object type.
*
* @param string $object_type The object type to get the deduplication query for.
* @param array<int> $duplicates The duplicates to deduplicate.
* @param object $wpdb The WordPress database object.
* @return string The deduplication query.
*/
public function get_indexable_deduplication_query_for_type( $object_type, $duplicates, $wpdb ) {
return parent::get_indexable_deduplication_query_for_type( $object_type, $duplicates, $wpdb );
}
}
Loading

0 comments on commit 7fc2d47

Please sign in to comment.