Skip to content

Commit

Permalink
Merge branch 'dev-5.1' into unitTest_MailFieldsTable_sourceMailField
Browse files Browse the repository at this point in the history
  • Loading branch information
thangnn committed Apr 23, 2024
2 parents fcb7d15 + 73395b3 commit cf7c4b9
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 44 deletions.
2 changes: 2 additions & 0 deletions plugins/bc-mail/src/Model/Table/MailFieldsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ public function duplicateMailField(string $value, array $context)
* @return boolean
* @checked
* @noTodo
* @unitTest
*/
public function halfTextMailField(string $value)
{
Expand Down Expand Up @@ -331,6 +332,7 @@ public function copy(?int $id, MailField $data = null, array $options = [])
* @return string 整形後選択リストソース
* @checked
* @noTodo
* @unitTest
*/
public function formatSource($source)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,12 @@ public function testAdmin_ajax_publish()
*/
public function testBeforeAddEvent()
{
$this->markTestIncomplete('こちらのテストはまだ未確認です');
$this->enableSecurityToken();
$this->enableCsrfToken();
$MailMessagesService = $this->getService(MailMessagesServiceInterface::class);
//テストデータベースを生成
$MailMessagesService->createTable(1);
$this->loadFixtureScenario(MailFieldsScenario::class);
$this->loadFixtureScenario(MailContentsScenario::class);

$this->enableSecurityToken();
$this->enableCsrfToken();
//イベントをコル
$this->entryEventToMock(self::EVENT_LAYER_CONTROLLER, 'BcMail.MailFields.beforeAdd', function (Event $event) {
$data = $event->getData('data');
Expand All @@ -296,17 +293,20 @@ public function testBeforeAddEvent()
});
//追加データを準備
$data = [
'mail_content_id' => 1,
'field_name' => 'name_add_1',
'type' => 'text',
'name' => '',
'source' => '資料請求|問い合わせ|その他'
];
//対象URLをコル
$this->post('/baser/admin/bc-mail/mail_fields/add/1', $data);
//check response code
$this->assertResponseCode(302);
//イベントに入るかどうか確認
$mailFields = $this->getTableLocator()->get('BcMail.MailFields');
$query = $mailFields->find()->where(['name' => 'beforeAdd']);
$this->assertEquals(1, $query->count());

//テストデータベースを削除
$MailMessagesService->dropTable(1);
}
Expand All @@ -316,86 +316,97 @@ public function testBeforeAddEvent()
*/
public function testAfterAddEvent()
{
$this->markTestIncomplete('こちらのテストはまだ未確認です');
$MailMessagesService = $this->getService(MailMessagesServiceInterface::class);
//テストデータベースを生成
$MailMessagesService->createTable(10);

$this->enableSecurityToken();
$this->enableCsrfToken();

//イベントをコル
$this->entryEventToMock(self::EVENT_LAYER_CONTROLLER, 'BcMail.MailFields.afterAdd', function (Event $event) {
$data = $event->getData('data');
$contentLinks = TableRegistry::getTableLocator()->get('BcMail.MailFields');
$data->name = 'afterAdd';
$contentLinks->save($data);
});
//Postデータを生成
$MailMessagesService = $this->getService(MailMessagesServiceInterface::class);
$MailMessagesService->createTable(1);

//テストデータベースを生成
$this->loadFixtureScenario(MailContentsScenario::class);
$this->enableSecurityToken();
$this->enableCsrfToken();

//正常系実行
$data = [
'mail_content_id' => 1,
'field_name' => 'name_add_1',
'type' => 'text',
'name' => '',
'source' => '資料請求|問い合わせ|その他'
];
//対象URLをコル
$this->post('/baser/admin/bc-mail/mail_fields/add/10', $data);
$this->post('/baser/admin/bc-mail/mail_fields/add/1', $data);
$this->assertResponseCode(302);

//イベントに入るかどうか確認
$mailFields = $this->getTableLocator()->get('BcMail.MailFields');
$query = $mailFields->find()->where(['name' => 'afterAdd']);
$this->assertEquals(1, $query->count());

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

/**
* Test beforeAddEvent
* Test beforeEditEvent
*/
public function testBeforeEditEvent()
{
$this->markTestIncomplete('こちらのテストはまだ未確認です');
$this->enableSecurityToken();
$this->enableCsrfToken();
//データを生成
$this->loadFixtureScenario(MailFieldsScenario::class);
//イベントをコル
$this->entryEventToMock(self::EVENT_LAYER_CONTROLLER, 'BcMail.MailFields.beforeEdit', function (Event $event) {
$data = $event->getData('data');
$data['name'] = 'beforeEdit';
$event->setData('data', $data);
});
//メールのコンテンツサービスをコル
$mailFieldsService = $this->getService(MailFieldsAdminServiceInterface::class);
$data = $mailFieldsService->get(1);
//対象URLをコル
$this->post('/baser/admin/bc-mail/mail_fields/edit/1/1', $data->toArray());
$this->enableSecurityToken();
$this->enableCsrfToken();
$MailMessagesService = $this->getService(MailMessagesServiceInterface::class);
//テストデータベースを生成
$MailMessagesService->createTable(1);
//データを生成
$this->loadFixtureScenario(MailContentsScenario::class);
$this->loadFixtureScenario(MailFieldsScenario::class);
$data = ['name' => 'editedName', 'type' => 'text'];
//対象URLをコル
$this->post('/baser/admin/bc-mail/mail_fields/edit/1/1', $data);
//check response code
$this->assertResponseCode(302);
//イベントに入るかどうか確認
$mailFields = $this->getTableLocator()->get('BcMail.MailFields');
$query = $mailFields->find()->where(['name' => 'beforeEdit']);
$this->assertEquals(1, $query->count());
//テストデータベースを削除
$MailMessagesService->dropTable(1);
}

/**
* Test beforeAddEvent
* Test afterAddEvent
*/
public function testAfterEditEvent()
{
$this->markTestIncomplete('こちらのテストはまだ未確認です');
$this->enableSecurityToken();
$this->enableCsrfToken();
//データを生成
$this->loadFixtureScenario(MailFieldsScenario::class);
//イベントをコル
$this->entryEventToMock(self::EVENT_LAYER_CONTROLLER, 'BcMail.MailFields.afterEdit', function (Event $event) {
$data = $event->getData('data');
$mailFields = TableRegistry::getTableLocator()->get('BcMail.MailFields');
$data->name = 'afterEdit';
$mailFields->save($data);
});
//メールのコンテンツサービスをコル
$mailFieldsService = $this->getService(MailFieldsAdminServiceInterface::class);
$data = $mailFieldsService->get(1);
//対象URLをコル
$this->post('/baser/admin/bc-mail/mail_fields/edit/1/1', $data->toArray());
$this->enableSecurityToken();
$this->enableCsrfToken();

//データを生成
$this->loadFixtureScenario(MailContentsScenario::class);
$this->loadFixtureScenario(MailFieldsScenario::class);

//正常系実行
$data = ['name' => 'afterEdit', 'type' => 'text'];
$this->post('/baser/admin/bc-mail/mail_fields/edit/1/1', $data);
$this->assertResponseCode(302);

//イベントに入るかどうか確認
$mailFields = $this->getTableLocator()->get('BcMail.MailFields');
$query = $mailFields->find()->where(['name' => 'afterEdit']);
Expand Down
13 changes: 10 additions & 3 deletions plugins/bc-mail/tests/TestCase/Model/Table/MailFieldsTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,15 @@ public function testDuplicateMailField()
*/
public function testHalfTextMailField()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
//case true
$string = 'abc123_';
$result = $this->MailFieldsTable->halfTextMailField($string);
$this->assertTrue($result);

//case false
$string = 'abcABC123_';
$result = $this->MailFieldsTable->halfTextMailField($string);
$this->assertFalse($result);
}

/**
Expand Down Expand Up @@ -275,8 +283,7 @@ public function testAfterSave()
*/
public function testFormatSource($source, $expected)
{
$this->markTestIncomplete('こちらのテストはまだ未確認です');
$result = $this->MailField->formatSource($source);
$result = $this->MailFieldsTable->formatSource($source);
$this->assertEquals($expected, $result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function index(WidgetAreasServiceInterface $service)
* @return void|ResponseInterface
* @checked
* @noTodo
* @unitTest
*/
public function add(WidgetAreasServiceInterface $service)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,36 @@ public function testAdmin_index()
*/
public function testAdmin_add()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$this->loginAdmin($this->getRequest('/'));
$this->enableSecurityToken();
$this->enableCsrfToken();

// データ生成
$data = [
'name' => 'test',
'widgets' => serialize([
[
1 => 'test 1',
2 => 'test 2'
]
])
];

//正常系実行
$this->post('/baser/admin/bc-widget-area/widget_areas/add', $data);
$this->assertResponseCode(302);
$this->assertFlashMessage('新しいウィジェットエリアを保存しました。');
$this->assertRedirect('/baser/admin/bc-widget-area/widget_areas/edit/1');

//データが空の場合、
$data = [
'name' => '',
'widgets' => ''
];
$this->post('/baser/admin/bc-widget-area/widget_areas/add', $data);
$vars = $this->_controller->viewBuilder()->getVars();
$this->assertEquals(['name' => ['_empty' => "ウィジェットエリア名を入力してください。"]], $vars['widgetArea']->getErrors());
$this->assertResponseCode(200);
}

/**
Expand Down

0 comments on commit cf7c4b9

Please sign in to comment.