Merge pull request #15144 from JKingsnorth/copying-events-contribution-pages
[civicrm-core.git] / tests / phpunit / api / v4 / Action / CustomValuePerformanceTest.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 5 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2019 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27 */
28
29 /**
30 *
31 * @package CRM
32 * @copyright CiviCRM LLC (c) 2004-2019
33 * $Id$
34 *
35 */
36
37
38 namespace api\v4\Action;
39
40 use Civi\Api4\Contact;
41 use Civi\Api4\CustomField;
42 use Civi\Api4\CustomGroup;
43 use api\v4\Traits\QueryCounterTrait;
44
45 /**
46 * @group headless
47 */
48 class CustomValuePerformanceTest extends BaseCustomValueTest {
49
50 use QueryCounterTrait;
51
52 public function testQueryCount() {
53
54 $this->markTestIncomplete();
55
56 $customGroupId = CustomGroup::create()
57 ->setCheckPermissions(FALSE)
58 ->addValue('name', 'MyContactFields')
59 ->addValue('title', 'MyContactFields')
60 ->addValue('extends', 'Contact')
61 ->execute()
62 ->first()['id'];
63
64 CustomField::create()
65 ->setCheckPermissions(FALSE)
66 ->addValue('label', 'FavColor')
67 ->addValue('custom_group_id', $customGroupId)
68 ->addValue('options', ['r' => 'Red', 'g' => 'Green', 'b' => 'Blue'])
69 ->addValue('html_type', 'Select')
70 ->addValue('data_type', 'String')
71 ->execute();
72
73 CustomField::create()
74 ->setCheckPermissions(FALSE)
75 ->addValue('label', 'FavAnimal')
76 ->addValue('custom_group_id', $customGroupId)
77 ->addValue('html_type', 'Text')
78 ->addValue('data_type', 'String')
79 ->execute();
80
81 CustomField::create()
82 ->setCheckPermissions(FALSE)
83 ->addValue('label', 'FavLetter')
84 ->addValue('custom_group_id', $customGroupId)
85 ->addValue('html_type', 'Text')
86 ->addValue('data_type', 'String')
87 ->execute();
88
89 CustomField::create()
90 ->setCheckPermissions(FALSE)
91 ->addValue('label', 'FavFood')
92 ->addValue('custom_group_id', $customGroupId)
93 ->addValue('html_type', 'Text')
94 ->addValue('data_type', 'String')
95 ->execute();
96
97 $this->beginQueryCount();
98
99 Contact::create()
100 ->setCheckPermissions(FALSE)
101 ->addValue('first_name', 'Red')
102 ->addValue('last_name', 'Tester')
103 ->addValue('contact_type', 'Individual')
104 ->addValue('MyContactFields.FavColor', 'r')
105 ->addValue('MyContactFields.FavAnimal', 'Sheep')
106 ->addValue('MyContactFields.FavLetter', 'z')
107 ->addValue('MyContactFields.FavFood', 'Coconuts')
108 ->execute();
109
110 Contact::get()
111 ->setCheckPermissions(FALSE)
112 ->addSelect('display_name')
113 ->addSelect('MyContactFields.FavColor.label')
114 ->addSelect('MyContactFields.FavColor.weight')
115 ->addSelect('MyContactFields.FavColor.is_default')
116 ->addSelect('MyContactFields.FavAnimal')
117 ->addSelect('MyContactFields.FavLetter')
118 ->addWhere('MyContactFields.FavColor', '=', 'r')
119 ->addWhere('MyContactFields.FavFood', '=', 'Coconuts')
120 ->addWhere('MyContactFields.FavAnimal', '=', 'Sheep')
121 ->addWhere('MyContactFields.FavLetter', '=', 'z')
122 ->execute()
123 ->first();
124
125 // FIXME: This count is artificially high due to the line
126 // $this->entity = Tables::getBriefName(Tables::getClassForTable($targetTable));
127 // In class Joinable. TODO: Investigate why.
128 }
129
130 }