From a18a5118afbd13d12d5885392fdc65fcd3b16c0a Mon Sep 17 00:00:00 2001 From: nghiem-mb Date: Tue, 3 Oct 2023 17:44:12 +0900 Subject: [PATCH 1/2] BcBaserHelperTest --- plugins/baser-core/src/Utility/BcFile.php | 11 +++++++++++ .../tests/TestCase/Utility/BcFileTest.php | 14 ++++++++++++++ .../TestCase/View/Helper/BcBaserHelperTest.php | 8 ++++---- 3 files changed, 29 insertions(+), 4 deletions(-) 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..84b2b62ac5 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,7 +1813,7 @@ 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(); } From b94fe0c86d41e55ff7af71962cf71ba4cda3ada4 Mon Sep 17 00:00:00 2001 From: nghiem-mb Date: Fri, 6 Oct 2023 09:09:28 +0900 Subject: [PATCH 2/2] fix bug --- .../baser-core/tests/TestCase/View/Helper/BcBaserHelperTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/baser-core/tests/TestCase/View/Helper/BcBaserHelperTest.php b/plugins/baser-core/tests/TestCase/View/Helper/BcBaserHelperTest.php index 84b2b62ac5..ac88e9685c 100644 --- a/plugins/baser-core/tests/TestCase/View/Helper/BcBaserHelperTest.php +++ b/plugins/baser-core/tests/TestCase/View/Helper/BcBaserHelperTest.php @@ -1815,7 +1815,6 @@ public function testIncludeCore($selectPlugin, $name, $data, $options, $expected $path3 = ROOT . '/lib/Baser/Plugin/Test/View/test.php'; $plugin = new BcFile($path3); $plugin->write('test'); - $plugin->close(); } $this->expectOutputRegex('/' . $expected . '/', $message);