Code Duplication    Length = 82-82 lines in 2 locations

tests/php/controller/viewcontrollerTest.php 2 locations

@@ 320-401 (lines=82) @@
317
	/**
318
	 * @dataProvider indexPublicDataProvider
319
	 */
320
	public function testPublicIndex($serverVersion, $isIE, $shareeActions, $shareeCanEdit) {
321
		$this->request->expects($this->once())
322
			->method('isUserAgent')
323
			->with(['/(MSIE)|(Trident)/'])
324
			->will($this->returnValue($isIE));
325
326
		$this->config->expects($this->at(0))
327
			->method('getSystemValue')
328
			->with('version')
329
			->will($this->returnValue($serverVersion));
330
331
		$this->config->expects($this->at(1))
332
			->method('getAppValue')
333
			->with($this->appName, 'installed_version')
334
			->will($this->returnValue('42.13.37'));
335
336
		$this->config->expects($this->at(2))
337
			->method('getAppValue')
338
			->with('theming', 'color', '#0082C9')
339
			->will($this->returnValue('#ff00ff'));
340
341
		$this->request->expects($this->at(1))
342
			->method('getServerProtocol')
343
			->will($this->returnValue('fancy_protocol'));
344
345
		$this->request->expects($this->at(2))
346
			->method('getServerHost')
347
			->will($this->returnValue('nextcloud-host.tld'));
348
349
		$this->request->expects($this->at(3))
350
			->method('getRequestUri')
351
			->will($this->returnValue('/request/uri/123/42'));
352
353
		$this->urlGenerator->expects($this->at(0))
354
			->method('imagePath')
355
			->with('core', 'favicon-touch.png')
356
			->will($this->returnValue('/core/img/foo'));
357
358
		$this->urlGenerator->expects($this->at(1))
359
			->method('getAbsoluteURL')
360
			->with('/core/img/foo')
361
			->will($this->returnValue('fancy_protocol://foo.bar/core/img/foo'));
362
363
		$this->urlGenerator->expects($this->at(2))
364
			->method('linkTo')
365
			->with('', 'remote.php')
366
			->will($this->returnValue('remote.php'));
367
368
		$this->urlGenerator->expects($this->at(3))
369
			->method('getAbsoluteURL')
370
			->with('remote.php/dav/public-calendars/fancy_token_123?export')
371
			->will($this->returnValue('fancy_protocol://foo.bar/remote.php/dav/public-calendars/fancy_token_123?export'));
372
373
		$this->request->expects($this->at(4))
374
			->method('getServerProtocol')
375
			->will($this->returnValue('fancy_protocol'));
376
377
		$actual = $this->controller->publicIndexForEmbedding('fancy_token_123');
378
379
		$this->assertInstanceOf('OCP\AppFramework\Http\TemplateResponse', $actual);
380
		$this->assertEquals([
381
			'appVersion' => '42.13.37',
382
			'initialView' => 'month',
383
			'emailAddress' => '',
384
			'skipPopover' => 'no',
385
			'weekNumbers' => 'no',
386
			'isPublic' => true,
387
			'isEmbedded' => true,
388
			'shareURL' => 'fancy_protocol://nextcloud-host.tld/request/uri/123/42',
389
			'previewImage' => 'fancy_protocol://foo.bar/core/img/foo',
390
			'firstRun' => 'no',
391
			'isIE' => $isIE,
392
			'defaultColor' => '#ff00ff',
393
			'webcalURL' => 'webcal://foo.bar/remote.php/dav/public-calendars/fancy_token_123?export',
394
			'downloadURL' => 'fancy_protocol://foo.bar/remote.php/dav/public-calendars/fancy_token_123?export',
395
			'token' => 'fancy_token_123',
396
			'shareeCanEditShares' => $shareeActions,
397
			'shareeCanEditCalendarProperties' => $shareeCanEdit,
398
			'canSharePublicLink' => 'no',
399
		], $actual->getParams());
400
		$this->assertEquals('main', $actual->getTemplateName());
401
	}
402
403
	/**
404
	 * @dataProvider indexPublicDataProvider
@@ 406-487 (lines=82) @@
403
	/**
404
	 * @dataProvider indexPublicDataProvider
405
	 */
406
	public function testPublicIndexWithBranding($serverVersion, $isIE, $shareeActions, $shareeCanEdit) {
407
		$this->request->expects($this->once())
408
			->method('isUserAgent')
409
			->with(['/(MSIE)|(Trident)/'])
410
			->will($this->returnValue($isIE));
411
412
		$this->config->expects($this->at(0))
413
			->method('getSystemValue')
414
			->with('version')
415
			->will($this->returnValue($serverVersion));
416
417
		$this->config->expects($this->at(1))
418
			->method('getAppValue')
419
			->with($this->appName, 'installed_version')
420
			->will($this->returnValue('42.13.37'));
421
422
		$this->config->expects($this->at(2))
423
			->method('getAppValue')
424
			->with('theming', 'color', '#0082C9')
425
			->will($this->returnValue('#ff00ff'));
426
427
		$this->request->expects($this->at(1))
428
			->method('getServerProtocol')
429
			->will($this->returnValue('fancy_protocol'));
430
431
		$this->request->expects($this->at(2))
432
			->method('getServerHost')
433
			->will($this->returnValue('nextcloud-host.tld'));
434
435
		$this->request->expects($this->at(3))
436
			->method('getRequestUri')
437
			->will($this->returnValue('/request/uri/123/42'));
438
439
		$this->urlGenerator->expects($this->at(0))
440
			->method('imagePath')
441
			->with('core', 'favicon-touch.png')
442
			->will($this->returnValue('/core/img/foo'));
443
444
		$this->urlGenerator->expects($this->at(1))
445
			->method('getAbsoluteURL')
446
			->with('/core/img/foo')
447
			->will($this->returnValue('fancy_protocol://foo.bar/core/img/foo'));
448
449
		$this->urlGenerator->expects($this->at(2))
450
			->method('linkTo')
451
			->with('', 'remote.php')
452
			->will($this->returnValue('remote.php'));
453
454
		$this->urlGenerator->expects($this->at(3))
455
			->method('getAbsoluteURL')
456
			->with('remote.php/dav/public-calendars/fancy_token_123?export')
457
			->will($this->returnValue('fancy_protocol://foo.bar/remote.php/dav/public-calendars/fancy_token_123?export'));
458
459
		$this->request->expects($this->at(4))
460
			->method('getServerProtocol')
461
			->will($this->returnValue('fancy_protocol'));
462
463
		$actual = $this->controller->publicIndexWithBranding('fancy_token_123');
464
465
		$this->assertInstanceOf('OCP\AppFramework\Http\TemplateResponse', $actual);
466
		$this->assertEquals([
467
			'appVersion' => '42.13.37',
468
			'initialView' => 'month',
469
			'emailAddress' => '',
470
			'skipPopover' => 'no',
471
			'weekNumbers' => 'no',
472
			'isPublic' => true,
473
			'isEmbedded' => false,
474
			'shareURL' => 'fancy_protocol://nextcloud-host.tld/request/uri/123/42',
475
			'previewImage' => 'fancy_protocol://foo.bar/core/img/foo',
476
			'firstRun' => 'no',
477
			'isIE' => $isIE,
478
			'defaultColor' => '#ff00ff',
479
			'webcalURL' => 'webcal://foo.bar/remote.php/dav/public-calendars/fancy_token_123?export',
480
			'downloadURL' => 'fancy_protocol://foo.bar/remote.php/dav/public-calendars/fancy_token_123?export',
481
			'token' => 'fancy_token_123',
482
			'shareeCanEditShares' => $shareeActions,
483
			'shareeCanEditCalendarProperties' => $shareeCanEdit,
484
			'canSharePublicLink' => 'no',
485
		], $actual->getParams());
486
		$this->assertEquals('public', $actual->getTemplateName());
487
	}
488
489
	public function indexPublicDataProvider() {
490
		return [