Skip to content

Commit

Permalink
Merge branch '5.1.x' of github.com:baserproject/basercms into 5.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Sep 20, 2024
2 parents 3178111 + 6445855 commit da150c2
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
6 changes: 6 additions & 0 deletions plugins/baser-core/src/Utility/BcPluginUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
*/

namespace BaserCore\Utility;
use BaserCore\Annotation\NoTodo;
use BaserCore\Annotation\Checked;
use BaserCore\Annotation\UnitTest;

/**
* Class BcPluginUtil
Expand All @@ -21,6 +24,9 @@ class BcPluginUtil
* プラグインのconfig内容を取得する
* @param string $name
* @return array
* @checked
* @noTodo
* @unitTest
*/
public static function getPluginConfig(string $name): array
{
Expand Down
92 changes: 92 additions & 0 deletions plugins/baser-core/tests/TestCase/Utility/BcPluginUtilTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace BaserCore\Test\TestCase\Utility;

use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcPluginUtil;
use BaserCore\Utility\BcUtil;

class BcPluginUtilTest extends BcTestCase
{
public function setUp(): void
{
parent::setUp();
}

public function tearDown(): void
{
parent::tearDown();
}

/**
* test getPluginConfig
* @param string $pluginName
* @param string|null $configContent
* @param array $expected
* @dataProvider getPluginConfigDataProvider
*/
public function testGetPluginConfig($pluginName, $configContent, $expected)
{
//create config file
$configPath = BcUtil::getPluginPath($pluginName) . 'config.php';
if ($configContent !== null) {
file_put_contents($configPath, $configContent);
}

$result = BcPluginUtil::getPluginConfig($pluginName);

$this->assertEquals($expected, $result);

//clean up
if ($configContent !== null) {
unlink($configPath);
}
}

public static function getPluginConfigDataProvider()
{
return [
[
'non_existent_plugin',
null,
[
'type' => [],
'title' => '',
'description' => '',
'author' => '',
'url' => '',
'adminLink' => '',
'installMessage' => '',
]
],

[
'test_plugin',
'<?php return [\'type\' => \'Plugin\', \'title\' => \'Test Plugin\'];',
[
'type' => ['Plugin'],
'title' => 'Test Plugin',
'description' => '',
'author' => '',
'url' => '',
'adminLink' => '',
'installMessage' => '',
]
],

[
'test_plugin',
'<?php return [\'type\' => \'Plugin,CorePlugin\', \'title\' => \'Test Plugin\'];',
[
'type' => ['Plugin', 'CorePlugin'],
'title' => 'Test Plugin',
'description' => '',
'author' => '',
'url' => '',
'adminLink' => '',
'installMessage' => '',
]
]
];
}
}

0 comments on commit da150c2

Please sign in to comment.