-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Jetpack Sync: Ensure duplicate Sync modules are not loaded (#38503)
* Jetpack Sync: Ensure duplicate Sync modules are removed
- Loading branch information
Showing
5 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
4 changes: 4 additions & 0 deletions
4
projects/packages/sync/changelog/fix-sync-custom-config-modules-loaded-twice
This file contains 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,4 @@ | ||
Significance: patch | ||
Type: fixed | ||
|
||
Jetpack Sync: Ensure duplicate Sync modules are not loaded |
This file contains 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 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 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,63 @@ | ||
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName | ||
|
||
namespace Automattic\Jetpack\Sync; | ||
|
||
use WorDBless\BaseTestCase; | ||
|
||
/** | ||
* Unit tests for the Automattic\Jetpack\Sync\Modules class. | ||
* | ||
* @package automattic/jetpack-sync | ||
*/ | ||
class Test_Modules extends BaseTestCase { | ||
|
||
/** | ||
* Runs before every test in this class. | ||
*/ | ||
public function set_up() { | ||
// Reset private static properties after each test. | ||
$reflection_class = new \ReflectionClass( '\Automattic\Jetpack\Sync\Modules' ); | ||
try { | ||
$reflection_class->setStaticPropertyValue( 'initialized_modules', null ); | ||
} catch ( \ReflectionException $e ) { // PHP 7 compat | ||
$configured = $reflection_class->getProperty( 'initialized_modules' ); | ||
$configured->setAccessible( true ); | ||
$configured->setValue( null ); | ||
} | ||
} | ||
|
||
/** | ||
* Runs after every test in this class. | ||
*/ | ||
public function tear_down() { | ||
remove_filter( 'jetpack_sync_modules', array( $this, 'add_posts_module' ) ); | ||
} | ||
|
||
/** | ||
* Tests get_modules with duplicate modules. | ||
*/ | ||
public function test_get_modules_will_remove_duplicates() { | ||
add_filter( 'jetpack_sync_modules', array( $this, 'add_posts_module' ) ); | ||
|
||
$modules = Modules::get_modules(); | ||
$module_classes = array(); | ||
foreach ( $modules as $module ) { | ||
$module_classes[] = get_class( $module ); | ||
} | ||
|
||
$this->assertSame( Modules::DEFAULT_SYNC_MODULES, $module_classes ); | ||
} | ||
|
||
/** | ||
* Adds Sync Posts module to Sync's module list. | ||
* | ||
* @param array $sync_modules The list of sync modules declared prior to this filter. | ||
* | ||
* @return array A list of sync modules that now includes Posts modules. | ||
*/ | ||
public function add_posts_module( array $sync_modules ) { | ||
$sync_modules[] = 'Automattic\\Jetpack\\Sync\\Modules\\Posts'; | ||
|
||
return $sync_modules; | ||
} | ||
} |