4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
14 * Class CRM_Case_WorkflowMessage_CaseActivityTest
16 class CRM_Case_WorkflowMessage_CaseActivityTest
extends CiviUnitTestCase
{
17 use \Civi\Test\WorkflowMessageTestTrait
;
19 public function getWorkflowClass(): string {
20 return CRM_Case_WorkflowMessage_CaseActivity
::class;
23 public function testAdhocClassEquiv() {
24 $examples = \Civi\Api4\ExampleData
::get(0)
25 ->setSelect(['name', 'data'])
26 ->addWhere('name', 'IN', ['workflow/case_activity/CaseAdhocExample', 'workflow/case_activity/CaseModelExample'])
30 $byAdhoc = Civi\WorkflowMessage\WorkflowMessage
::create('case_activity', $examples['workflow/case_activity/CaseAdhocExample']);
31 $byClass = new CRM_Case_WorkflowMessage_CaseActivity($examples['workflow/case_activity/CaseModelExample']);
32 $this->assertSameWorkflowMessage($byClass, $byAdhoc, 'Compare byClass and byAdhoc: ');
36 * Ensure that various methods of constructing a WorkflowMessage all produce similar results.
38 * To see this, we take all the example data and use it with diff constructors.
40 public function testConstructorEquivalence() {
41 $examples = $this->findExamples()->execute()->indexBy('name')->column('data');
42 $this->assertTrue(count($examples) >= 1, 'Must have at least one example data-set');
43 foreach ($examples as $example) {
44 $this->assertConstructorEquivalence($example);
49 * Basic canary test fetching a specific example.
51 * @throws \API_Exception
52 * @throws \Civi\API\Exception\UnauthorizedException
54 public function testExampleGet() {
55 $file = \Civi
::paths()->getPath('[civicrm.root]/tests/phpunit/CRM/Case/WorkflowMessage/CaseActivity/CaseModelExample.ex.php');
56 $name = 'workflow/case_activity/CaseModelExample';
58 $this->assertTrue(file_exists($file), "Expect find canary file ($file)");
60 $get = \Civi\Api4\ExampleData
::get()
61 ->addWhere('name', '=', $name)
64 $this->assertEquals($name, $get['name']);
65 $this->assertTrue(!isset($get['data']));
66 $this->assertTrue(!isset($get['asserts']));
68 $get = \Civi\Api4\ExampleData
::get()
69 ->addWhere('name', '=', $name)
73 $this->assertEquals($name, $get['name']);
74 $this->assertEquals(100, $get['data']['modelProps']['contact']['contact_id']);
75 $this->assertEquals('myrole', $get['data']['modelProps']['contact']['role']);