Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Merge branch '2773-BcBaserHelperTest' into dev-baserproject#2773-BcDa…
Browse files Browse the repository at this point in the history
…tabaseServiceTest
  • Loading branch information
nghiem-mb committed Oct 4, 2023
2 parents 347ded8 + a18a511 commit 4101c7c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
11 changes: 11 additions & 0 deletions plugins/baser-core/src/Utility/BcFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
14 changes: 14 additions & 0 deletions plugins/baser-core/tests/TestCase/Utility/BcFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'));
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 4101c7c

Please sign in to comment.