Code Duplication    Length = 20-20 lines in 3 locations

packages/autoloader/tests/php/tests/unit/test-plugin-locator.php 3 locations

@@ 110-129 (lines=20) @@
107
	/**
108
	 * Tests that it can guess plugins that are stored in an option.
109
	 */
110
	public function test_using_option_finds_in_option() {
111
		add_test_option(
112
			'test_plugin_paths',
113
			array( 'dummy_current/dummy_current.php' )
114
		);
115
116
		$this->path_processor->expects( $this->exactly( 2 ) )
117
			->method( 'find_directory_with_autoloader' )
118
			->withConsecutive(
119
				array( 0 ),
120
				array( 'dummy_current/dummy_current.php' )
121
			)
122
			->willReturnOnConsecutiveCalls( false, TEST_DATA_PATH . '/plugins/dummy_current' );
123
124
		$plugin_paths = $this->locator->find_using_option( 'test_plugin_paths' );
125
126
		$this->assertTrue( is_array( $plugin_paths ) );
127
		$this->assertCount( 1, $plugin_paths );
128
		$this->assertContains( TEST_DATA_PATH . '/plugins/dummy_current', $plugin_paths );
129
	}
130
131
	/**
132
	 * Tests that it can find plugins that are stored in a site option.
@@ 134-153 (lines=20) @@
131
	/**
132
	 * Tests that it can find plugins that are stored in a site option.
133
	 */
134
	public function test_using_option_finds_in_site_option() {
135
		add_test_site_option(
136
			'test_plugin_paths',
137
			array( 'dummy_current/dummy_current.php' )
138
		);
139
140
		$this->path_processor->expects( $this->exactly( 2 ) )
141
			->method( 'find_directory_with_autoloader' )
142
			->withConsecutive(
143
				array( 0 ),
144
				array( 'dummy_current/dummy_current.php' )
145
			)
146
			->willReturnOnConsecutiveCalls( false, TEST_DATA_PATH . '/plugins/dummy_current' );
147
148
		$plugin_paths = $this->locator->find_using_option( 'test_plugin_paths', true );
149
150
		$this->assertTrue( is_array( $plugin_paths ) );
151
		$this->assertCount( 1, $plugin_paths );
152
		$this->assertContains( TEST_DATA_PATH . '/plugins/dummy_current', $plugin_paths );
153
	}
154
155
	/**
156
	 * Tests that it can guess plugins that are stored in an option's key.
@@ 158-177 (lines=20) @@
155
	/**
156
	 * Tests that it can guess plugins that are stored in an option's key.
157
	 */
158
	public function test_using_option_finds_plugin_in_key() {
159
		add_test_option(
160
			'test_plugin_paths',
161
			array( 'dummy_current/dummy_current.php' => 123456 )
162
		);
163
164
		$this->path_processor->expects( $this->exactly( 2 ) )
165
			->method( 'find_directory_with_autoloader' )
166
			->withConsecutive(
167
				array( 'dummy_current/dummy_current.php' ),
168
				array( 123456 )
169
			)
170
			->willReturnOnConsecutiveCalls( TEST_DATA_PATH . '/plugins/dummy_current', false );
171
172
		$plugin_paths = $this->locator->find_using_option( 'test_plugin_paths' );
173
174
		$this->assertTrue( is_array( $plugin_paths ) );
175
		$this->assertCount( 1, $plugin_paths );
176
		$this->assertContains( TEST_DATA_PATH . '/plugins/dummy_current', $plugin_paths );
177
	}
178
179
	/**
180
	 * Tests that plugins activating this request are not discovered if a nonce is not set.