From fac3d63b38ef9c7e7c9fe027e5df6cfc20368095 Mon Sep 17 00:00:00 2001 From: mattab Date: Tue, 27 Sep 2016 14:07:13 +1300 Subject: [PATCH] Fix test --- plugins/CustomPiwikJs/File.php | 6 ++++-- plugins/CustomPiwikJs/tests/Integration/FileTest.php | 11 +++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/CustomPiwikJs/File.php b/plugins/CustomPiwikJs/File.php index b5750c68508..03d874e61d5 100644 --- a/plugins/CustomPiwikJs/File.php +++ b/plugins/CustomPiwikJs/File.php @@ -38,7 +38,9 @@ public function checkWritable() public function save($content) { - file_put_contents($this->file, $content); + if(false === file_put_contents($this->file, $content)) { + throw new AccessDeniedException(sprintf("Could not write to %s", $this->file)); + } } public function getContent() @@ -60,7 +62,7 @@ public function getName() */ public function hasWriteAccess() { - if(file_exists($this->file) && !is_writable($this->file)) { + if (file_exists($this->file) && !is_writable($this->file)) { return false; } return is_writable(dirname($this->file)) || is_writable($this->file); diff --git a/plugins/CustomPiwikJs/tests/Integration/FileTest.php b/plugins/CustomPiwikJs/tests/Integration/FileTest.php index 91ac384a8ae..e445bdaf888 100644 --- a/plugins/CustomPiwikJs/tests/Integration/FileTest.php +++ b/plugins/CustomPiwikJs/tests/Integration/FileTest.php @@ -63,8 +63,15 @@ private function makeNotWritableFile() $file = new File($path); $file->save('will be saved OK, and then we make it non writable.'); - chmod($path, 0444); - chmod($this->dir, 0444); + if (!chmod($path, 0444)) { + throw new \Exception("chmod on the file didn't work"); + } + if (!chmod(dirname($path), 0755)) { + throw new \Exception("chmod on the directory didn't work"); + } + $this->assertTrue(is_writable(dirname($path))); + $this->assertFalse(is_writable($path)); + $this->assertTrue(file_exists($path)); return $file; }