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 Dec 20, 2024
2 parents 389f345 + be553fc commit 7d030c3
Show file tree
Hide file tree
Showing 16 changed files with 233 additions and 14 deletions.
2 changes: 1 addition & 1 deletion plugins/baser-core/src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function __construct(
parent::__construct($request, $response, $name, $eventManager, $components);

// CSRFトークンの場合は高速化のためここで処理を終了
if(!$request->is('requestview')) return;
if(!BcUtil::isConsole() && !$request->is('requestview')) return;

$request->getSession()->start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
?>


<?php if (!$freezed): ?>
<?php if (!isset($freezed) || !$freezed): ?>
<div class="bs-mail-form-auth-captcha">
<div>
<?php $this->BcBaser->img($captchaUrl, ['alt' => __d('baser_core', '認証画像'), 'class' => $options['class']]) ?>
Expand Down
1 change: 1 addition & 0 deletions plugins/bc-installer/src/BcInstallerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function services(ContainerInterface $container): void
* @param \Cake\Routing\RouteBuilder $routes
* @checked
* @noTodo
* @unitTest
*/
public function routes($routes): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class InstallationsController extends BcAdminAppController
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function beforeFilter(EventInterface $event)
{
Expand Down
1 change: 1 addition & 0 deletions plugins/bc-installer/src/Mailer/Admin/InstallerMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class InstallerMailer extends BcAdminMailer
* @param PasswordRequest|EntityInterface
* @checked
* @noTodo
* @unitTest
*/
public function installed(string $email)
{
Expand Down
14 changes: 13 additions & 1 deletion plugins/bc-installer/tests/TestCase/BcInstallerPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
use BcInstaller\Service\Admin\InstallationsAdminServiceInterface;
use BcInstaller\Service\InstallationsServiceInterface;
use Cake\Console\CommandCollection;
use Cake\Core\Configure;
use Cake\Core\Container;
use Cake\Routing\Router;

class BcInstallerPluginTest extends BcTestCase
{
Expand Down Expand Up @@ -40,7 +42,17 @@ public function test_services()
*/
public function test_routes()
{
$this->markTestIncomplete('Not implemented yet.');
Configure::write('BcEnv.isInstalled', false);
$routes = Router::createRouteBuilder('/install');
$this->BcInstallerPlugin->routes($routes);
$result = Router::parseRequest($this->getRequest('/install'));
$this->assertEquals('Installations', $result['controller']);

$routes = Router::createRouteBuilder('/');
$this->BcInstallerPlugin->routes($routes);
$result = Router::parseRequest($this->getRequest('/'));
$this->assertEquals('Installations', $result['controller']);
Configure::write('BcEnv.isInstalled', true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace BcInstaller\Test\TestCase\Controller\Admin;
use BaserCore\TestSuite\BcTestCase;
use BcInstaller\Controller\Admin\InstallationsController;
use Cake\Event\Event;

/**
* Class InstallationsControllerTest
Expand Down Expand Up @@ -45,7 +46,10 @@ public function tearDown(): void
*/
public function testBeforeFilter()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$this->InstallationsController = new InstallationsController($this->getRequest());
$event = new Event('Controller.beforeFilter', $this->InstallationsController);
$this->InstallationsController->beforeFilter($event);
$this->assertEquals(300, ini_get("max_execution_time"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* baserCMS : Based Website Development Project <https://basercms.net>
* Copyright (c) baserCMS Users Community <https://basercms.net/community/>
*
* @copyright Copyright (c) baserCMS Users Community
* @link https://basercms.net baserCMS Project
* @since baserCMS v 4.0.9
* @license https://basercms.net/license/index.html
*/

namespace BcInstaller\Test\TestCase\Mailer\Admin;
use BaserCore\Test\Factory\SiteConfigFactory;
use BaserCore\Test\Factory\SiteFactory;
use BaserCore\TestSuite\BcTestCase;
use BcInstaller\Mailer\Admin\InstallerMailer;
use Cake\TestSuite\EmailTrait;

/**
* Class InstallerMailerTest
*
* @property InstallerMailer $InstallerMailer
*/
class InstallerMailerTest extends BcTestCase
{

use EmailTrait;

/**
* setup
*/
public function setUp(): void
{
parent::setUp();
SiteConfigFactory::make(['name' => 'email', 'value' => 'basertest@example.com'])->persist();
SiteFactory::make(['id' => 1, 'display_name' => 'main site'])->persist();

$this->InstallerMailer = new InstallerMailer();
}

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

/**
* beforeFilter
*/
public function testInstalled()
{
$this->InstallerMailer->installed('test@example.com');

//戻り値確認
$this->assertEquals(['test@example.com' => 'test@example.com'], $this->InstallerMailer->getTo());
$vars = $this->InstallerMailer->viewBuilder()->getVars();
$this->assertEquals('test@example.com', $vars['email']);
$this->assertEquals('https://localhost/', $vars['siteUrl']);
$this->assertEquals('https://localhost/baser/admin/baser-core/users/login', $vars['adminUrl']);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function initialize(): void
* @param int ブログコンテンツID
* @checked
* @noTodo
* @unitTest
*/
public function edit(MailContentsAdminServiceInterface $service, int $id)
{
Expand Down Expand Up @@ -99,6 +100,7 @@ public function edit(MailContentsAdminServiceInterface $service, int $id)
* @return Response
* @checked
* @noTodo
* @unitTest
*/
private function redirectEditMail($template)
{
Expand Down Expand Up @@ -135,6 +137,7 @@ private function redirectEditMail($template)
* @return Response
* @checked
* @noTodo
* @unitTest
*/
private function redirectEditForm($template)
{
Expand Down
2 changes: 2 additions & 0 deletions plugins/bc-mail/src/Controller/Admin/MailFieldsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function initialize(): void
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function beforeFilter(EventInterface $event)
{
Expand All @@ -78,6 +79,7 @@ public function beforeFilter(EventInterface $event)
* プラグインの環境をチェックする
* @checked
* @noTodo
* @unitTest
*/
protected function _checkEnv()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public function delete(
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function attachment(MailMessagesServiceInterface $service)
{
Expand All @@ -189,7 +190,6 @@ public function attachment(MailMessagesServiceInterface $service)
}
Header(sprintf('Content-type: %s; name=%s', $mineType, $file));
echo file_get_contents($filePath);
exit();
}

/**
Expand All @@ -199,6 +199,7 @@ public function attachment(MailMessagesServiceInterface $service)
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function download_csv(MailMessagesAdminServiceInterface $service, int $mailContentId)
{
Expand Down
1 change: 1 addition & 0 deletions plugins/bc-mail/src/View/Helper/MailformHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ public function create($context = null, $options = []): string
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function authCaptcha(string $fieldName, array $options = [])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

namespace BcMail\Test\TestCase\Controller\Admin;

use BaserCore\Test\Factory\ContentFactory;
use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcContainerTrait;
Expand Down Expand Up @@ -90,23 +89,49 @@ public function test_delete()
*/
public function testAdmin_edit()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$this->enableSecurityToken();
$this->enableCsrfToken();
//データーを生成
$mailContentServices = $this->getService(MailContentsServiceInterface::class);
//データを生成
$this->loadFixtureScenario(MailContentsScenario::class);
//Postデータを生成
$mailContent = $mailContentServices->get(1);
$mailContent->description = 'this is api edit';
//対象URLをコル
$this->post('/baser/admin/bc-mail/mail_contents/edit/1', $mailContent->toArray());
$this->assertResponseCode(302);
$this->assertFlashMessage('メールフォーム「お問い合わせ」を更新しました。');

//エラーを発生した場合
$this->post('/baser/admin/bc-mail/mail_contents/edit/222', $mailContent->toArray());
$this->assertResponseCode(404);
}

/**
* test redirectEditMail
*/
public function test_redirectEditMail()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$rs = $this->execPrivateMethod($this->MailContentsController, 'redirectEditMail', ['default']);
$this->assertEquals(302, $rs->getStatusCode());
$this->assertEquals(
['https://localhost/baser/admin/bc-theme-file/theme_files/edit/BcFront/BcMail/email/text/default.php'],
$rs->getHeader('Location')
);
}

/**
* test redirectEditForm
*/
public function test_redirectEditForm()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$rs = $this->execPrivateMethod($this->MailContentsController, 'redirectEditForm', ['default']);
$this->assertEquals(302, $rs->getStatusCode());
$this->assertEquals(
['https://localhost/baser/admin/bc-theme-file/theme_files/edit/BcFront/BcMail/etc/Mail/default/index.php'],
$rs->getHeader('Location')
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
namespace BcMail\Test\TestCase\Controller\Admin;

use BaserCore\Service\BcDatabaseServiceInterface;
use BaserCore\Test\Factory\ContentFactory;
use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcContainerTrait;
use BaserCore\Utility\BcFile;
use BaserCore\Utility\BcFolder;
use BcMail\Controller\Admin\MailFieldsController;
use BcMail\Service\Admin\MailFieldsAdminServiceInterface;
use BcMail\Service\MailFieldsServiceInterface;
use BcMail\Service\MailMessagesServiceInterface;
use BcMail\Test\Factory\MailFieldsFactory;
use BcMail\Test\Scenario\MailContentsScenario;
Expand Down Expand Up @@ -75,7 +76,31 @@ public function testInitialize()
*/
public function testBeforeFilter()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
ContentFactory::make([
'name' => 'name_test',
'plugin' => 'BcMail',
'type' => 'MailContent',
'url' => '/contact/',
'site_id' => 1,
'title' => 'お問い合わせ',
'entity_id' => 1
])->persist();

//正常テスト・エラーにならない
$request = $this->getRequest('/baser/admin/bc-mail/mail_fields/view/1/1');
$request = $this->loginAdmin($request);
$this->MailFieldsController = new MailFieldsController($request);
$event = new Event('filter');
$this->MailFieldsController->beforeFilter($event);

//異常テスト
$request = $this->getRequest('/baser/admin/bc-mail/mail_fields/view/2222/1');
$request = $this->loginAdmin($request);
$this->MailFieldsController = new MailFieldsController($request);
$event = new Event('filter');
$this->expectExceptionMessage('コンテンツデータが見つかりません。');
$this->expectException('BaserCore\Error\BcException');
$this->MailFieldsController->beforeFilter($event);
}

/**
Expand Down Expand Up @@ -469,4 +494,19 @@ public function testAdmin_unpublish()
//check redirect
$this->assertRedirect('/baser/admin/bc-mail/mail_fields/index/1');
}

/**
* _checkEnv
*/
public function test_checkEnv()
{
$folderPath = '/var/www/html/webroot/files/mail/limited';
$folder = new BcFolder($folderPath);
$folder->delete();

$this->execPrivateMethod($this->MailFieldsController, '_checkEnv');
$this->assertTrue(is_dir($folderPath));
$file = new BcFile($folderPath . DS . '.htaccess');
$this->assertTextContains('Order allow', $file->read());
}
}
Loading

0 comments on commit 7d030c3

Please sign in to comment.