Skip to content
This repository
Browse code

Applying patch from 'Ceeram'. Adds File::copy() and test case. Refs #150

  • Loading branch information...
commit 8d40532931827697ee2653e9eafc035d433632c5 1 parent ee7015c
Mark Story authored October 08, 2009
17  cake/libs/file.php
@@ -314,7 +314,7 @@ function delete() {
314 314
 	}
315 315
 
316 316
 /**
317  
- * Returns the File extension.
  317
+ * Returns the File info.
318 318
  *
319 319
  * @return string The File extension
320 320
  * @access public
@@ -540,5 +540,20 @@ function lastChange() {
540 540
 	function &Folder() {
541 541
 		return $this->Folder;
542 542
 	}
  543
+
  544
+/**
  545
+ * Copy the File to $dest
  546
+ *
  547
+ * @param string $dest destination for the copy
  548
+ * @param boolean $overwrite Overwrite $dest if exists
  549
+ * @return boolean Succes
  550
+ * @access public
  551
+ */
  552
+	function copy($dest, $overwrite = true) {
  553
+		if (!$this->exists() || is_file($dest) && !$overwrite) {
  554
+			return false;
  555
+		}
  556
+		return copy($this->path, $dest);
  557
+	}
543 558
 }
544 559
 ?>
29  cake/tests/cases/libs/file.test.php
@@ -417,6 +417,35 @@ function testDelete() {
417 417
 	}
418 418
 
419 419
 /**
  420
+ * testCopy method
  421
+ *
  422
+ * @access public
  423
+ * @return void
  424
+ */
  425
+	function testCopy() {
  426
+		$dest = TMP . 'tests' . DS . 'cakephp.file.test.tmp';
  427
+		$file = __FILE__;
  428
+		$this->File =& new File($file);
  429
+		$result = $this->File->copy($dest);
  430
+		$this->assertTrue($result);
  431
+
  432
+		$result = $this->File->copy($dest, true);
  433
+		$this->assertTrue($result);
  434
+
  435
+		$result = $this->File->copy($dest, false);
  436
+		$this->assertFalse($result);
  437
+
  438
+		$this->File->close();
  439
+		unlink($dest);
  440
+
  441
+		$TmpFile =& new File('/this/does/not/exist');
  442
+		$result = $TmpFile->copy($dest);
  443
+		$this->assertFalse($result);
  444
+
  445
+		$TmpFile->close();
  446
+	}
  447
+
  448
+/**
420 449
  * getTmpFile method
421 450
  *
422 451
  * @param bool $paintSkip

0 notes on commit 8d40532

Please sign in to comment.
Something went wrong with that request. Please try again.