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

Commit 71a4ae0

Browse files
committed
Fix unit-test
1 parent 40f153a commit 71a4ae0

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

tests/php/test-class-migrate.php

+24-1
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,34 @@ function test_is_migrated() {
108108
* @see Migrate::maybe_migrate()
109109
*/
110110
function test_maybe_migrate() {
111-
$migrate = new Migrate( $this->plugin );
111+
delete_option( Migrate::KEY );
112+
$migrate = $this->getMockBuilder( 'CustomizeSnapshots\Migrate' )
113+
->setMethods( array( 'changeset_migrate' ) )
114+
->setConstructorArgs( array( $this->plugin ) )
115+
->getMock();
116+
$migrate->expects( $this->once() )
117+
->method( 'changeset_migrate' )
118+
->with( 1, true )
119+
->will( $this->returnValue( 92 ) );
112120
$migrate->maybe_migrate();
113121
$this->assertEquals( 10, has_action( 'admin_notices', array( $migrate, 'show_migration_notice' ) ) );
114122
$this->assertEquals( 10, has_action( 'admin_enqueue_scripts', array( $migrate, 'enqueue_script' ) ) );
115123
$this->assertEquals( 10, has_action( 'wp_ajax_customize_snapshot_migration', array( $migrate, 'handle_migrate_changeset_request' ) ) );
124+
125+
// If no post to migrate fall back and add option value.
126+
$migrate_obj = $this->getMockBuilder( 'CustomizeSnapshots\Migrate' )
127+
->setMethods( array( 'changeset_migrate' ) )
128+
->setConstructorArgs( array( $this->plugin ) )
129+
->getMock();
130+
$migrate_obj->expects( $this->once() )
131+
->method( 'changeset_migrate' )
132+
->with( 1, true )
133+
->will( $this->returnValue( false ) );
134+
$migrate_obj->maybe_migrate();
135+
$this->assertNotEquals( 10, has_action( 'admin_notices', array( $migrate_obj, 'show_migration_notice' ) ) );
136+
$this->assertNotEquals( 10, has_action( 'admin_enqueue_scripts', array( $migrate_obj, 'enqueue_script' ) ) );
137+
$this->assertNotEquals( 10, has_action( 'wp_ajax_customize_snapshot_migration', array( $migrate_obj, 'handle_migrate_changeset_request' ) ) );
138+
$this->assertEquals( 1, get_option( Migrate::KEY ) );
116139
}
117140

118141
/**

tests/php/test-class-snapshot-ajax.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ function test_handle_migrate_changeset_request() {
4141
->setMethods( array( 'changeset_migrate' ) )
4242
->setConstructorArgs( array( $this->plugin ) )
4343
->getMock();
44-
$migrate_obj->expects( $this->once() )
44+
$migrate_obj->expects( $this->any() )
4545
->method( 'changeset_migrate' )
46-
->with( 1, false )
4746
->will( $this->returnValue( 92 ) );
4847
$migrate_obj->maybe_migrate();
4948
$this->set_input_vars(array(

0 commit comments

Comments
 (0)