diff --git a/plugins/baser-core/src/Utility/BcFile.php b/plugins/baser-core/src/Utility/BcFile.php index 9804ef1647..d437c9b4a5 100644 --- a/plugins/baser-core/src/Utility/BcFile.php +++ b/plugins/baser-core/src/Utility/BcFile.php @@ -101,4 +101,15 @@ public function write($data) return (bool) file_put_contents($this->path, $data); } + /** + * ファイルを削除 + * @return bool + */ + public function delete() + { + if(!is_file($this->path)) { + return false; + } + return unlink($this->path); + } } diff --git a/plugins/baser-core/tests/TestCase/Utility/BcFileTest.php b/plugins/baser-core/tests/TestCase/Utility/BcFileTest.php index caf8486187..6b05f0ae06 100644 --- a/plugins/baser-core/tests/TestCase/Utility/BcFileTest.php +++ b/plugins/baser-core/tests/TestCase/Utility/BcFileTest.php @@ -68,4 +68,18 @@ public function testWriteAndRead() $this->assertEquals('test', $file->read()); (new BcFolder(dirname($path)))->delete(); } + + /** + * test Delete + * @return void + */ + public function testDelete() + { + $path = TMP_TESTS . 'test' . DS . 'test.txt'; + $file = new BcFile($path); + $file->create(); + $this->assertTrue($file->delete()); + (new BcFolder(dirname($path)))->delete(); + $this->assertFalse($file->delete()); + } } diff --git a/plugins/baser-core/tests/TestCase/View/Helper/BcBaserHelperTest.php b/plugins/baser-core/tests/TestCase/View/Helper/BcBaserHelperTest.php index 289f73193f..ac88e9685c 100644 --- a/plugins/baser-core/tests/TestCase/View/Helper/BcBaserHelperTest.php +++ b/plugins/baser-core/tests/TestCase/View/Helper/BcBaserHelperTest.php @@ -11,11 +11,11 @@ namespace BaserCore\Test\TestCase\View\Helper; +use BaserCore\Utility\BcFile; use ReflectionClass; use Cake\Event\Event; use Cake\Core\Configure; use Cake\Routing\Router; -use Cake\Filesystem\File; use Cake\Event\EventManager; use Cake\View\Helper\UrlHelper; use Cake\View\Helper\HtmlHelper; @@ -222,13 +222,13 @@ public function testGetElement() // 管理画面用のテンプレートがなくフロントのテンプレートがある場合 $templateDir = ROOT . DS . 'plugins' . DS . 'bc-admin-third' . DS . 'templates'. DS; - $fileFront = new File($templateDir . 'element' . DS . 'test.php'); + $fileFront = new BcFile($templateDir . 'element' . DS . 'test.php'); $fileFront->create(); $fileFront->write('front'); $this->assertTextContains('front', $this->BcBaser->getElement('test')); // 管理画面用のテンプレートとフロントのテンプレートの両方がある場合 - $fileAdmin = new File($templateDir . 'Admin' . DS . 'element' . DS . 'test.php'); + $fileAdmin = new BcFile($templateDir . 'Admin' . DS . 'element' . DS . 'test.php'); $fileAdmin->create(); $fileAdmin->write('admin'); $this->assertTextContains('admin', $this->BcBaser->getElement('test')); @@ -1813,9 +1813,8 @@ public function testIncludeCore($selectPlugin, $name, $data, $options, $expected $path2 = ROOT . '/lib/Baser/Plugin/Test/View'; mkdir($path2); $path3 = ROOT . '/lib/Baser/Plugin/Test/View/test.php'; - $plugin = new File($path3); + $plugin = new BcFile($path3); $plugin->write('test'); - $plugin->close(); } $this->expectOutputRegex('/' . $expected . '/', $message);