Merge pull request #21578 from civicrm/5.42
[civicrm-core.git] / tests / phpunit / api / v4 / Entity / ExampleDataTest.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 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 */
18
19
20 namespace api\v4\Entity;
21
22 use api\v4\UnitTestCase;
23
24 /**
25 * @group headless
26 */
27 class ExampleDataTest extends UnitTestCase {
28
29 /**
30 * Basic canary test fetching a specific example.
31 *
32 * @throws \API_Exception
33 * @throws \Civi\API\Exception\UnauthorizedException
34 */
35 public function testGet() {
36 $file = \Civi::paths()->getPath('[civicrm.root]/Civi/WorkflowMessage/GenericWorkflowMessage/Alex.ex.php');
37 $name = 'workflow/generic/Alex';
38
39 $this->assertTrue(file_exists($file), "Expect find canary file ($file)");
40
41 $get = \Civi\Api4\ExampleData::get()
42 ->addWhere('name', '=', $name)
43 ->execute()
44 ->single();
45 $this->assertEquals($name, $get['name']);
46 $this->assertTrue(!isset($get['data']), 'Default "get" should not return "data"');
47 $this->assertTrue(!isset($get['asserts']), 'Default "get" should not return "asserts"');
48
49 $get = \Civi\Api4\ExampleData::get()
50 ->addWhere('name', 'LIKE', 'workflow/generic/%')
51 ->execute();
52 $this->assertTrue($get->count() > 0);
53 foreach ($get as $gotten) {
54 $this->assertStringStartsWith('workflow/generic/', $gotten['name']);
55 }
56
57 $get = \Civi\Api4\ExampleData::get()
58 ->addWhere('name', '=', $name)
59 ->addSelect('workflow', 'data')
60 ->execute()
61 ->single();
62 $this->assertEquals($name, $get['name']);
63 $this->assertEquals(100, $get['data']['modelProps']['contact']['contact_id']);
64 }
65
66 }