Code Duplication    Length = 30-30 lines in 3 locations

tests/php/controller/proxycontrollerTest.php 3 locations

@@ 129-158 (lines=30) @@
126
		], $actual->getData());
127
	}
128
129
	public function testProxyConnectException() {
130
		$testUrl = 'http://abc.def/foobar?123';
131
132
		$this->client->expects($this->once())
133
			->method('newClient')
134
			->will($this->returnValue($this->newClient));
135
		$this->newClient->expects($this->once())
136
			->method('get')
137
			->with($testUrl, [
138
				'stream' => true,
139
			])
140
			->will($this->throwException(new ConnectException('Exception Message foo bar 42',
141
				$this->exceptionRequest, $this->exceptionResponse)));
142
		$this->l10n->expects($this->once())
143
			->method('t')
144
			->with($this->equalTo('Error connecting to remote server'))
145
			->will($this->returnValue('translated string 1337'));
146
		$this->logger->expects($this->once())
147
			->method('debug')
148
			->with($this->equalTo('Exception Message foo bar 42'));
149
150
		$actual = $this->controller->proxy($testUrl);
151
152
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
153
		$this->assertEquals('422', $actual->getStatus());
154
		$this->assertEquals([
155
			'message' => 'translated string 1337',
156
			'proxy_code' => -1
157
		], $actual->getData());
158
	}
159
160
	public function testProxyRequestExceptionHTTP() {
161
		$testUrl = 'http://abc.def/foobar?123';
@@ 160-189 (lines=30) @@
157
		], $actual->getData());
158
	}
159
160
	public function testProxyRequestExceptionHTTP() {
161
		$testUrl = 'http://abc.def/foobar?123';
162
163
		$this->client->expects($this->once())
164
			->method('newClient')
165
			->will($this->returnValue($this->newClient));
166
		$this->newClient->expects($this->once())
167
			->method('get')
168
			->with($testUrl, [
169
				'stream' => true,
170
			])
171
			->will($this->throwException(new RequestException('Exception Message foo bar 42',
172
				$this->exceptionRequest, $this->exceptionResponse)));
173
		$this->l10n->expects($this->once())
174
			->method('t')
175
			->with($this->equalTo('Error requesting resource on remote server'))
176
			->will($this->returnValue('translated string 1337'));
177
		$this->logger->expects($this->once())
178
			->method('debug')
179
			->with($this->equalTo('Exception Message foo bar 42'));
180
181
		$actual = $this->controller->proxy($testUrl);
182
183
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
184
		$this->assertEquals('422', $actual->getStatus());
185
		$this->assertEquals([
186
			'message' => 'translated string 1337',
187
			'proxy_code' => -2
188
		], $actual->getData());
189
	}
190
191
	public function testProxyRequestExceptionHTTPS() {
192
		$testUrl = 'https://abc.def/foobar?123';
@@ 191-220 (lines=30) @@
188
		], $actual->getData());
189
	}
190
191
	public function testProxyRequestExceptionHTTPS() {
192
		$testUrl = 'https://abc.def/foobar?123';
193
194
		$this->client->expects($this->once())
195
			->method('newClient')
196
			->will($this->returnValue($this->newClient));
197
		$this->newClient->expects($this->once())
198
			->method('get')
199
			->with($testUrl, [
200
				'stream' => true,
201
			])
202
			->will($this->throwException(new RequestException('Exception Message foo bar 42',
203
				$this->exceptionRequest, $this->exceptionResponse)));
204
		$this->l10n->expects($this->once())
205
			->method('t')
206
			->with($this->equalTo('Error requesting resource on remote server. This could possible be related to a certificate mismatch'))
207
			->will($this->returnValue('translated string 1337'));
208
		$this->logger->expects($this->once())
209
			->method('debug')
210
			->with($this->equalTo('Exception Message foo bar 42'));
211
212
		$actual = $this->controller->proxy($testUrl);
213
214
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
215
		$this->assertEquals('422', $actual->getStatus());
216
		$this->assertEquals([
217
			'message' => 'translated string 1337',
218
			'proxy_code' => -2
219
		], $actual->getData());
220
	}
221
}
222