Completed
Push — feature/reorg ( 2e8e86...35db6f )
by
unknown
25:00 queued 15:50
created

Test_Atomic_Admin_Menu   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 477
Duplicated Lines 47.8 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 228
loc 477
rs 10
c 0
b 0
f 0
wmc 18
lcom 1
cbo 2

16 Methods

Rating   Name   Duplication   Size   Complexity  
A test-class-atomic-admin-menu.php ➔ site_is_private() 0 3 1
A wpSetUpBeforeClass() 7 7 1
A setUp() 12 12 1
A test_get_instance() 9 9 1
A test_add_browse_sites_link() 0 7 1
A test_add_browse_sites_link_multisite() 0 29 2
A test_add_new_site_link() 0 21 1
A test_add_site_card_menu() 0 27 2
A test_set_site_card_menu_class() 0 26 2
A wpcomsh_site_icon_url() 0 3 1
A custom_site_icon_url() 0 3 1
A test_add_wpcom_upgrades_menu() 42 42 1
A test_jetpack_parent_file() 9 9 1
B test_add_users_menu() 63 63 1
B test_add_tools_menu() 76 76 1
A test_add_options_menu() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Tests for Atomic_Admin_Menu class.
4
 *
5
 * @package Jetpack
6
 */
7
8
use Automattic\Jetpack\Dashboard_Customizations\Atomic_Admin_Menu;
9
use Automattic\Jetpack\Status;
10
11
require_jetpack_file( 'modules/masterbar/admin-menu/class-admin-menu.php' );
12
require_jetpack_file( 'modules/masterbar/admin-menu/class-atomic-admin-menu.php' );
13
require_jetpack_file( 'tests/php/modules/masterbar/data/admin-menu.php' );
14
15
/**
16
 * Class Test_Atomic_Admin_Menu.
17
 *
18
 * @coversDefaultClass Automattic\Jetpack\Dashboard_Customizations\Atomic_Admin_Menu
19
 */
20
class Test_Atomic_Admin_Menu extends WP_UnitTestCase {
21
22
	/**
23
	 * Menu data fixture.
24
	 *
25
	 * @var array
26
	 */
27
	public static $menu_data;
28
29
	/**
30
	 * Submenu data fixture.
31
	 *
32
	 * @var array
33
	 */
34
	public static $submenu_data;
35
36
	/**
37
	 * Test domain.
38
	 *
39
	 * @var string
40
	 */
41
	public static $domain;
42
43
	/**
44
	 * Whether this testsuite is run on WP.com.
45
	 *
46
	 * @var bool
47
	 */
48
	public static $is_wpcom;
49
50
	/**
51
	 * Admin menu instance.
52
	 *
53
	 * @var Atomic_Admin_Menu
54
	 */
55
	public static $admin_menu;
56
57
	/**
58
	 * Mock user ID.
59
	 *
60
	 * @var int
61
	 */
62
	private static $user_id = 0;
63
64
	/**
65
	 * Create shared fixtures.
66
	 *
67
	 * @param WP_UnitTest_Factory $factory Fixture factory.
68
	 */
69 View Code Duplication
	public static function wpSetUpBeforeClass( $factory ) {
70
		static::$domain  = ( new Status() )->get_site_suffix();
71
		static::$user_id = $factory->user->create( array( 'role' => 'administrator' ) );
0 ignored issues
show
Bug introduced by
Since $user_id is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user_id to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
72
73
		static::$menu_data    = get_menu_fixture();
74
		static::$submenu_data = get_submenu_fixture();
75
	}
76
77
	/**
78
	 * Set up data.
79
	 */
80 View Code Duplication
	public function setUp() {
81
		parent::setUp();
82
		global $menu, $submenu;
83
84
		// Initialize in setUp so it registers hooks for every test.
85
		static::$admin_menu = Atomic_Admin_Menu::get_instance();
86
87
		$menu    = static::$menu_data;
88
		$submenu = static::$submenu_data;
89
90
		wp_set_current_user( static::$user_id );
0 ignored issues
show
Bug introduced by
Since $user_id is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user_id to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
91
	}
92
93
	/**
94
	 * Test get_instance.
95
	 *
96
	 * @covers ::get_instance
97
	 * @covers ::__construct
98
	 */
99 View Code Duplication
	public function test_get_instance() {
100
		$instance = Atomic_Admin_Menu::get_instance();
101
102
		$this->assertInstanceOf( Atomic_Admin_Menu::class, $instance );
103
		$this->assertSame( $instance, static::$admin_menu );
104
105
		$this->assertSame( 99999, has_action( 'admin_menu', array( $instance, 'reregister_menu_items' ) ) );
106
		$this->assertSame( 10, has_action( 'admin_enqueue_scripts', array( $instance, 'enqueue_scripts' ) ) );
107
	}
108
109
	/**
110
	 * Tests add_browse_sites_link.
111
	 *
112
	 * @covers ::add_browse_sites_link
113
	 */
114
	public function test_add_browse_sites_link() {
115
		global $menu;
116
117
		// No output when executed in single site mode.
118
		static::$admin_menu->add_browse_sites_link();
119
		$this->assertArrayNotHasKey( 0, $menu );
120
	}
121
122
	/**
123
	 * Tests add_browse_sites_link.
124
	 *
125
	 * @covers ::add_browse_sites_link
126
	 */
127
	public function test_add_browse_sites_link_multisite() {
128
		if ( ! is_multisite() ) {
129
			$this->markTestSkipped( 'Only used on multisite' );
130
		}
131
132
		global $menu;
133
134
		// No output when user has just one site.
135
		static::$admin_menu->add_browse_sites_link();
136
		$this->assertArrayNotHasKey( 0, $menu );
137
138
		// Give user a second site.
139
		set_transient( 'jetpack_connected_user_data_' . static::$user_id, array( 'site_count' => 2 ) );
0 ignored issues
show
Bug introduced by
Since $user_id is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user_id to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
140
141
		static::$admin_menu->add_browse_sites_link();
142
143
		$browse_sites_menu_item = array(
144
			'Browse sites',
145
			'read',
146
			'https://wordpress.com/home',
147
			'site-switcher',
148
			'menu-top toplevel_page_https://wordpress.com/home',
149
			'toplevel_page_https://wordpress.com/home',
150
			'dashicons-arrow-left-alt2',
151
		);
152
		$this->assertSame( $menu[0], $browse_sites_menu_item );
153
154
		delete_transient( 'jetpack_connected_user_data_' . static::$user_id );
0 ignored issues
show
Bug introduced by
Since $user_id is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user_id to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
155
	}
156
157
	/**
158
	 * Tests add_new_site_link.
159
	 *
160
	 * @covers ::add_new_site_link
161
	 */
162
	public function test_add_new_site_link() {
163
		global $menu;
164
165
		// Set jetpack user data.
166
		set_transient( 'jetpack_connected_user_data_' . static::$user_id, array( 'site_count' => 1 ) );
0 ignored issues
show
Bug introduced by
Since $user_id is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user_id to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
167
168
		static::$admin_menu->add_new_site_link();
169
170
		$new_site_menu_item = array(
171
			'Add new site',
172
			'read',
173
			'https://wordpress.com/start?ref=calypso-sidebar',
174
			'Add new site',
175
			'menu-top toplevel_page_https://wordpress.com/start?ref=calypso-sidebar',
176
			'toplevel_page_https://wordpress.com/start?ref=calypso-sidebar',
177
			'dashicons-plus-alt',
178
		);
179
		$this->assertSame( $menu[1002], $new_site_menu_item ); // 1001 is the separator position, 1002 is the link position
180
181
		delete_transient( 'jetpack_connected_user_data_' . static::$user_id );
0 ignored issues
show
Bug introduced by
Since $user_id is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user_id to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
182
	}
183
184
	/**
185
	 * Tests add_site_card_menu
186
	 *
187
	 * @covers ::add_site_card_menu
188
	 */
189
	public function test_add_site_card_menu() {
190
		global $menu;
191
192
		if ( ! function_exists( 'site_is_private' ) ) {
193
			function site_is_private() { // phpcs:ignore
194
				return false;
195
			}
196
		}
197
		static::$admin_menu->add_site_card_menu();
198
199
		$home_url            = home_url();
200
		$site_card_menu_item = array(
201
			// phpcs:ignore Squiz.Strings.DoubleQuoteUsage.NotRequired
202
			'
203
<div class="site__info">
204
	<div class="site__title">' . get_option( 'blogname' ) . '</div>
205
	<div class="site__domain">' . static::$domain . "</div>\n\t\n</div>",
206
			'read',
207
			$home_url,
208
			'site-card',
209
			'menu-top toplevel_page_' . $home_url,
210
			'toplevel_page_' . $home_url,
211
			'data:image/svg+xml,%3Csvg%20class%3D%22gridicon%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Ctitle%3EGlobe%3C%2Ftitle%3E%3Crect%20fill-opacity%3D%220%22%20x%3D%220%22%20width%3D%2224%22%20height%3D%2224%22%2F%3E%3Cg%3E%3Cpath%20fill%3D%22%23fff%22%20d%3D%22M12%202C6.477%202%202%206.477%202%2012s4.477%2010%2010%2010%2010-4.477%2010-10S17.523%202%2012%202zm0%2018l2-2%201-1v-2h-2v-1l-1-1H9v3l2%202v1.93c-3.94-.494-7-3.858-7-7.93l1%201h2v-2h2l3-3V6h-2L9%205v-.41C9.927%204.21%2010.94%204%2012%204s2.073.212%203%20.59V6l-1%201v2l1%201%203.13-3.13c.752.897%201.304%201.964%201.606%203.13H18l-2%202v2l1%201h2l.286.286C18.03%2018.06%2015.24%2020%2012%2020z%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E',
212
		);
213
214
		$this->assertEquals( $menu[1], $site_card_menu_item );
215
	}
216
217
	/**
218
	 * Tests set_site_card_menu_class
219
	 *
220
	 * @covers ::set_site_card_menu_class
221
	 */
222
	public function test_set_site_card_menu_class() {
223
		global $menu;
224
225
		if ( ! function_exists( 'site_is_private' ) ) {
226
			function site_is_private() { // phpcs:ignore
0 ignored issues
show
Best Practice introduced by
The function site_is_private() has been defined more than once; this definition is ignored, only the first definition in this file (L193-195) is considered.

This check looks for functions that have already been defined in the same file.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
227
				return false;
228
			}
229
		}
230
231
		static::$admin_menu->add_site_card_menu();
232
233
		$menu = static::$admin_menu->set_site_card_menu_class( $menu );
234
		$this->assertNotContains( 'has-site-icon', $menu[1][4] );
235
236
		// Atomic fallback site icon counts as no site icon.
237
		add_filter( 'get_site_icon_url', array( $this, 'wpcomsh_site_icon_url' ) );
238
		$menu = static::$admin_menu->set_site_card_menu_class( $menu );
239
		remove_filter( 'get_site_icon_url', array( $this, 'wpcomsh_site_icon_url' ) );
240
		$this->assertNotContains( 'has-site-icon', $menu[1][4] );
241
242
		// Custom site icon triggers CSS class.
243
		add_filter( 'get_site_icon_url', array( $this, 'custom_site_icon_url' ) );
244
		$menu = static::$admin_menu->set_site_card_menu_class( $menu );
245
		remove_filter( 'get_site_icon_url', array( $this, 'custom_site_icon_url' ) );
246
		$this->assertContains( 'has-site-icon', $menu[1][4] );
247
	}
248
249
	/**
250
	 * Shim wpcomsh fallback site icon.
251
	 *
252
	 * @return string
253
	 */
254
	public function wpcomsh_site_icon_url() {
255
		return 'https://s0.wp.com/i/webclip.png';
256
	}
257
258
	/**
259
	 * Custom site icon.
260
	 *
261
	 * @return string
262
	 */
263
	public function custom_site_icon_url() {
264
		return 'https://s0.wp.com/i/jetpack.png';
265
	}
266
267
	/**
268
	 * Tests add_upgrades_menu
269
	 *
270
	 * @covers ::add_upgrades_menu
271
	 */
272 View Code Duplication
	public function test_add_wpcom_upgrades_menu() {
273
		global $menu, $submenu;
274
275
		static::$admin_menu->add_upgrades_menu();
276
277
		$slug = 'https://wordpress.com/plans/' . static::$domain;
278
279
		$upgrades_menu_item = array(
280
			'Upgrades',
281
			'manage_options',
282
			$slug,
283
			'Upgrades',
284
			'menu-top toplevel_page_https://wordpress.com/plans/' . static::$domain,
285
			'toplevel_page_https://wordpress.com/plans/' . static::$domain,
286
			'dashicons-cart',
287
		);
288
		$this->assertSame( $menu['4.80608'], $upgrades_menu_item );
289
290
		$plans_submenu_item = array(
291
			'Plans',
292
			'manage_options',
293
			$slug,
294
			'Plans',
295
		);
296
		$this->assertContains( $plans_submenu_item, $submenu[ $slug ] );
297
298
		$domains_submenu_item = array(
299
			'Domains',
300
			'manage_options',
301
			'https://wordpress.com/domains/manage/' . static::$domain,
302
			'Domains',
303
		);
304
		$this->assertContains( $domains_submenu_item, $submenu[ $slug ] );
305
306
		$purchases_submenu_item = array(
307
			'Purchases',
308
			'manage_options',
309
			'https://wordpress.com/purchases/subscriptions/' . static::$domain,
310
			'Purchases',
311
		);
312
		$this->assertContains( $purchases_submenu_item, $submenu[ $slug ] );
313
	}
314
315
	/**
316
	 * Tests jetpack_parent_file
317
	 *
318
	 * @covers ::jetpack_parent_file
319
	 */
320 View Code Duplication
	public function test_jetpack_parent_file() {
321
		$parent_file = 'edit.php';
322
		$this->assertSame( $parent_file, static::$admin_menu->jetpack_parent_file( $parent_file ) );
323
324
		$this->assertSame(
325
			'https://wordpress.com/activity-log/' . static::$domain,
326
			static::$admin_menu->jetpack_parent_file( 'jetpack' )
327
		);
328
	}
329
330
	/**
331
	 * Tests add_users_menu
332
	 *
333
	 * @covers ::add_users_menu
334
	 */
335 View Code Duplication
	public function test_add_users_menu() {
336
		global $menu, $submenu;
337
338
		// Current user can't list users.
339
		wp_set_current_user( $this->factory->user->create( array( 'role' => 'editor' ) ) );
340
		$menu = array();
341
342
		static::$admin_menu->add_users_menu( true );
343
344
		$this->assertEmpty( $menu );
345
346
		// Reset.
347
		wp_set_current_user( static::$user_id );
0 ignored issues
show
Bug introduced by
Since $user_id is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user_id to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
348
		$menu = static::$menu_data;
349
350
		static::$admin_menu->add_users_menu( static::$domain );
0 ignored issues
show
Documentation introduced by
static::$domain is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
351
352
		$slug = 'https://wordpress.com/people/team/' . static::$domain;
353
354
		$users_menu_item = array(
355
			'Users',
356
			'list_users',
357
			$slug,
358
			'Users',
359
			'menu-top toplevel_page_' . $slug,
360
			'toplevel_page_' . $slug,
361
			'dashicons-admin-users',
362
		);
363
		$this->assertSame( $menu[70], $users_menu_item );
364
		$this->assertEmpty( $submenu['users.php'] );
365
366
		$all_people_submenu_item = array(
367
			'All People',
368
			'list_users',
369
			$slug,
370
			'All People',
371
		);
372
		$this->assertContains( $all_people_submenu_item, $submenu[ $slug ] );
373
374
		$add_new_submenu_item = array(
375
			'Add New',
376
			'promote_users',
377
			'https://wordpress.com/people/new/' . static::$domain,
378
			'Add New',
379
		);
380
		$this->assertContains( $add_new_submenu_item, $submenu[ $slug ] );
381
382
		$profile_submenu_item = array(
383
			'My Profile',
384
			'read',
385
			'https://wordpress.com/me',
386
			'My Profile',
387
		);
388
		$this->assertContains( $profile_submenu_item, $submenu[ $slug ] );
389
390
		$account_submenu_item = array(
391
			'Account Settings',
392
			'read',
393
			'https://wordpress.com/me/account',
394
			'Account Settings',
395
		);
396
		$this->assertContains( $account_submenu_item, $submenu[ $slug ] );
397
	}
398
399
	/**
400
	 * Tests add_tools_menu
401
	 *
402
	 * @covers ::add_tools_menu
403
	 */
404 View Code Duplication
	public function test_add_tools_menu() {
405
		global $menu, $submenu;
406
407
		$slug = 'https://wordpress.com/marketing/tools/' . static::$domain;
408
		static::$admin_menu->add_tools_menu( static::$domain );
0 ignored issues
show
Documentation introduced by
static::$domain is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
409
410
		$tools_menu_item = array(
411
			'Tools',
412
			'manage_options',
413
			$slug,
414
			'Tools',
415
			'menu-top toplevel_page_' . $slug,
416
			'toplevel_page_' . $slug,
417
			'dashicons-admin-tools',
418
		);
419
420
		$this->assertSame( $menu[75], $tools_menu_item );
421
		$this->assertArrayNotHasKey( 'tools.php', $submenu );
422
423
		// Contains the following menu items.
424
425
		$marketing_submenu_item = array(
426
			'Marketing',
427
			'manage_options',
428
			'https://wordpress.com/marketing/tools/' . static::$domain,
429
			'Marketing',
430
		);
431
		$this->assertContains( $marketing_submenu_item, $submenu[ $slug ] );
432
433
		$earn_submenu_item = array(
434
			'Earn',
435
			'manage_options',
436
			'https://wordpress.com/earn/' . static::$domain,
437
			'Earn',
438
		);
439
		$this->assertContains( $earn_submenu_item, $submenu[ $slug ] );
440
441
		$import_submenu_item = array(
442
			'Import',
443
			'import',
444
			'https://wordpress.com/import/' . static::$domain,
445
			'Import',
446
		);
447
		$this->assertContains( $import_submenu_item, $submenu[ $slug ] );
448
449
		$export_submenu_item = array(
450
			'Export',
451
			'export',
452
			'https://wordpress.com/export/' . static::$domain,
453
			'Export',
454
		);
455
		$this->assertContains( $export_submenu_item, $submenu[ $slug ] );
456
457
		// NOT contains the following menu items.
458
459
		$tools_submenu_item = array(
460
			'Available Tools',
461
			'edit_posts',
462
			'tools.php',
463
		);
464
		$this->assertNotContains( $tools_submenu_item, $submenu[ $slug ] );
465
466
		$import_submenu_item = array(
467
			'Import',
468
			'import',
469
			'import.php',
470
		);
471
		$this->assertNotContains( $import_submenu_item, $submenu[ $slug ] );
472
473
		$export_submenu_item = array(
474
			'Export',
475
			'export',
476
			'export.php',
477
		);
478
		$this->assertNotContains( $export_submenu_item, $submenu[ $slug ] );
479
	}
480
481
	/**
482
	 * Tests add_options_menu
483
	 *
484
	 * @covers ::add_options_menu
485
	 */
486 View Code Duplication
	public function test_add_options_menu() {
487
		global $submenu;
488
489
		static::$admin_menu->add_options_menu( static::$domain );
0 ignored issues
show
Documentation introduced by
static::$domain is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
490
491
		$this->assertNotContains( 'options-discussion.php', $submenu['options-general.php'] );
492
		$this->assertNotContains( 'options-writing.php', $submenu['options-general.php'] );
493
494
		$this->assertContains( 'Hosting Configuration', $submenu['options-general.php'][6] );
495
	}
496
}
497