1990f6c8e9d1d21e331d2915d35ccb93d0136196
[civicrm-core.git] / tests / phpunit / api / v4 / Action / CustomValuePerformanceTest.php
1 <?php
2
3 namespace api\v4\Action;
4
5 use Civi\Api4\Contact;
6 use Civi\Api4\CustomField;
7 use Civi\Api4\CustomGroup;
8 use api\v4\Traits\QueryCounterTrait;
9
10 /**
11 * @group headless
12 */
13 class CustomValuePerformanceTest extends BaseCustomValueTest {
14
15 use QueryCounterTrait;
16
17 public function testQueryCount() {
18
19 $this->markTestIncomplete();
20
21 $customGroupId = CustomGroup::create()
22 ->setCheckPermissions(FALSE)
23 ->addValue('name', 'MyContactFields')
24 ->addValue('title', 'MyContactFields')
25 ->addValue('extends', 'Contact')
26 ->execute()
27 ->first()['id'];
28
29 CustomField::create()
30 ->setCheckPermissions(FALSE)
31 ->addValue('label', 'FavColor')
32 ->addValue('custom_group_id', $customGroupId)
33 ->addValue('options', ['r' => 'Red', 'g' => 'Green', 'b' => 'Blue'])
34 ->addValue('html_type', 'Select')
35 ->addValue('data_type', 'String')
36 ->execute();
37
38 CustomField::create()
39 ->setCheckPermissions(FALSE)
40 ->addValue('label', 'FavAnimal')
41 ->addValue('custom_group_id', $customGroupId)
42 ->addValue('html_type', 'Text')
43 ->addValue('data_type', 'String')
44 ->execute();
45
46 CustomField::create()
47 ->setCheckPermissions(FALSE)
48 ->addValue('label', 'FavLetter')
49 ->addValue('custom_group_id', $customGroupId)
50 ->addValue('html_type', 'Text')
51 ->addValue('data_type', 'String')
52 ->execute();
53
54 CustomField::create()
55 ->setCheckPermissions(FALSE)
56 ->addValue('label', 'FavFood')
57 ->addValue('custom_group_id', $customGroupId)
58 ->addValue('html_type', 'Text')
59 ->addValue('data_type', 'String')
60 ->execute();
61
62 $this->beginQueryCount();
63
64 Contact::create()
65 ->setCheckPermissions(FALSE)
66 ->addValue('first_name', 'Red')
67 ->addValue('last_name', 'Tester')
68 ->addValue('contact_type', 'Individual')
69 ->addValue('MyContactFields.FavColor', 'r')
70 ->addValue('MyContactFields.FavAnimal', 'Sheep')
71 ->addValue('MyContactFields.FavLetter', 'z')
72 ->addValue('MyContactFields.FavFood', 'Coconuts')
73 ->execute();
74
75 Contact::get()
76 ->setCheckPermissions(FALSE)
77 ->addSelect('display_name')
78 ->addSelect('MyContactFields.FavColor.label')
79 ->addSelect('MyContactFields.FavColor.weight')
80 ->addSelect('MyContactFields.FavColor.is_default')
81 ->addSelect('MyContactFields.FavAnimal')
82 ->addSelect('MyContactFields.FavLetter')
83 ->addWhere('MyContactFields.FavColor', '=', 'r')
84 ->addWhere('MyContactFields.FavFood', '=', 'Coconuts')
85 ->addWhere('MyContactFields.FavAnimal', '=', 'Sheep')
86 ->addWhere('MyContactFields.FavLetter', '=', 'z')
87 ->execute()
88 ->first();
89
90 // FIXME: This count is artificially high due to the line
91 // $this->entity = Tables::getBriefName(Tables::getClassForTable($targetTable));
92 // In class Joinable. TODO: Investigate why.
93 }
94
95 }