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

unitTest_CustomContentsTable_beforeSave #3392

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public function validationWithTable(Validator $validator): Validator
* @return boolean
* @checked
* @noTodo
* @unitTest
*/
public function beforeSave(EventInterface $event, EntityInterface $entity, \ArrayObject $options)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,25 @@

namespace BcCustomContent\Test\TestCase\Model\Table;

use ArrayObject;
use BaserCore\Service\PluginsServiceInterface;
use BaserCore\TestSuite\BcTestCase;
use BcCustomContent\Model\Table\CustomContentsTable;
use BcCustomContent\Service\CustomContentsServiceInterface;
use BcCustomContent\Test\Scenario\CustomContentsScenario;
use Cake\Event\Event;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

/**
* CustomContentsTableTest
* @property CustomContentsTable $CustomContentsTable
*/
class CustomContentsTableTest extends BcTestCase
{
/**
* ScenarioAwareTrait
*/
use ScenarioAwareTrait;

/**
* Set up
Expand Down Expand Up @@ -64,7 +74,6 @@ public function test_validationWithTable()
'range' => '一覧表示件数は100までの数値で入力してください。',
'halfText' => '一覧表示件数は半角で入力してください。'
], $errors['list_count']);

//101を入力した場合
$validator = $this->CustomContentsTable->getValidator('withTable');
$errors = $validator->validate([
Expand All @@ -73,7 +82,6 @@ public function test_validationWithTable()
$this->assertEquals([
'range' => '一覧表示件数は100までの数値で入力してください。',
], $errors['list_count']);

//何も入力しない場合
$validator = $this->CustomContentsTable->getValidator('withTable');
$errors = $validator->validate([
Expand All @@ -83,4 +91,22 @@ public function test_validationWithTable()
'_empty' => '一覧表示件数は必須項目です。',
], $errors['list_count']);
}

/**
* test beforeSave
*/
public function test_beforeSave()
{
//サービスクラス
$PluginsService = $this->getService(PluginsServiceInterface::class);
$customContentService = $this->getService(CustomContentsServiceInterface::class);
$PluginsService->attach('BcSearchIndex');

//set isExcluded true
$this->loadFixtureScenario(CustomContentsScenario::class);
$customContent = $customContentService->get(1);
$customContent->content->exclude_search = 1;
$this->CustomContentsTable->beforeSave(new Event("beforeSave"), $customContent, new ArrayObject());
$this->assertTrue($this->CustomContentsTable->isExcluded());
HungDV2022 marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading