Code Duplication    Length = 56-57 lines in 2 locations

tests/filesystem/UploadTest.php 2 locations

@@ 473-528 (lines=56) @@
470
		);
471
	}
472
473
	public function testUploadFileWithNoExtensionTwiceAppendsNumber() {
474
		// create tmp file
475
		$tmpFileName = 'UploadTest-testUpload';
476
		$tmpFilePath = TEMP_FOLDER . '/' . $tmpFileName;
477
		$tmpFileContent = '';
478
		for($i=0; $i<10000; $i++) $tmpFileContent .= '0';
479
		file_put_contents($tmpFilePath, $tmpFileContent);
480
481
		// emulates the $_FILES array
482
		$tmpFile = array(
483
			'name' => $tmpFileName,
484
			'type' => 'text/plaintext',
485
			'size' => filesize($tmpFilePath),
486
			'tmp_name' => $tmpFilePath,
487
			'extension' => 'txt',
488
			'error' => UPLOAD_ERR_OK,
489
		);
490
491
		$v = new UploadTest_Validator();
492
		$v->setAllowedExtensions(array(''));
493
494
		// test upload into default folder
495
		$u = new Upload();
496
		$u->setValidator($v);
497
		$u->loadIntoFile($tmpFile);
498
		$file = $u->getFile();
499
500
		$this->assertEquals(
501
			'UploadTest-testUpload',
502
			$file->Name,
503
			'File is uploaded without extension'
504
		);
505
		$this->assertFileExists(
506
			AssetStoreTest_SpyStore::getLocalPath($file),
507
			'File exists'
508
		);
509
510
		$u = new Upload();
511
		$u->setValidator($v);
512
		$u->loadIntoFile($tmpFile);
513
		$file2 = $u->getFile();
514
		$this->assertEquals(
515
			'UploadTest-testUpload-v2',
516
			$file2->Name,
517
			'File receives a number attached to the end'
518
		);
519
		$this->assertFileExists(
520
			AssetStoreTest_SpyStore::getLocalPath($file2),
521
			'File exists'
522
		);
523
		$this->assertGreaterThan(
524
			$file->ID,
525
			$file2->ID,
526
			'File database record is not the same'
527
		);
528
	}
529
530
	public function testReplaceFile() {
531
		// create tmp file
@@ 530-586 (lines=57) @@
527
		);
528
	}
529
530
	public function testReplaceFile() {
531
		// create tmp file
532
		$tmpFileName = 'UploadTest-testUpload';
533
		$tmpFilePath = TEMP_FOLDER . '/' . $tmpFileName;
534
		$tmpFileContent = '';
535
		for($i=0; $i<10000; $i++) $tmpFileContent .= '0';
536
		file_put_contents($tmpFilePath, $tmpFileContent);
537
538
		// emulates the $_FILES array
539
		$tmpFile = array(
540
			'name' => $tmpFileName,
541
			'type' => 'text/plaintext',
542
			'size' => filesize($tmpFilePath),
543
			'tmp_name' => $tmpFilePath,
544
			'extension' => 'txt',
545
			'error' => UPLOAD_ERR_OK,
546
		);
547
548
		$v = new UploadTest_Validator();
549
		$v->setAllowedExtensions(array(''));
550
551
		// test upload into default folder
552
		$u = new Upload();
553
		$u->setValidator($v);
554
		$u->loadIntoFile($tmpFile);
555
		$file = $u->getFile();
556
557
		$this->assertEquals(
558
			'UploadTest-testUpload',
559
			$file->Name,
560
			'File is uploaded without extension'
561
		);
562
		$this->assertFileExists(
563
			AssetStoreTest_SpyStore::getLocalPath($file),
564
			'File exists'
565
		);
566
567
		$u = new Upload();
568
		$u->setValidator($v);
569
		$u->setReplaceFile(true);
570
		$u->loadIntoFile($tmpFile);
571
		$file2 = $u->getFile();
572
		$this->assertEquals(
573
			'UploadTest-testUpload',
574
			$file2->Name,
575
			'File does not receive new name'
576
		);
577
		$this->assertFileExists(
578
			AssetStoreTest_SpyStore::getLocalPath($file2),
579
			'File exists'
580
		);
581
		$this->assertEquals(
582
			$file->ID,
583
			$file2->ID,
584
			'File database record is the same'
585
		);
586
	}
587
588
	public function testReplaceFileWithLoadIntoFile() {
589
		// create tmp file