Code Duplication    Length = 105-105 lines in 2 locations

tests/php/controller/viewcontrollerTest.php 2 locations

@@ 359-463 (lines=105) @@
356
	/**
357
	 * @dataProvider indexPublicDataProvider
358
	 */
359
	public function testPublicIndex($isAssetPipelineEnabled, $showAssetPipelineError, $serverVersion, $expectsSupportsClass, $needsAutosize, $isIE) {
360
		$this->config->expects($this->at(0))
361
			->method('getSystemValue')
362
			->with('version')
363
			->will($this->returnValue($serverVersion));
364
365
		$this->config->expects($this->at(1))
366
			->method('getSystemValue')
367
			->with('asset-pipeline.enabled', false)
368
			->will($this->returnValue($isAssetPipelineEnabled));
369
370
		if (!$showAssetPipelineError) {
371
			$this->request->expects($this->once())
372
				->method('isUserAgent')
373
				->with(['/(MSIE)|(Trident)/'])
374
				->will($this->returnValue($isIE));
375
		}
376
377
		if ($showAssetPipelineError) {
378
			$actual = $this->controller->index();
379
380
			$this->assertInstanceOf('OCP\AppFramework\Http\TemplateResponse', $actual);
381
			$this->assertEquals([], $actual->getParams());
382
			$this->assertEquals('main-asset-pipeline-unsupported', $actual->getTemplateName());
383
		} else {
384
			$this->config->expects($this->at(2))
385
				->method('getSystemValue')
386
				->with('version')
387
				->will($this->returnValue($serverVersion));
388
389
			$this->config->expects($this->at(3))
390
				->method('getAppValue')
391
				->with($this->appName, 'installed_version')
392
				->will($this->returnValue('42.13.37'));
393
394
			$this->config->expects($this->at(4))
395
				->method('getAppValue')
396
				->with('theming', 'color', '#0082C9')
397
				->will($this->returnValue('#ff00ff'));
398
399
			$this->request->expects($this->at(1))
400
				->method('getServerProtocol')
401
				->will($this->returnValue('fancy_protocol'));
402
403
			$this->request->expects($this->at(2))
404
				->method('getServerHost')
405
				->will($this->returnValue('nextcloud-host.tld'));
406
407
			$this->request->expects($this->at(3))
408
				->method('getRequestUri')
409
				->will($this->returnValue('/request/uri/123/42'));
410
411
			$this->urlGenerator->expects($this->at(0))
412
				->method('imagePath')
413
				->with('core', 'favicon-touch.png')
414
				->will($this->returnValue('/core/img/foo'));
415
416
			$this->urlGenerator->expects($this->at(1))
417
				->method('getAbsoluteURL')
418
				->with('/core/img/foo')
419
				->will($this->returnValue('fancy_protocol://foo.bar/core/img/foo'));
420
421
			$this->urlGenerator->expects($this->at(2))
422
				->method('linkTo')
423
				->with('', 'remote.php')
424
				->will($this->returnValue('remote.php'));
425
426
			$this->urlGenerator->expects($this->at(3))
427
				->method('getAbsoluteURL')
428
				->with('remote.php/dav/public-calendars/fancy_token_123?export')
429
				->will($this->returnValue('fancy_protocol://foo.bar/remote.php/dav/public-calendars/fancy_token_123?export'));
430
431
			$this->request->expects($this->at(4))
432
				->method('getServerProtocol')
433
				->will($this->returnValue('fancy_protocol'));
434
435
436
437
			$actual = $this->controller->publicIndex('fancy_token_123');
438
439
			$this->assertInstanceOf('OCP\AppFramework\Http\TemplateResponse', $actual);
440
			$this->assertEquals([
441
				'appVersion' => '42.13.37',
442
				'initialView' => 'month',
443
				'emailAddress' => '',
444
				'skipPopover' => 'no',
445
				'weekNumbers' => 'no',
446
				'supportsClass' => $expectsSupportsClass,
447
				'isPublic' => true,
448
				'isEmbedded' => true,
449
				'shareURL' => 'fancy_protocol://nextcloud-host.tld/request/uri/123/42',
450
				'previewImage' => 'fancy_protocol://foo.bar/core/img/foo',
451
				'firstRun' => 'no',
452
				'webCalWorkaround' => 'no',
453
				'needsAutosize' => $needsAutosize,
454
				'isIE' => $isIE,
455
				'defaultColor' => '#ff00ff',
456
				'webcalURL' => 'webcal://foo.bar/remote.php/dav/public-calendars/fancy_token_123?export',
457
				'downloadURL' => 'fancy_protocol://foo.bar/remote.php/dav/public-calendars/fancy_token_123?export',
458
				'token' => 'fancy_token_123',
459
			], $actual->getParams());
460
			$this->assertEquals('main', $actual->getTemplateName());
461
		}
462
463
	}
464
465
	/**
466
	 * @dataProvider indexPublicDataProvider
@@ 468-572 (lines=105) @@
465
	/**
466
	 * @dataProvider indexPublicDataProvider
467
	 */
468
	public function testPublicIndexWithBranding($isAssetPipelineEnabled, $showAssetPipelineError, $serverVersion, $expectsSupportsClass, $needsAutosize, $isIE) {
469
		$this->config->expects($this->at(0))
470
			->method('getSystemValue')
471
			->with('version')
472
			->will($this->returnValue($serverVersion));
473
474
		$this->config->expects($this->at(1))
475
			->method('getSystemValue')
476
			->with('asset-pipeline.enabled', false)
477
			->will($this->returnValue($isAssetPipelineEnabled));
478
479
		if (!$showAssetPipelineError) {
480
			$this->request->expects($this->once())
481
				->method('isUserAgent')
482
				->with(['/(MSIE)|(Trident)/'])
483
				->will($this->returnValue($isIE));
484
		}
485
486
		if ($showAssetPipelineError) {
487
			$actual = $this->controller->index();
488
489
			$this->assertInstanceOf('OCP\AppFramework\Http\TemplateResponse', $actual);
490
			$this->assertEquals([], $actual->getParams());
491
			$this->assertEquals('main-asset-pipeline-unsupported', $actual->getTemplateName());
492
		} else {
493
			$this->config->expects($this->at(2))
494
				->method('getSystemValue')
495
				->with('version')
496
				->will($this->returnValue($serverVersion));
497
498
			$this->config->expects($this->at(3))
499
				->method('getAppValue')
500
				->with($this->appName, 'installed_version')
501
				->will($this->returnValue('42.13.37'));
502
503
			$this->config->expects($this->at(4))
504
				->method('getAppValue')
505
				->with('theming', 'color', '#0082C9')
506
				->will($this->returnValue('#ff00ff'));
507
508
			$this->request->expects($this->at(1))
509
				->method('getServerProtocol')
510
				->will($this->returnValue('fancy_protocol'));
511
512
			$this->request->expects($this->at(2))
513
				->method('getServerHost')
514
				->will($this->returnValue('nextcloud-host.tld'));
515
516
			$this->request->expects($this->at(3))
517
				->method('getRequestUri')
518
				->will($this->returnValue('/request/uri/123/42'));
519
520
			$this->urlGenerator->expects($this->at(0))
521
				->method('imagePath')
522
				->with('core', 'favicon-touch.png')
523
				->will($this->returnValue('/core/img/foo'));
524
525
			$this->urlGenerator->expects($this->at(1))
526
				->method('getAbsoluteURL')
527
				->with('/core/img/foo')
528
				->will($this->returnValue('fancy_protocol://foo.bar/core/img/foo'));
529
530
			$this->urlGenerator->expects($this->at(2))
531
				->method('linkTo')
532
				->with('', 'remote.php')
533
				->will($this->returnValue('remote.php'));
534
535
			$this->urlGenerator->expects($this->at(3))
536
				->method('getAbsoluteURL')
537
				->with('remote.php/dav/public-calendars/fancy_token_123?export')
538
				->will($this->returnValue('fancy_protocol://foo.bar/remote.php/dav/public-calendars/fancy_token_123?export'));
539
540
			$this->request->expects($this->at(4))
541
				->method('getServerProtocol')
542
				->will($this->returnValue('fancy_protocol'));
543
544
545
546
			$actual = $this->controller->publicIndexWithBranding('fancy_token_123');
547
548
			$this->assertInstanceOf('OCP\AppFramework\Http\TemplateResponse', $actual);
549
			$this->assertEquals([
550
				'appVersion' => '42.13.37',
551
				'initialView' => 'month',
552
				'emailAddress' => '',
553
				'skipPopover' => 'no',
554
				'weekNumbers' => 'no',
555
				'supportsClass' => $expectsSupportsClass,
556
				'isPublic' => true,
557
				'isEmbedded' => false,
558
				'shareURL' => 'fancy_protocol://nextcloud-host.tld/request/uri/123/42',
559
				'previewImage' => 'fancy_protocol://foo.bar/core/img/foo',
560
				'firstRun' => 'no',
561
				'webCalWorkaround' => 'no',
562
				'needsAutosize' => $needsAutosize,
563
				'isIE' => $isIE,
564
				'defaultColor' => '#ff00ff',
565
				'webcalURL' => 'webcal://foo.bar/remote.php/dav/public-calendars/fancy_token_123?export',
566
				'downloadURL' => 'fancy_protocol://foo.bar/remote.php/dav/public-calendars/fancy_token_123?export',
567
				'token' => 'fancy_token_123',
568
			], $actual->getParams());
569
			$this->assertEquals('public', $actual->getTemplateName());
570
		}
571
572
	}
573
574
	public function indexPublicDataProvider() {
575
		return [