mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Fix lies in Shell::createFile()
It could lie if the file was not writable. Fixes #2371
This commit is contained in:
parent
8d1edd72f2
commit
b61e3e0378
2 changed files with 24 additions and 9 deletions
|
@ -657,7 +657,7 @@ class Shell extends Object {
|
|||
}
|
||||
|
||||
$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 @@ class ShellTest extends CakeTestCase {
|
|||
$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 @@ class ShellTest extends CakeTestCase {
|
|||
$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 @@ class ShellTest extends CakeTestCase {
|
|||
$this->assertTrue($result);
|
||||
$this->assertTrue(file_exists($file));
|
||||
$this->assertEquals(file_get_contents($file), $contents);
|
||||
|
||||
$Folder->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -588,8 +586,25 @@ class ShellTest extends CakeTestCase {
|
|||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue