diff --git a/plugins/baser-core/src/Controller/AppController.php b/plugins/baser-core/src/Controller/AppController.php
index 042326c8f9..488570b559 100644
--- a/plugins/baser-core/src/Controller/AppController.php
+++ b/plugins/baser-core/src/Controller/AppController.php
@@ -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();
diff --git a/plugins/bc-front/templates/plugin/BcMail/element/auth_captcha.php b/plugins/bc-front/templates/plugin/BcMail/element/auth_captcha.php
index c3f498d710..8b2fe10228 100644
--- a/plugins/bc-front/templates/plugin/BcMail/element/auth_captcha.php
+++ b/plugins/bc-front/templates/plugin/BcMail/element/auth_captcha.php
@@ -24,7 +24,7 @@
?>
-
+
BcBaser->img($captchaUrl, ['alt' => __d('baser_core', '認証画像'), 'class' => $options['class']]) ?>
diff --git a/plugins/bc-installer/src/BcInstallerPlugin.php b/plugins/bc-installer/src/BcInstallerPlugin.php
index 0e6d1f8cb4..0c0563e4c2 100644
--- a/plugins/bc-installer/src/BcInstallerPlugin.php
+++ b/plugins/bc-installer/src/BcInstallerPlugin.php
@@ -47,6 +47,7 @@ public function services(ContainerInterface $container): void
* @param \Cake\Routing\RouteBuilder $routes
* @checked
* @noTodo
+ * @unitTest
*/
public function routes($routes): void
{
diff --git a/plugins/bc-installer/src/Controller/Admin/InstallationsController.php b/plugins/bc-installer/src/Controller/Admin/InstallationsController.php
index fdc348bebd..59c5c9402f 100644
--- a/plugins/bc-installer/src/Controller/Admin/InstallationsController.php
+++ b/plugins/bc-installer/src/Controller/Admin/InstallationsController.php
@@ -49,6 +49,7 @@ class InstallationsController extends BcAdminAppController
* @return void
* @checked
* @noTodo
+ * @unitTest
*/
public function beforeFilter(EventInterface $event)
{
diff --git a/plugins/bc-installer/src/Mailer/Admin/InstallerMailer.php b/plugins/bc-installer/src/Mailer/Admin/InstallerMailer.php
index 076f6dd09b..aba99d1054 100644
--- a/plugins/bc-installer/src/Mailer/Admin/InstallerMailer.php
+++ b/plugins/bc-installer/src/Mailer/Admin/InstallerMailer.php
@@ -33,6 +33,7 @@ class InstallerMailer extends BcAdminMailer
* @param PasswordRequest|EntityInterface
* @checked
* @noTodo
+ * @unitTest
*/
public function installed(string $email)
{
diff --git a/plugins/bc-installer/tests/TestCase/BcInstallerPluginTest.php b/plugins/bc-installer/tests/TestCase/BcInstallerPluginTest.php
index 50714a0455..c8b371926a 100644
--- a/plugins/bc-installer/tests/TestCase/BcInstallerPluginTest.php
+++ b/plugins/bc-installer/tests/TestCase/BcInstallerPluginTest.php
@@ -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
{
@@ -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);
}
/**
diff --git a/plugins/bc-installer/tests/TestCase/Controller/Admin/InstallationsControllerTest.php b/plugins/bc-installer/tests/TestCase/Controller/Admin/InstallationsControllerTest.php
index ca642492d2..15c6f3af42 100644
--- a/plugins/bc-installer/tests/TestCase/Controller/Admin/InstallationsControllerTest.php
+++ b/plugins/bc-installer/tests/TestCase/Controller/Admin/InstallationsControllerTest.php
@@ -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
@@ -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"));
}
/**
diff --git a/plugins/bc-installer/tests/TestCase/Mailer/Admin/InstallerMailerTest.php b/plugins/bc-installer/tests/TestCase/Mailer/Admin/InstallerMailerTest.php
new file mode 100644
index 0000000000..e6b4d431d8
--- /dev/null
+++ b/plugins/bc-installer/tests/TestCase/Mailer/Admin/InstallerMailerTest.php
@@ -0,0 +1,66 @@
+
+ * Copyright (c) baserCMS Users 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']);
+ }
+
+}
diff --git a/plugins/bc-mail/src/Controller/Admin/MailContentsController.php b/plugins/bc-mail/src/Controller/Admin/MailContentsController.php
index 75d4da3a1f..cf196e1467 100644
--- a/plugins/bc-mail/src/Controller/Admin/MailContentsController.php
+++ b/plugins/bc-mail/src/Controller/Admin/MailContentsController.php
@@ -55,6 +55,7 @@ public function initialize(): void
* @param int ブログコンテンツID
* @checked
* @noTodo
+ * @unitTest
*/
public function edit(MailContentsAdminServiceInterface $service, int $id)
{
@@ -99,6 +100,7 @@ public function edit(MailContentsAdminServiceInterface $service, int $id)
* @return Response
* @checked
* @noTodo
+ * @unitTest
*/
private function redirectEditMail($template)
{
@@ -135,6 +137,7 @@ private function redirectEditMail($template)
* @return Response
* @checked
* @noTodo
+ * @unitTest
*/
private function redirectEditForm($template)
{
diff --git a/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php b/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php
index 153fd49efe..4b05fe6d87 100644
--- a/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php
+++ b/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php
@@ -54,6 +54,7 @@ public function initialize(): void
* @return void
* @checked
* @noTodo
+ * @unitTest
*/
public function beforeFilter(EventInterface $event)
{
@@ -78,6 +79,7 @@ public function beforeFilter(EventInterface $event)
* プラグインの環境をチェックする
* @checked
* @noTodo
+ * @unitTest
*/
protected function _checkEnv()
{
diff --git a/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php b/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php
index c102d212d6..3ccf5bed9d 100644
--- a/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php
+++ b/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php
@@ -163,6 +163,7 @@ public function delete(
* @return void
* @checked
* @noTodo
+ * @unitTest
*/
public function attachment(MailMessagesServiceInterface $service)
{
@@ -189,7 +190,6 @@ public function attachment(MailMessagesServiceInterface $service)
}
Header(sprintf('Content-type: %s; name=%s', $mineType, $file));
echo file_get_contents($filePath);
- exit();
}
/**
@@ -199,6 +199,7 @@ public function attachment(MailMessagesServiceInterface $service)
* @return void
* @checked
* @noTodo
+ * @unitTest
*/
public function download_csv(MailMessagesAdminServiceInterface $service, int $mailContentId)
{
diff --git a/plugins/bc-mail/src/View/Helper/MailformHelper.php b/plugins/bc-mail/src/View/Helper/MailformHelper.php
index 45b04a688e..d6530ed63a 100755
--- a/plugins/bc-mail/src/View/Helper/MailformHelper.php
+++ b/plugins/bc-mail/src/View/Helper/MailformHelper.php
@@ -275,6 +275,7 @@ public function create($context = null, $options = []): string
* @return void
* @checked
* @noTodo
+ * @unitTest
*/
public function authCaptcha(string $fieldName, array $options = [])
{
diff --git a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailContentsControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailContentsControllerTest.php
index d67bbbcb5c..0445422574 100644
--- a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailContentsControllerTest.php
+++ b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailContentsControllerTest.php
@@ -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;
@@ -90,7 +89,23 @@ 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);
}
/**
@@ -98,7 +113,12 @@ public function testAdmin_edit()
*/
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')
+ );
}
/**
@@ -106,7 +126,12 @@ public function test_redirectEditMail()
*/
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')
+ );
}
/**
diff --git a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php
index ce15e3ccdf..d752155861 100644
--- a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php
+++ b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php
@@ -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;
@@ -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);
}
/**
@@ -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());
+ }
}
diff --git a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php
index cd25a95477..56d9c04280 100644
--- a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php
+++ b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php
@@ -207,6 +207,47 @@ public function testDelete()
*/
public function testAttachment()
{
- $this->markTestIncomplete('このテストは、まだ実装されていません。');
+ $this->enableSecurityToken();
+ $this->enableCsrfToken();
+
+ $MailMessagesService = $this->getService(MailMessagesServiceInterface::class);
+ $MailMessagesService->createTable(1);
+ MailContentFactory::make(['id' => 1])->persist();
+ ContentFactory::make(['name' => 'name_test', 'plugin' => 'BcMail', 'type' => 'MailContent', 'entity_id' => 1])->persist();
+ $mailMessageTable = TableRegistry::getTableLocator()->get('mail_message_1');
+ $mailMessageTable->save(new Entity(['id' => 1, 'created' => '2016-07-29 18:02:53', 'modified' => '2020-09-14 21:10:41']));
+ $mailMessageTable->save(new Entity(['id' => 2, 'created' => '2016-07-29 18:02:53', 'modified' => '2020-09-14 21:10:41']));
+
+ ob_start();
+ $this->get('/baser/admin/bc-mail/mail_messages/attachment/1/00000002_tel.jpg');
+ $actualIsHelp = ob_get_clean();
+ $this->assertNotEmpty($actualIsHelp);
+
+ //不要テーブルを削除
+ $MailMessagesService->dropTable(1);
+ }
+
+ /**
+ * test download_csv
+ */
+ public function testDownloadCsv()
+ {
+ $this->enableSecurityToken();
+ $this->enableCsrfToken();
+ //データを生成
+ $MailMessagesService = $this->getService(MailMessagesServiceInterface::class);
+ $MailMessagesService->createTable(1);
+ MailContentFactory::make(['id' => 1])->persist();
+ ContentFactory::make(['name' => 'name_test', 'plugin' => 'BcMail', 'type' => 'MailContent', 'entity_id' => 1])->persist();
+ $mailMessageTable = TableRegistry::getTableLocator()->get('mail_message_1');
+ $mailMessageTable->save(new Entity(['id' => 1, 'created' => '2016-07-29 18:02:53', 'modified' => '2020-09-14 21:10:41']));
+ $mailMessageTable->save(new Entity(['id' => 2, 'created' => '2016-07-29 18:02:53', 'modified' => '2020-09-14 21:10:41']));
+
+ //対象メソッドをテスト
+ $this->get('/baser/admin/bc-mail/mail_messages/download_csv/1');
+ $this->assertResponseCode(200);
+
+ //不要テーブルを削除
+ $MailMessagesService->dropTable(1);
}
}
diff --git a/plugins/bc-mail/tests/TestCase/View/Helper/MailformHelperTest.php b/plugins/bc-mail/tests/TestCase/View/Helper/MailformHelperTest.php
index 285332f5e9..51e2844f1f 100644
--- a/plugins/bc-mail/tests/TestCase/View/Helper/MailformHelperTest.php
+++ b/plugins/bc-mail/tests/TestCase/View/Helper/MailformHelperTest.php
@@ -10,13 +10,18 @@
*/
namespace BcMail\Test\TestCase\View\Helper;
+use BaserCore\Test\Factory\ContentFactory;
+use BaserCore\Test\Factory\SiteFactory;
use BaserCore\TestSuite\BcTestCase;
+use BaserCore\View\Helper\BcBaserHelper;
use BcMail\Model\Entity\MailField;
+use BcMail\Test\Factory\MailContentFactory;
use BcMail\Test\Factory\MailMessagesFactory;
use BcMail\Service\MailFieldsServiceInterface;
use BcMail\View\Helper\MailformHelper;
use BcMail\Test\Scenario\MailContentsScenario;
use BcMail\Test\Scenario\MailFieldsScenario;
+use BcMail\View\MailFrontAppView;
use Cake\ORM\ResultSet;
use Cake\View\View;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;
@@ -71,7 +76,23 @@ public function testCreate()
*/
public function testAuthCaptcha()
{
- $this->markTestIncomplete('このテストは、まだ実装されていません。');
+ //データ生成
+ SiteFactory::make(['id' => 1])->persist();
+ ContentFactory::make(['plugin' => 'BcMail', 'type' => 'MailContent', 'entity_id' => 1, 'url' => '/contact/', 'site_id' => 1, 'lft' => 1, 'rght' => 2])->persist();
+ MailContentFactory::make(['id' => 1, 'form_template' => 'default', 'mail_template' => 'mail_default'])->persist();
+
+ //準備
+ $view = new MailFrontAppView($this->getRequest('/contact/'));
+ $view->setPlugin('BcMail');
+ $options['helper'] = new BcBaserHelper($view);
+ $this->MailformHelper = new MailformHelper($view);
+
+ //対象メッソどを呼ぶ
+ ob_start();
+ $this->MailformHelper->authCaptcha('auth_captcha', $options);
+ $result = ob_get_clean();
+ //戻る値を確認
+ $this->assertTextContains(' alt="認証画像" class="auth-captcha-image"', $result);
}
/**