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 11, 2024
2 parents de0f110 + a60afb4 commit ce25638
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public function index(MailMessagesAdminServiceInterface $service, int $mailConte
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function view(
MailMessagesAdminServiceInterface $service,
Expand All @@ -130,6 +131,7 @@ public function view(
* @return void|Response
* @checked
* @noTodo
* @unitTest
*/
public function delete(
MailMessagesServiceInterface $service,
Expand Down
1 change: 1 addition & 0 deletions plugins/bc-mail/src/Model/Table/MailMessagesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public function setupUpload(int $mailContentId)
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function afterMarshal(Event $event)
{
Expand Down
1 change: 1 addition & 0 deletions plugins/bc-mail/src/View/Helper/MailHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public function descriptionExists()
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function link($title, $contentsName, $datas = [], $options = [])
{
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 @@ -306,6 +306,7 @@ public function authCaptcha(string $fieldName, array $options = [])
* @return array
* @checked
* @noTodo
* @unitTest
*/
public function getGroupValidErrors(ResultSetInterface $mailFields, string $groupValid, array $options = [], bool $distinct = true)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use BcMail\Service\MailMessagesServiceInterface;
use BcMail\Test\Factory\MailContentFactory;
use Cake\Event\Event;
use Cake\ORM\Entity;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\IntegrationTestTrait;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

Expand Down Expand Up @@ -132,15 +134,72 @@ public function testIndex()
*/
public function testView()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
// メールメッセージのデータを作成する
ContentFactory::make([
'plugin' => 'BcMail',
'type' => 'MailContent',
'url' => '/contact/',
'site_id' => 1,
'title' => 'お問い合わせ',
'entity_id' => 1,
])->persist();
MailContentFactory::make(['id' => 1])->persist();
$MailMessagesService = $this->getService(MailMessagesServiceInterface::class);
//テストデータベースを生成
$MailMessagesService->createTable(1);
$mailMessageTable = TableRegistry::getTableLocator()->get('BcMail.MailMessages');
$mailContentId = 1;
$mailMessageTable->setup($mailContentId);
$mailMessageTable->save(new Entity(['id' => 1]));

//正常テスト
$this->get('/baser/admin/bc-mail/mail_messages/view/1/1');
$this->assertResponseCode(200);

//異常テスト
$this->get('/baser/admin/bc-mail/mail_messages/view/1/2');
$this->assertResponseCode(404);

$MailMessagesService->dropTable(1);
}

/**
* [ADMIN] 受信メール削除
*/
public function testDelete()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$this->enableSecurityToken();
$this->enableCsrfToken();
// メールメッセージのデータを作成する
ContentFactory::make([
'plugin' => 'BcMail',
'type' => 'MailContent',
'url' => '/contact/',
'site_id' => 1,
'title' => 'お問い合わせ',
'entity_id' => 1,
])->persist();
MailContentFactory::make(['id' => 1])->persist();
$MailMessagesService = $this->getService(MailMessagesServiceInterface::class);
//テストデータベースを生成
$MailMessagesService->createTable(1);
$mailMessageTable = TableRegistry::getTableLocator()->get('BcMail.MailMessages');
$mailContentId = 1;
$mailMessageTable->setup($mailContentId);
$mailMessageTable->setup($mailContentId);
$mailMessageTable->save(new Entity(['id' => 1]));

//正常テスト
$this->post('/baser/admin/bc-mail/mail_messages/delete/1/1');
$this->assertResponseCode(302);
$this->assertRedirect(['action' => 'index', 1]);
$this->assertFlashMessage('お問い合わせ への受信データ NO「1」 を削除しました。');

//異常テスト
$this->get('/baser/admin/bc-mail/mail_messages/delete/1/1');
$this->assertResponseCode(405);

$MailMessagesService->dropTable(1);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use BcMail\Test\TestCase\Model\Array;
use BcMail\Test\TestCase\Model\ClassRegistry;
use Cake\Core\Exception\CakeException;
use Cake\Event\Event;
use Cake\ORM\Entity;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\Validation\Validator;
Expand Down Expand Up @@ -668,4 +669,38 @@ public static function validationDefaultDataProvider()
];
}

/**
* test afterMarshal
*/
public function testAfterMarshal()
{
MailFieldsFactory::make([
'id' => 99,
'mail_content_id' => 1,
'field_name' => 'ok99',
'valid_ex' => 'VALID_GROUP_COMPLATE, keke',
'use_field' => 1,
])->persist();
MailFieldsFactory::make([
'id' => 98,
'mail_content_id' => 1,
'field_name' => 'ok98',
'type' => 'number',
'valid_ex' => 'VALID_GROUP_COMPLATE, 98',
'use_field' => 1,
])->persist();
$this->MailMessage->setMailFields(1);
$mailMessage = new MailMessage([
'id' => 1,
'name_1' => "hehe",
'ok98' => "hic98",
'ok99' => "",
]);
$event = new Event('event');
$event->setData('entity', $mailMessage);
$this->MailMessage->afterMarshal($event);
$entity = $event->getData('entity');
$this->assertCount(1, $entity->getErrors()['_not_complate']);
}

}
19 changes: 7 additions & 12 deletions plugins/bc-mail/tests/TestCase/View/Helper/MailHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,25 +149,20 @@ public function testGetToken()
* メールフォームへのリンクを取得
* @dataProvider linkProvider
*/
public function testLink($title, $contentsName, $expected)
public function testLink($title, $contentsName, $url, $expected)
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
ContentFactory::make(['plugin' => 'BcMail', 'type' => 'MailContent', 'name' => $contentsName, 'url' => $url, 'entity_id' => 1])->persist();
$this->expectOutputString($expected);
$this->Mail->link($title, $contentsName, $datas = [], $options = []);
$this->MailHelper->link($title, $contentsName);
}

public static function linkProvider()
{
return [
['タイトル', 'Members', '<a href="/Members">タイトル</a>'],
[' ', 'a', '<a href="/a"> </a>'],
[' ', ' ', '<a href="/ "> </a>'],
[' ', '///', '<a href="/"> </a>'],
[' ', '////a', '<a href="/a"> </a>'],
[' ', '////a//a/aa', '<a href="/a/a/aa"> </a>'],
[' ', '/../../../../a', '<a href="/../../../../a"> </a>'],
['', 'javascript:void(0);', '<a href="/javascript:void(0);"></a>'],
['<script>alert(1)</script>', '////a', '<a href="/a"><script>alert(1)</script></a>']
['タイトル', '/Members/', '/a/', '<a href="/a/index">タイトル</a>'],
[' ', 'a', '/a/', '<a href="/a/index"> </a>'],
[' ', ' ', '', '<a href="/bc-mail/mail"> </a>'],
[' ', '///', '///', '<a href="/index"> </a>'],
];
}

Expand Down
23 changes: 23 additions & 0 deletions plugins/bc-mail/tests/TestCase/View/Helper/MailformHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@
use BaserCore\TestSuite\BcTestCase;
use BcMail\Model\Entity\MailField;
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 Cake\ORM\ResultSet;
use Cake\View\View;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

class MailformHelperTest extends BcTestCase
{
/**
* ScenarioAwareTrait
*/
use ScenarioAwareTrait;

/**
* set up
Expand Down Expand Up @@ -97,4 +105,19 @@ public static function isGroupLastFieldProvider()
[[['group_field' => 'group1'], ['group_field' => 'group2']], 0, true],
];
}

/**
* test getGroupValidErrors
*/
public function testGetGroupValidErrors()
{
// prepare
$this->loadFixtureScenario(MailContentsScenario::class);
$this->loadFixtureScenario(MailFieldsScenario::class);
$MailFieldsService = $this->getService(MailFieldsServiceInterface::class);
// get mail field list
$mailFields = $MailFieldsService->getIndex(1)->all();
$rs = $this->MailformHelper->getGroupValidErrors($mailFields, 'field_name');
$this->assertEquals([], $rs);
}
}

0 comments on commit ce25638

Please sign in to comment.