Merge pull request #23283 from eileenmcnaughton/import_saved_map
[civicrm-core.git] / tests / phpunit / api / v4 / Custom / CustomValuePerformanceTest.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\Custom;
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 CustomTestBase {
31
32 use QueryCounterTrait;
33
34 public function testQueryCount() {
35
36 $this->markTestIncomplete();
37
38 $customGroupId = CustomGroup::create(FALSE)
39 ->addValue('name', 'MyContactFields')
40 ->addValue('title', 'MyContactFields')
41 ->addValue('extends', 'Contact')
42 ->execute()
43 ->first()['id'];
44
45 CustomField::create(FALSE)
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
53 CustomField::create(FALSE)
54 ->addValue('label', 'FavAnimal')
55 ->addValue('custom_group_id', $customGroupId)
56 ->addValue('html_type', 'Text')
57 ->addValue('data_type', 'String')
58 ->execute();
59
60 CustomField::create(FALSE)
61 ->addValue('label', 'FavLetter')
62 ->addValue('custom_group_id', $customGroupId)
63 ->addValue('html_type', 'Text')
64 ->addValue('data_type', 'String')
65 ->execute();
66
67 CustomField::create(FALSE)
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
76 $this->createTestRecord('Contact', [
77 'first_name' => 'Red',
78 'last_name' => 'Tester',
79 'contact_type' => 'Individual',
80 'MyContactFields.FavColor' => 'r',
81 'MyContactFields.FavAnimal' => 'Sheep',
82 'MyContactFields.FavLetter' => 'z',
83 'MyContactFields.FavFood' => 'Coconuts',
84 ]);
85
86 Contact::get(FALSE)
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 // $this->assertLessThan(10, $this->getQueryCount());
104
105 }
106
107 }