Permalink
Browse files

Fix lies in Shell::createFile()

It could lie if the file was not writable.

Fixes #2371
  • Loading branch information...
1 parent 8d1edd7 commit b61e3e037855655f043c185ff9bd9a8154dca325 @markstory markstory committed Dec 14, 2011
Showing with 24 additions and 9 deletions.
  1. +1 −1 lib/Cake/Console/Shell.php
  2. +23 −8 lib/Cake/Test/Case/Console/ShellTest.php
@@ -657,7 +657,7 @@ public function createFile($path, $contents) {
}
$File = new File($path, true);
- if ($File->exists()) {
+ if ($File->exists() && $File->writable()) {
$data = $File->prepare($contents);
$File->write($data);
$this->out(__d('cake_console', '<success>Wrote</success> `%s`', $path));
@@ -126,6 +126,11 @@ public function setUp() {
$error = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Shell = new ShellTestShell($output, $error, $in);
+
+ if (is_dir(TMP . 'shell_test')) {
+ $Folder = new Folder(TMP . 'shell_test');
+ $Folder->delete();
+ }
}
/**
@@ -490,11 +495,6 @@ public function testShortPath() {
$path = $expected = DS . 'tmp' . DS . 'ab' . DS . 'index.php';
$this->assertEquals($this->Shell->shortPath($path), $expected);
- // Shell::shortPath needs Folder::realpath
- // $path = DS . 'tmp' . DS . 'ab' . DS . '..' . DS . 'cd';
- // $expected = DS . 'tmp' . DS . 'cd';
- // $this->assertEquals($this->Shell->shortPath($path), $expected);
-
$path = DS . 'tmp' . DS . 'ab' . DS . DS . 'cd';
$expected = DS . 'tmp' . DS . 'ab' . DS . 'cd';
$this->assertEquals($this->Shell->shortPath($path), $expected);
@@ -542,8 +542,6 @@ public function testCreateFileNonInteractive() {
$this->assertTrue($result);
$this->assertTrue(file_exists($file));
$this->assertEquals(file_get_contents($file), $contents);
-
- $Folder->delete();
}
/**
@@ -588,8 +586,25 @@ public function testCreateFileInteractive() {
$this->assertTrue($result);
$this->assertTrue(file_exists($file));
$this->assertEquals($contents, file_get_contents($file));
+ }
- $Folder->delete();
+/**
+ * Test that you can't create files that aren't writable.
+ *
+ * @return void
+ */
+ public function testCreateFileNoPermissions() {
+ $path = TMP . 'shell_test';
+ $file = $path . DS . 'no_perms';
+
+ mkdir($path);
+ chmod($path, 0444);
+
+ $this->Shell->createFile($file, 'testing');
+ $this->assertFalse(file_exists($file));
+
+ chmod($path, 0744);
+ rmdir($path);
}
/**

0 comments on commit b61e3e0

Please sign in to comment.