Code Duplication    Length = 103-103 lines in 2 locations

tests/php/controller/viewcontrollerTest.php 2 locations

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