Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #124 from xwp/fix/123
Browse files Browse the repository at this point in the history
Fix migration notice on new WP install
  • Loading branch information
westonruter committed Feb 27, 2017
2 parents bdfb0ec + 71a4ae0 commit bf0f7f7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
5 changes: 5 additions & 0 deletions php/class-migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public function is_migrated() {
*/
public function maybe_migrate() {
if ( ! $this->is_migrated() ) {
$found_post = $this->changeset_migrate( 1, true );
if ( empty( $found_post ) ) {
update_option( self::KEY, 1 );
return;
}
add_action( 'admin_notices', array( $this, 'show_migration_notice' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_script' ) );
add_action( 'wp_ajax_customize_snapshot_migration', array( $this, 'handle_migrate_changeset_request' ) );
Expand Down
25 changes: 24 additions & 1 deletion tests/php/test-class-migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,34 @@ function test_is_migrated() {
* @see Migrate::maybe_migrate()
*/
function test_maybe_migrate() {
$migrate = new Migrate( $this->plugin );
delete_option( Migrate::KEY );
$migrate = $this->getMockBuilder( 'CustomizeSnapshots\Migrate' )
->setMethods( array( 'changeset_migrate' ) )
->setConstructorArgs( array( $this->plugin ) )
->getMock();
$migrate->expects( $this->once() )
->method( 'changeset_migrate' )
->with( 1, true )
->will( $this->returnValue( 92 ) );
$migrate->maybe_migrate();
$this->assertEquals( 10, has_action( 'admin_notices', array( $migrate, 'show_migration_notice' ) ) );
$this->assertEquals( 10, has_action( 'admin_enqueue_scripts', array( $migrate, 'enqueue_script' ) ) );
$this->assertEquals( 10, has_action( 'wp_ajax_customize_snapshot_migration', array( $migrate, 'handle_migrate_changeset_request' ) ) );

// If no post to migrate fall back and add option value.
$migrate_obj = $this->getMockBuilder( 'CustomizeSnapshots\Migrate' )
->setMethods( array( 'changeset_migrate' ) )
->setConstructorArgs( array( $this->plugin ) )
->getMock();
$migrate_obj->expects( $this->once() )
->method( 'changeset_migrate' )
->with( 1, true )
->will( $this->returnValue( false ) );
$migrate_obj->maybe_migrate();
$this->assertNotEquals( 10, has_action( 'admin_notices', array( $migrate_obj, 'show_migration_notice' ) ) );
$this->assertNotEquals( 10, has_action( 'admin_enqueue_scripts', array( $migrate_obj, 'enqueue_script' ) ) );
$this->assertNotEquals( 10, has_action( 'wp_ajax_customize_snapshot_migration', array( $migrate_obj, 'handle_migrate_changeset_request' ) ) );
$this->assertEquals( 1, get_option( Migrate::KEY ) );
}

/**
Expand Down
3 changes: 1 addition & 2 deletions tests/php/test-class-snapshot-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ function test_handle_migrate_changeset_request() {
->setMethods( array( 'changeset_migrate' ) )
->setConstructorArgs( array( $this->plugin ) )
->getMock();
$migrate_obj->expects( $this->once() )
$migrate_obj->expects( $this->any() )
->method( 'changeset_migrate' )
->with( 1, false )
->will( $this->returnValue( 92 ) );
$migrate_obj->maybe_migrate();
$this->set_input_vars(array(
Expand Down

0 comments on commit bf0f7f7

Please sign in to comment.