@@ -108,11 +108,34 @@ function test_is_migrated() {
108
108
* @see Migrate::maybe_migrate()
109
109
*/
110
110
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 ) );
112
120
$ migrate ->maybe_migrate ();
113
121
$ this ->assertEquals ( 10 , has_action ( 'admin_notices ' , array ( $ migrate , 'show_migration_notice ' ) ) );
114
122
$ this ->assertEquals ( 10 , has_action ( 'admin_enqueue_scripts ' , array ( $ migrate , 'enqueue_script ' ) ) );
115
123
$ 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 ) );
116
139
}
117
140
118
141
/**
0 commit comments