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

BcMailを全体テストの実行対象に追加する #2835

Merged
merged 21 commits into from
Nov 15, 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
6 changes: 3 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
<testsuite name="BcInstaller">
<directory>plugins/bc-installer/tests/TestCase</directory>
</testsuite>
<!-- <testsuite name="BcMail">-->
<!-- <directory>plugins/bc-mail/tests/TestCase</directory>-->
<!-- </testsuite>-->
<testsuite name="BcMail">
<directory>plugins/bc-mail/tests/TestCase</directory>
</testsuite>
<testsuite name="BcSearchIndex">
<directory>plugins/bc-search-index/tests/TestCase</directory>
</testsuite>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ public function view(MailFieldsServiceInterface $service, int $id)
*/
public function list(MailFieldsServiceInterface $service, int $mailContentId)
{
$mailField = $message = null;
$mailFields = $message = null;
try {
$mailField = $service->getList($mailContentId);
$mailFields = $service->getList($mailContentId);
} catch (RecordNotFoundException $e) {
$this->setResponse($this->response->withStatus(404));
$message = __d('baser_core', 'データが見つかりません。');
Expand All @@ -201,10 +201,10 @@ public function list(MailFieldsServiceInterface $service, int $mailContentId)
}

$this->set([
'mailField' => $mailField,
'mailFields' => $mailFields,
'message' => $message
]);
$this->viewBuilder()->setOption('serialize', ['mailField', 'message']);
$this->viewBuilder()->setOption('serialize', ['mailFields', 'message']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function getViewVarsForDownloadCsv(int $mailContentId, ServerRequest $req
return [
'encoding' => $request->getQuery('encoding') ?? 'utf-8',
'messages' => $this->MailMessages->convertMessageToCsv($this->getIndex()->all()->toArray()),
'contentName' => $request->getAttribute('currentContent')->name,
'contentName' => $request->getAttribute('currentContent')?->name,
];
}

Expand Down
29 changes: 24 additions & 5 deletions plugins/bc-mail/tests/Scenario/MailContentsScenario.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace BcMail\Test\Scenario;

use BaserCore\Test\Factory\ContentFactory;
use BaserCore\Test\Factory\ContentFolderFactory;
use BcMail\Test\Factory\MailContentFactory;
use CakephpFixtureFactories\Scenario\FixtureScenarioInterface;

Expand All @@ -32,6 +33,24 @@ class MailContentsScenario implements FixtureScenarioInterface
*/
public function load(...$args)
{
ContentFactory::make([
'id' => 1,
'plugin' => 'BaserCore',
'type' => 'ContentFolder',
'url' => '/',
'site_id' => 1,
'title' => 'baserCMSサンプル',
'entity_id' => 1,
'parent_id' => null,
'rght' => 6,
'lft' => 1,
'status' => true,
'created_date' => '2023-02-16 16:41:37',
])->persist();
ContentFolderFactory::make([
'id' => 1
])->persist();

MailContentFactory::make([
'id' => 1,
'description' => 'description test',
Expand All @@ -45,7 +64,6 @@ public function load(...$args)
'save_info' => 1,
])->persist();
ContentFactory::make([
'id' => 1,
'name' => 'name_test',
'plugin' => 'BcMail',
'type' => 'MailContent',
Expand All @@ -54,14 +72,13 @@ public function load(...$args)
'title' => 'お問い合わせ',
'entity_id' => 1,
'parent_id' => 1,
'rght' => 1,
'rght' => 3,
'lft' => 2,
'status' => true,
'created_date' => '2023-02-16 16:41:37',
])->persist();

MailContentFactory::make([
'id' => 2,
'description' => 'description test 2',
'sender_name' => '送信先名を入力してください',
'subject_user' => 'お問い合わせ頂きありがとうございます',
Expand All @@ -71,15 +88,17 @@ public function load(...$args)
'redirect_url' => '/',
])->persist();
ContentFactory::make([
'id' => 2,
'name' => 'name_test',
'plugin' => 'BcMail',
'type' => 'MailContent',
'url' => '/form/',
'site_id' => 1,
'title' => 'テスト',
'entity_id' => 2,
'rght' => 1,
'lft' => 2,
'rght' => 5,
'parent_id' => 1,
'lft' => 4,
'status' => true,
'created_date' => '2023-02-16 16:41:37',
])->persist();
Expand Down
57 changes: 43 additions & 14 deletions plugins/bc-mail/tests/Scenario/MailFieldsScenario.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace BcMail\Test\Scenario;

use BaserCore\Test\Factory\ContentFactory;
use BcMail\Test\Factory\MailContentFactory;
use BcMail\Test\Factory\MailFieldsFactory;
use CakephpFixtureFactories\Scenario\FixtureScenarioInterface;

Expand Down Expand Up @@ -38,24 +40,28 @@ public function load(...$args)
'field_name' => 'name_1',
'type' => 'text',
'head' => 'お名前',
'maxlength' => 255,
'options' => 'placeholder|性',
'group_field' => 'name',
'group_valid' => 'name',
'valid' => 0,
'not_empty' => 1,
'use_field' => 1,
'no_send' => 0,
'sort' => 1,
'created' => '2015-08-10 18:57:47',
'modified' => NULL,
'attention' => '',
'before_attachment' => '<small>[名]</small>',
'before_attachment' => '',
'after_attachment' => '',
'source' => '',
'source' => '資料請求|問い合わせ|その他',
'size' => 1,
'text_rows' => '0',
'maxlength' => 1,
'options' => '',
'class' => '',
'default_value' => '',
'description' => '',
'group_field' => '',
'group_valid' => '',
'valid' => '',
'valid_ex' => 'VALID_NOT_UNCHECKED',
'auto_convert' => '',
'not_empty' => 1,
'use_field' => 1,
'no_send' => 0,
'sort' => '15',
'created' => '2015-01-27 12:56:54',
'modified' => null
])->persist();
MailFieldsFactory::make([
'id' => 2,
Expand All @@ -77,7 +83,6 @@ public function load(...$args)
'created' => '2015-08-10 18:57:47',
'modified' => NULL,
])->persist();

MailFieldsFactory::make([
'id' => 3,
'mail_content_id' => 1,
Expand All @@ -96,5 +101,29 @@ public function load(...$args)
'created' => '2015-08-10 18:57:47',
'modified' => NULL,
])->persist();

MailContentFactory::make([
'id' => 100,
'description' => '<p>このコンテンツはメールフォーム機能により作られており、この文章については管理画面の [お問い合わせ] &rarr; [設定] より更新ができます。また、メールフォームは [コンテンツ管理] よりいくつでも作成することができます。</p>',
'sender_1' => '',
'sender_2' => '',
'sender_name' => 'baserCMSサンプル',
'subject_user' => '【baserCMS】お問い合わせ頂きありがとうございます。',
'subject_admin' => '【baserCMS】お問い合わせを受け付けました',
'form_template' => 'default',
'mail_template' => 'mail_default',
'redirect_url' => '/',
'widget_area' => NULL,
'ssl_on' => 0,
'save_info' => 1,
'auth_captcha' => 1,
'publish_begin' => NULL,
'publish_end' => NULL,
'created' => NULL,
'modified' => NULL,
])->persist();
ContentFactory::make(['plugin' => 'BcMail', 'type' => 'MailContent'])
->treeNode(100, 1, 0, 'test', '/contact/', 100, true)->persist();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use BaserCore\Utility\BcContainerTrait;
use BcMail\Controller\Admin\MailContentsController;
use BcMail\Service\MailContentsServiceInterface;
use BcMail\Test\Factory\MailContentFactory;
use BcMail\Test\Scenario\MailContentsScenario;
use Cake\Event\Event;
use Cake\ORM\TableRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use BcMail\Controller\Admin\MailFieldsController;
use BcMail\Service\Admin\MailFieldsAdminServiceInterface;
use BcMail\Service\MailMessagesServiceInterface;
use BcMail\Test\Scenario\MailContentsScenario;
use BcMail\Test\Scenario\MailFieldsScenario;
use Cake\Event\Event;
use Cake\ORM\TableRegistry;
Expand Down Expand Up @@ -148,9 +149,12 @@ public function testAdmin_ajax_publish()
*/
public function testBeforeAddEvent()
{
$this->markTestIncomplete('こちらのテストはまだ未確認です');
$MailMessagesService = $this->getService(MailMessagesServiceInterface::class);
//テストデータベースを生成
$MailMessagesService->createTable(10);
$MailMessagesService->createTable(1);
$this->loadFixtureScenario(MailFieldsScenario::class);
$this->loadFixtureScenario(MailContentsScenario::class);

$this->enableSecurityToken();
$this->enableCsrfToken();
Expand All @@ -167,21 +171,22 @@ public function testBeforeAddEvent()
'name' => '性',
];
//対象URLをコル
$this->post('/baser/admin/bc-mail/mail_fields/add/10', $data);
$this->post('/baser/admin/bc-mail/mail_fields/add/1', $data);
//イベントに入るかどうか確認
$mailFields = $this->getTableLocator()->get('BcMail.MailFields');
$query = $mailFields->find()->where(['name' => 'beforeAdd']);
$this->assertEquals(1, $query->count());

//テストデータベースを削除
$MailMessagesService->dropTable(10);
$MailMessagesService->dropTable(1);
}

/**
* Test beforeAddEvent
*/
public function testAfterAddEvent()
{
$this->markTestIncomplete('こちらのテストはまだ未確認です');
$MailMessagesService = $this->getService(MailMessagesServiceInterface::class);
//テストデータベースを生成
$MailMessagesService->createTable(10);
Expand Down Expand Up @@ -217,6 +222,7 @@ public function testAfterAddEvent()
*/
public function testBeforeEditEvent()
{
$this->markTestIncomplete('こちらのテストはまだ未確認です');
$this->enableSecurityToken();
$this->enableCsrfToken();
//データを生成
Expand All @@ -243,6 +249,7 @@ public function testBeforeEditEvent()
*/
public function testAfterEditEvent()
{
$this->markTestIncomplete('こちらのテストはまだ未確認です');
$this->enableSecurityToken();
$this->enableCsrfToken();
//データを生成
Expand Down
Loading