Skip to content

Commit

Permalink
Merge pull request #4074 from thangnnmd/unitTest_MailMessagesTable_af…
Browse files Browse the repository at this point in the history
…terMarshal

MailMessagesTable::afterMarshal
  • Loading branch information
HungDV2022 authored Dec 11, 2024
2 parents 91d8157 + 39121e9 commit 3164455
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
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
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']);
}

}

0 comments on commit 3164455

Please sign in to comment.