Commit | Line | Data |
---|---|---|
19b53e5b C |
1 | <?php |
2 | ||
380f3545 TO |
3 | /* |
4 | +--------------------------------------------------------------------+ | |
7d61e75f | 5 | | Copyright CiviCRM LLC. All rights reserved. | |
380f3545 | 6 | | | |
7d61e75f TO |
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 | | |
380f3545 TO |
10 | +--------------------------------------------------------------------+ |
11 | */ | |
12 | ||
13 | /** | |
14 | * | |
15 | * @package CRM | |
ca5cec67 | 16 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
380f3545 TO |
17 | * $Id$ |
18 | * | |
19 | */ | |
20 | ||
21 | ||
19b53e5b C |
22 | namespace api\v4\Action; |
23 | ||
24 | use Civi\Api4\Contact; | |
25 | use Civi\Api4\CustomField; | |
26 | use Civi\Api4\CustomGroup; | |
27 | use api\v4\Traits\QueryCounterTrait; | |
28 | ||
29 | /** | |
30 | * @group headless | |
31 | */ | |
32 | class CustomValuePerformanceTest extends BaseCustomValueTest { | |
33 | ||
34 | use QueryCounterTrait; | |
35 | ||
36 | public function testQueryCount() { | |
37 | ||
38 | $this->markTestIncomplete(); | |
39 | ||
40 | $customGroupId = CustomGroup::create() | |
41 | ->setCheckPermissions(FALSE) | |
42 | ->addValue('name', 'MyContactFields') | |
43 | ->addValue('title', 'MyContactFields') | |
44 | ->addValue('extends', 'Contact') | |
45 | ->execute() | |
46 | ->first()['id']; | |
47 | ||
48 | CustomField::create() | |
49 | ->setCheckPermissions(FALSE) | |
50 | ->addValue('label', 'FavColor') | |
51 | ->addValue('custom_group_id', $customGroupId) | |
52 | ->addValue('options', ['r' => 'Red', 'g' => 'Green', 'b' => 'Blue']) | |
53 | ->addValue('html_type', 'Select') | |
54 | ->addValue('data_type', 'String') | |
55 | ->execute(); | |
56 | ||
57 | CustomField::create() | |
58 | ->setCheckPermissions(FALSE) | |
59 | ->addValue('label', 'FavAnimal') | |
60 | ->addValue('custom_group_id', $customGroupId) | |
61 | ->addValue('html_type', 'Text') | |
62 | ->addValue('data_type', 'String') | |
63 | ->execute(); | |
64 | ||
65 | CustomField::create() | |
66 | ->setCheckPermissions(FALSE) | |
67 | ->addValue('label', 'FavLetter') | |
68 | ->addValue('custom_group_id', $customGroupId) | |
69 | ->addValue('html_type', 'Text') | |
70 | ->addValue('data_type', 'String') | |
71 | ->execute(); | |
72 | ||
73 | CustomField::create() | |
74 | ->setCheckPermissions(FALSE) | |
75 | ->addValue('label', 'FavFood') | |
76 | ->addValue('custom_group_id', $customGroupId) | |
77 | ->addValue('html_type', 'Text') | |
78 | ->addValue('data_type', 'String') | |
79 | ->execute(); | |
80 | ||
81 | $this->beginQueryCount(); | |
82 | ||
83 | Contact::create() | |
84 | ->setCheckPermissions(FALSE) | |
85 | ->addValue('first_name', 'Red') | |
86 | ->addValue('last_name', 'Tester') | |
87 | ->addValue('contact_type', 'Individual') | |
88 | ->addValue('MyContactFields.FavColor', 'r') | |
89 | ->addValue('MyContactFields.FavAnimal', 'Sheep') | |
90 | ->addValue('MyContactFields.FavLetter', 'z') | |
91 | ->addValue('MyContactFields.FavFood', 'Coconuts') | |
92 | ->execute(); | |
93 | ||
94 | Contact::get() | |
95 | ->setCheckPermissions(FALSE) | |
96 | ->addSelect('display_name') | |
97 | ->addSelect('MyContactFields.FavColor.label') | |
98 | ->addSelect('MyContactFields.FavColor.weight') | |
99 | ->addSelect('MyContactFields.FavColor.is_default') | |
100 | ->addSelect('MyContactFields.FavAnimal') | |
101 | ->addSelect('MyContactFields.FavLetter') | |
102 | ->addWhere('MyContactFields.FavColor', '=', 'r') | |
103 | ->addWhere('MyContactFields.FavFood', '=', 'Coconuts') | |
104 | ->addWhere('MyContactFields.FavAnimal', '=', 'Sheep') | |
105 | ->addWhere('MyContactFields.FavLetter', '=', 'z') | |
106 | ->execute() | |
107 | ->first(); | |
108 | ||
109 | // FIXME: This count is artificially high due to the line | |
110 | // $this->entity = Tables::getBriefName(Tables::getClassForTable($targetTable)); | |
111 | // In class Joinable. TODO: Investigate why. | |
112 | } | |
113 | ||
114 | } |