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 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
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,12 +11,16 @@

namespace BcCustomContent\Test\TestCase\Model\Table;

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

/**
* CustomContentsTableTest
Expand Down Expand Up @@ -78,6 +82,7 @@ public function test_validationWithTable()
$validator = $this->CustomContentsTable->getValidator('withTable');
$errors = $validator->validate([
'list_count' => '101'

]);
$this->assertEquals([
'range' => '一覧表示件数は100までの数値で入力してください。',
Expand Down Expand Up @@ -125,4 +130,28 @@ public function test_createSearchIndex()
$this->assertEquals($rs['publish_begin'], '2021-01-01 00:00:00');
$this->assertEquals($rs['publish_end'], '2021-12-31 23:59:59');
}

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

$this->loadFixtureScenario(CustomContentsScenario::class);

//isExcluded false
$customContent = $customContentService->get(1);
$this->CustomContentsTable->beforeSave(new Event("beforeSave"), $customContent, new ArrayObject());
$this->assertFalse($this->CustomContentsTable->isExcluded());

//isExcluded true
$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