APIv4 - Reorganize test classes, don't use transactions for custom value tests
[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\Api4TestBase;
23 use Civi\Test\TransactionalInterface;
24
25 /**
26 * @group headless
27 */
28 class ExampleDataTest extends Api4TestBase implements TransactionalInterface {
29
30 /**
31 * Basic canary test fetching a specific example.
32 *
33 * @throws \API_Exception
34 * @throws \Civi\API\Exception\UnauthorizedException
35 */
36 public function testGet() {
37 $file = \Civi::paths()->getPath('[civicrm.root]/Civi/WorkflowMessage/GenericWorkflowMessage/Alex.ex.php');
38 $name = 'workflow/generic/Alex';
39
40 $this->assertTrue(file_exists($file), "Expect find canary file ($file)");
41
42 $get = \Civi\Api4\ExampleData::get()
43 ->addWhere('name', '=', $name)
44 ->execute()
45 ->single();
46 $this->assertEquals($name, $get['name']);
47 $this->assertTrue(!isset($get['data']), 'Default "get" should not return "data"');
48 $this->assertTrue(!isset($get['asserts']), 'Default "get" should not return "asserts"');
49
50 $get = \Civi\Api4\ExampleData::get()
51 ->addWhere('name', 'LIKE', 'workflow/generic/%')
52 ->execute();
53 $this->assertTrue($get->count() > 0);
54 foreach ($get as $gotten) {
55 $this->assertStringStartsWith('workflow/generic/', $gotten['name']);
56 }
57
58 $get = \Civi\Api4\ExampleData::get()
59 ->addWhere('name', '=', $name)
60 ->addSelect('workflow', 'data')
61 ->execute()
62 ->single();
63 $this->assertEquals($name, $get['name']);
64 $this->assertEquals(100, $get['data']['modelProps']['contact']['contact_id']);
65 }
66
67 }