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 // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
||
| 13 | class PluginsHandlerTest extends TestCase { |
||
| 14 | |||
| 15 | const DEFAULT_ACTIVE_PLUGINS = array( 'test1/test1.php', 'test2/test2.php' ); |
||
| 16 | const DEFAULT_MULTISITE_PLUGINS = array( |
||
| 17 | 'multi1/multi1.php' => 'details', |
||
| 18 | 'multi2/multi2.php' => 'details', |
||
| 19 | ); |
||
| 20 | |||
| 21 | /** |
||
| 22 | * This method is called before each test. |
||
| 23 | */ |
||
| 24 | public function setUp() { |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Set up mock Plugins_Handler methods. |
||
| 38 | * |
||
| 39 | * @param Array $active_plugins The names of the active plugins. |
||
| 40 | * @param Boolean $use_multisite Whether the env is multisite. |
||
| 41 | */ |
||
| 42 | private function set_up_mocks( |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Tests is_directory_plugin() with a single-file plugin. |
||
| 63 | * |
||
| 64 | * @covers Plugins_Handler::is_directory_plugin |
||
| 65 | */ |
||
| 66 | public function test_is_directory_plugin_single_file() { |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Tests is_directory_plugin() with a single-file plugin that begins with '/'. |
||
| 72 | * |
||
| 73 | * @covers Plugins_Handler::is_directory_plugin |
||
| 74 | */ |
||
| 75 | public function test_is_directory_plugin_single_file_with_slash() { |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Tests is_directory_plugin() with a plugin with a directory. |
||
| 81 | * |
||
| 82 | * @covers Plugins_Handler::is_directory_plugin |
||
| 83 | */ |
||
| 84 | public function test_is_directory_plugin_dir() { |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Tests should_autoloader_reset() with an already active plugin. |
||
| 90 | * |
||
| 91 | * @covers Plugins_Handler::should_autoloader_reset |
||
| 92 | */ |
||
| 93 | public function test_should_autoloader_reset_known_plugin() { |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Tests should_autoloader_reset() with an activating, unknown plugin. |
||
| 109 | * |
||
| 110 | * @covers Plugins_Handler::should_autoloader_reset |
||
| 111 | */ |
||
| 112 | public function test_should_autoloader_reset_unknown_plugin() { |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Tests get_all_active_plugins() with activating plugins (via request and |
||
| 131 | * non-request methods) and a list of active plugins. |
||
| 132 | * |
||
| 133 | * @covers Plugins_Handler::get_all_active_plugins |
||
| 134 | */ |
||
| 135 | public function test_get_all_active_plugins_everything() { |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Tests get_all_active_plugins() with multiple plugins activating (via request and |
||
| 163 | * non-request methods) and a list of active plugins. |
||
| 164 | * |
||
| 165 | * @covers Plugins_Handler::get_all_active_plugins |
||
| 166 | */ |
||
| 167 | public function test_get_all_active_plugins_multiple_activating() { |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Tests get_all_active_plugins() with no nonce included in the request. Since |
||
| 201 | * a nonce isn't included, the plugin will not be activated. |
||
| 202 | * |
||
| 203 | * @covers Plugins_Handler::get_all_active_plugins |
||
| 204 | */ |
||
| 205 | public function test_get_all_active_plugins_no_nonce() { |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Tests get_all_active_plugins() with no activating plugins. |
||
| 232 | * |
||
| 233 | * @covers Plugins_Handler::get_all_active_plugins |
||
| 234 | */ |
||
| 235 | public function test_get_all_active_plugins_no_activating() { |
||
| 249 | |||
| 250 | |||
| 251 | /** |
||
| 252 | * Tests get_all_active_plugins() with no activating plugins and a single |
||
| 253 | * active plugin. |
||
| 254 | * |
||
| 255 | * @covers Plugins_Handler::get_all_active_plugins |
||
| 256 | */ |
||
| 257 | public function test_get_all_active_plugins_single_active() { |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Tests get_all_active_plugins() with an active single-file plugin and single-file |
||
| 268 | * plugins skipped. |
||
| 269 | * |
||
| 270 | * @covers Plugins_Handler::get_all_active_plugins |
||
| 271 | */ |
||
| 272 | View Code Duplication | public function test_get_all_active_plugins_single_file_plugin_skip() { |
|
| 281 | |||
| 282 | /** |
||
| 283 | * Tests get_all_active_plugins with a single-file plugin and single-file |
||
| 284 | * plugins not skipped. |
||
| 285 | * |
||
| 286 | * @covers Plugins_Handler::get_all_active_plugins |
||
| 287 | */ |
||
| 288 | View Code Duplication | public function test_get_all_active_plugins_single_file_plugin_dont_skip() { |
|
| 296 | |||
| 297 | /** |
||
| 298 | * Tests get_all_active_plugins with activating plugins (via request and |
||
| 299 | * non-request methods) and a list of active plugins. |
||
| 300 | * |
||
| 301 | * @covers Plugins_Handler::get_all_active_plugins |
||
| 302 | */ |
||
| 303 | public function test_get_all_active_plugins_multisite() { |
||
| 328 | } |
||
| 329 |