Code Duplication    Length = 20-21 lines in 2 locations

tests/core/avatar/avatarcontrollertest.php 2 locations

@@ 260-280 (lines=21) @@
257
	/**
258
	 * Test a correct post of an avatar using POST
259
	 */
260
	public function testPostAvatarFile() {
261
		//Create temp file
262
		$fileName = tempnam(null, "avatarTest");
263
		$copyRes = copy(OC::$SERVERROOT.'/tests/data/testimage.jpg', $fileName);
264
		$this->assertTrue($copyRes);
265
266
		//Create file in cache
267
		$this->container['Cache']->method('get')->willReturn(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.jpg'));
268
269
		//Create request return
270
		$reqRet = ['error' => [0], 'tmp_name' => [$fileName], 'size' => [filesize(OC::$SERVERROOT.'/tests/data/testimage.jpg')]];
271
		$this->container['Request']->method('getUploadedFile')->willReturn($reqRet);
272
273
		$response = $this->avatarController->postAvatar(null);
274
275
		//On correct upload always respond with the notsquare message
276
		$this->assertEquals('notsquare', $response->getData()['data']);
277
278
		//File should be deleted
279
		$this->assertFalse(file_exists($fileName));
280
	}
281
282
	/**
283
	 * Test invalid post os an avatar using POST
@@ 298-317 (lines=20) @@
295
	/**
296
	 * Check what happens when we upload a GIF
297
	 */
298
	public function testPostAvatarFileGif() {
299
		//Create temp file
300
		$fileName = tempnam(null, "avatarTest");
301
		$copyRes = copy(OC::$SERVERROOT.'/tests/data/testimage.gif', $fileName);
302
		$this->assertTrue($copyRes);
303
304
		//Create file in cache
305
		$this->container['Cache']->method('get')->willReturn(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.gif'));
306
307
		//Create request return
308
		$reqRet = ['error' => [0], 'tmp_name' => [$fileName], 'size' => filesize(OC::$SERVERROOT.'/tests/data/testimage.gif')];
309
		$this->container['Request']->method('getUploadedFile')->willReturn($reqRet);
310
311
		$response = $this->avatarController->postAvatar(null);
312
313
		$this->assertEquals('Unknown filetype', $response->getData()['data']['message']);
314
315
		//File should be deleted
316
		$this->assertFalse(file_exists($fileName));
317
	}
318
319
	/**
320
	 * Test posting avatar from existing file