Skip to content

Commit

Permalink
Merge branch '5.1.x' into advisory-fix-2
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Nov 15, 2024
2 parents 4516d26 + 990a3d5 commit 86d3065
Show file tree
Hide file tree
Showing 46 changed files with 790 additions and 111 deletions.
2 changes: 1 addition & 1 deletion plugins/baser-core/src/BaserCorePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public function setupThemePlugin(array $themes): void
if (!is_dir($pluginsPath)) continue;
$path[] = $pluginsPath;
}
if($path) {
if(isset($path) && $path) {
Configure::write('App.paths.plugins', array_merge(
Configure::read('App.paths.plugins'),
$path
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/Controller/BcFrontAppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function initialize(): void
* @return Response|void
* @checked
* @noTodo
* @unitTest
*/
public function beforeFilter(EventInterface $event)
{
Expand Down
5 changes: 3 additions & 2 deletions plugins/baser-core/src/Event/BcEventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ class BcEventDispatcher
* @return boolean|Event
* @checked
* @noTodo
* @unitTest
*/
public static function dispatch($name, $subject, $data = [], $options = [])
{
$options = array_merge([
'layer' => '',
'plugin' => method_exists($subject, 'getPlugin')? $subject->getPlugin() : '',
'class' => method_exists($subject, 'getName')? $subject->getName() : ''
'plugin' => method_exists($subject, 'getPlugin') ? $subject->getPlugin() : '',
'class' => method_exists($subject, 'getName') ? $subject->getName() : ''
], $options);

$eventName = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class PrefixOrmResolver extends OrmResolver implements ResolverInterface
* @return array|EntityInterface|null
* @checked
* @noTodo
* @unitTest
*/
public function find(array $conditions, $type = self::TYPE_AND): \ArrayAccess|array|null
{
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/Mailer/Admin/BcAdminMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class BcAdminMailer extends BcMailer
* @param null $config
* @checked
* @noTodo
* @unitTest
*/
public function __construct($config = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class PasswordRequestMailer extends BcAdminMailer
* @param PasswordRequest|EntityInterface
* @checked
* @noTodo
* @unitTest
*/
public function resetPassword(EntityInterface $user, EntityInterface $passwordRequest)
{
Expand Down
4 changes: 4 additions & 0 deletions plugins/baser-core/src/Mailer/BcMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class BcMailer extends Mailer
* @param null $config
* @checked
* @noTodo
* @unitTest
*/
public function __construct($config = null)
{
Expand All @@ -68,6 +69,7 @@ public function __construct($config = null)
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function setEmailTransport()
{
Expand Down Expand Up @@ -105,6 +107,7 @@ public function setEmailTransport()
* @return string
* @checked
* @noTodo
* @unitTest
*/
public function getPlugin(): ?string
{
Expand All @@ -119,6 +122,7 @@ public function getPlugin(): ?string
* @psalm-return array{headers: string, message: string}
* @checked
* @noTodo
* @unitTest
*/
public function deliver(string $content = ''): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function initialize(array $config): void
* @return string
* @checked
* @noTodo
* @unitTest
*/
public function getType(): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public function getViewVarsForUpdate(EntityInterface $entity): array
* @return mixed|string
* @checked
* @noTodo
* @unitTest
*/
public function whichPhp()
{
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/Service/PagesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public function getIndex(array $queryParams = []): Query
* @return Query
* @checked
* @noTodo
* @unitTest
*/
protected function createIndexConditions(Query $query, $options = [])
{
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/Service/PermissionGroupsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ public function buildByUserGroup(int $userGroupId)
* @return bool
* @checked
* @noTodo
* @unitTest
*/
public function rebuildByUserGroup(int $userGroupId)
{
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/Service/PermissionsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ public function getNamesById($ids): array
* @return array
* @checked
* @noTodo
* @unitTest
*/
public function getControlSource(string $field, array $options = [])
{
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/Service/PluginsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ public function add(array $postData)
* - `versions`: 取得可能なコアのバージョンリスト
* @checked
* @noTodo
* @unitTest
*/
public function getAvailableCoreVersionInfo()
{
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/Service/SiteConfigsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ public function clearCache()
* @throws \Throwable
* @checked
* @noTodo
* @unitTest
*/
public function sendTestMail(array $postData, string $email, string $subject, string $body)
{
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/TestSuite/BcTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public function setUp(): void
* クラスメソッド名を取得する
* @checked
* @noTodo
* @unitTest
*/
public function classMethod()
{
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/tests/TestCase/BaserCorePluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public function testBootStrap(): void
$pathsPluginsExpected = [
'/var/www/html/plugins/',
'/var/www/html/vendor/baserproject/',
'/var/www/html/plugins/bc-custom-content/plugins/',
];

$this->assertEquals($pathsPluginsExpected, Configure::read('App.paths.plugins'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
namespace BaserCore\Test\TestCase\Controller;

use BaserCore\Controller\BcFrontAppController;
use BaserCore\Test\Factory\ContentFactory;
use BaserCore\Test\Factory\PluginFactory;
use BaserCore\Test\Factory\SiteFactory;
use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcContainer;
use Cake\Core\Configure;
use Cake\Event\Event;
use Cake\I18n\I18n;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

/**
Expand Down Expand Up @@ -88,7 +90,14 @@ public function testNotFound()
*/
public function testBeforeFilter()
{
$this->markTestIncomplete('このテストはまだ実装されていません。');
//準備
ContentFactory::make(['url' => '/', 'site_id' => 2])->persist();
SiteFactory::make(['id' => 2, 'lang' => 'english'])->persist();
$this->BcFrontAppController->setRequest($this->loginAdmin($this->getRequest('/')));
//テスト
$this->BcFrontAppController->beforeFilter(new Event('Controller.beforeFilter', $this->BcFrontAppController));
//language check
$this->assertEquals('en', I18n::getLocale());
}

/**
Expand Down
92 changes: 92 additions & 0 deletions plugins/baser-core/tests/TestCase/Event/BcEventDispatcherTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* baserCMS : Based Website Development Project <https://basercms.net>
* Copyright (c) NPO baser foundation <https://baserfoundation.org/>
*
* @copyright Copyright (c) NPO baser foundation
* @link https://basercms.net baserCMS Project
* @since 5.0.0
* @license https://basercms.net/license/index.html MIT License
*/

namespace BaserCore\Test\TestCase\Event;

use BaserCore\Event\BcModelEventDispatcher;
use BaserCore\Event\BcModelEventListener;
use BaserCore\Model\Table\UsersTable;
use BaserCore\TestSuite\BcTestCase;
use Cake\Event\Event;
use Cake\Event\EventManager;

/**
* Class BcEventDispatcherTest
*
*/
class BcEventDispatcherTest extends BcTestCase
{

/**
* @var EventManager|null
*/
public $eventManager;

/**
* @var BcModelEventDispatcher|null
*/
public $bcModelEventDispatcher;
/**
* set up
*
* @return void
*/
public function setUp(): void
{
parent::setUp();
$this->eventManager = EventManager::instance();
$this->bcModelEventDispatcher = new BcModelEventDispatcher();
foreach($this->bcModelEventDispatcher->implementedEvents() as $key => $event) {
$this->eventManager->off($key);
}
}

/**
* tearDown
*
* @return void
*/
public function tearDown(): void
{
parent::tearDown();
}

/**
* dispatch
*/
public function testDispatch()
{
foreach($this->bcModelEventDispatcher->implementedEvents() as $key => $event) {
$this->eventManager->off($key);
}

$listener = $this->getMockBuilder(BcModelEventListener::class)
->onlyMethods(['implementedEvents'])
->addMethods(['usersBeforeFind'])
->getMock();

$listener->method('implementedEvents')
->willReturn(['Model.Users.beforeFind' => ['callable' => 'usersBeforeFind']]);

$listener->expects($this->once())
->method('usersBeforeFind');

$this->eventManager
->on($listener)
->on($this->bcModelEventDispatcher)
->dispatch(new Event(
'Model.beforeFind',
new UsersTable,
[]
));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* baserCMS : Based Website Development Project <https://basercms.net>
* Copyright (c) NPO baser foundation <https://baserfoundation.org/>
*
* @copyright Copyright (c) NPO baser foundation
* @link https://basercms.net baserCMS Project
* @since 5.0.0
* @license https://basercms.net/license/index.html MIT License
*/
namespace BaserCore\Test\TestCase\Identifier\Resolver;

use BaserCore\Identifier\Resolver\PrefixOrmResolver;
use BaserCore\Test\Factory\UserFactory;
use BaserCore\TestSuite\BcTestCase;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

/**
* Class PrefixOrmResolverTest
* @property PrefixOrmResolver $PrefixOrmResolver
*
*/
class PrefixOrmResolverTest extends BcTestCase
{
/**
* ScenarioAwareTrait
*/
use ScenarioAwareTrait;

/**
* Set Up
*
* @return void
*/
public function setUp(): void
{
parent::setUp();
$this->PrefixOrmResolver = new PrefixOrmResolver();
}

/**
* Tear Down
*
* @return void
*/
public function tearDown(): void
{
parent::tearDown();
}

/**
* testInitialize
*
* @return void
*/
public function testFind(): void
{
//準備
UserFactory::make(['id' => 1, 'name' => 'user_test'])->persist();
$this->PrefixOrmResolver->setConfig('prefix', 'test');

//正常テスト
$rs = $this->PrefixOrmResolver->find(['id' => 'test_1']);
$this->assertEquals('user_test', $rs->name);

//異常テスト 
$rs = $this->PrefixOrmResolver->find(['id' => 'user_1']);
$this->assertNull($rs);
}
}
Loading

0 comments on commit 86d3065

Please sign in to comment.