Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BcBaserHelperTest #2780

Merged
merged 2 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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);
Expand Down