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