@@ -145,23 +145,44 @@ public function test_is_needed() {
145145 public function maybe_add_preload_rest_paths_data () {
146146 return [
147147 'no_type_post ' => [
148- 'screen ' => 'user ' ,
149- 'post_type ' => '' ,
148+ 'set_up ' => static function () {
149+ set_current_screen ( 'user ' );
150+ },
150151 'should_preload_path ' => false ,
151152 ],
152153 'post_type_post ' => [
153- 'screen ' => 'edit ' ,
154- 'post_type ' => 'post ' ,
154+ 'set_up ' => static function () {
155+ set_current_screen ( 'edit ' );
156+ get_current_screen ()->post_type = 'post ' ;
157+ },
155158 'should_preload_path ' => false ,
156159 ],
157160 'post_type_page ' => [
158- 'screen ' => 'edit ' ,
159- 'post_type ' => 'page ' ,
161+ 'set_up ' => static function () {
162+ set_current_screen ( 'edit ' );
163+ get_current_screen ()->post_type = 'page ' ;
164+ },
160165 'should_preload_path ' => false ,
161166 ],
162167 'post_type_amp_validated_url ' => [
163- 'screen ' => 'edit ' ,
164- 'post_type ' => AMP_Validated_URL_Post_Type::POST_TYPE_SLUG ,
168+ 'set_up ' => static function () {
169+ set_current_screen ( 'edit ' );
170+ get_current_screen ()->post_type = AMP_Validated_URL_Post_Type::POST_TYPE_SLUG ;
171+ },
172+ 'should_preload_path ' => true ,
173+ ],
174+ 'settings_screen ' => [
175+ 'set_up ' => function () {
176+ global $ pagenow , $ plugin_page , $ menu ;
177+ $ pagenow = 'admin.php ' ;
178+ $ plugin_page = 'amp-options ' ;
179+ $ menu = [
180+ [
181+ 2 => $ plugin_page ,
182+ ],
183+ ];
184+ $ this ->assertEquals ( AMP_Options_Manager::OPTION_NAME , get_admin_page_parent () );
185+ },
165186 'should_preload_path ' => true ,
166187 ],
167188 ];
@@ -171,15 +192,12 @@ public function maybe_add_preload_rest_paths_data() {
171192 * @dataProvider maybe_add_preload_rest_paths_data
172193 * @covers ::maybe_add_preload_rest_paths()
173194 */
174- public function test_maybe_add_preload_rest_paths ( $ screen , $ post_type , $ should_preload_path ) {
195+ public function test_maybe_add_preload_rest_paths ( callable $ set_up , $ should_preload_path ) {
175196 if ( ! function_exists ( 'rest_preload_api_request ' ) ) {
176197 $ this ->markTestIncomplete ( 'REST preload is not available so skipping. ' );
177198 }
178199
179- set_current_screen ( $ screen );
180- if ( ! empty ( $ post_type ) ) {
181- get_current_screen ()->post_type = $ post_type ;
182- }
200+ $ set_up ();
183201
184202 $ this ->call_private_method ( $ this ->instance , 'maybe_add_preload_rest_paths ' );
185203
0 commit comments