Code Duplication    Length = 87-87 lines in 2 locations

tests/php/controller/viewcontrollerTest.php 2 locations

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