Merge pull request #20093 from larssandergreen/mailings-AB-test-improvements
[civicrm-core.git] / tests / phpunit / CRM / Case / WorkflowMessage / CaseActivityTest.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
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 +--------------------------------------------------------------------+
11 */
12
13 /**
14 * Class CRM_Case_WorkflowMessage_CaseActivityTest
15 */
16 class CRM_Case_WorkflowMessage_CaseActivityTest extends CiviUnitTestCase {
17 use \Civi\Test\WorkflowMessageTestTrait;
18
19 public function getWorkflowClass(): string {
20 return CRM_Case_WorkflowMessage_CaseActivity::class;
21 }
22
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'])
27 ->execute()
28 ->indexBy('name')
29 ->column('data');
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: ');
33 }
34
35 /**
36 * Ensure that various methods of constructing a WorkflowMessage all produce similar results.
37 *
38 * To see this, we take all the example data and use it with diff constructors.
39 */
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);
45 }
46 }
47
48 /**
49 * Basic canary test fetching a specific example.
50 *
51 * @throws \API_Exception
52 * @throws \Civi\API\Exception\UnauthorizedException
53 */
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';
57
58 $this->assertTrue(file_exists($file), "Expect find canary file ($file)");
59
60 $get = \Civi\Api4\ExampleData::get()
61 ->addWhere('name', '=', $name)
62 ->execute()
63 ->single();
64 $this->assertEquals($name, $get['name']);
65 $this->assertTrue(!isset($get['data']));
66 $this->assertTrue(!isset($get['asserts']));
67
68 $get = \Civi\Api4\ExampleData::get()
69 ->addWhere('name', '=', $name)
70 ->addSelect('data')
71 ->execute()
72 ->single();
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']);
76 }
77
78 }