Merge pull request #20741 from civicrm/5.39
[civicrm-core.git] / tests / phpunit / CRM / Contact / BAO / QueryTestDataProvider.php
CommitLineData
6a488035
TO
1<?php
2// vim: set si ai expandtab tabstop=4 shiftwidth=4 softtabstop=4:
3
4/**
5 * File for the CRM_Contact_BAO_Query class
6 *
7 * (PHP 5)
8 *
6c6e6187
TO
9 * @author Walt Haas <walt@dharmatech.org> (801) 534-1262
10 * @copyright Copyright CiviCRM LLC (C) 2009
11 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html
6a488035 12 * GNU Affero General Public License version 3
6c6e6187
TO
13 * @version $Id: GroupTestDataProvider.php 23715 2009-09-21 06:35:47Z shot $
14 * @package CiviCRM
6a488035
TO
15 *
16 * This file is part of CiviCRM
17 *
18 * CiviCRM is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU Affero General Public License
20 * as published by the Free Software Foundation; either version 3 of
21 * the License, or (at your option) any later version.
22 *
23 * CiviCRM is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU Affero General Public License for more details.
27 *
28 * You should have received a copy of the GNU Affero General Public
29 * License along with this program. If not, see
30 * <http://www.gnu.org/licenses/>.
31 */
32
33/**
34 * Provide data to the CRM_Contact_BAO_QueryTest class
35 *
6c6e6187 36 * @package CiviCRM
6a488035
TO
37 */
38class CRM_Contact_BAO_QueryTestDataProvider implements Iterator {
39
40 /**
9f266042 41 * Current count.
42 *
43 * @var int
6a488035
TO
44 */
45 private $i = 0;
46
47 /**
6c6e6187 48 * @var mixed[]
6a488035
TO
49 * This dataset describes various form values and what contact
50 * IDs should be selected when the form values are applied to the
51 * database in dataset.xml
52 */
9099cab3 53 private $dataset = [
eba243b1 54 // Include static group 3
9099cab3
CW
55 [
56 'fv' => ['group' => '3'],
57 'id' => [
92915c55
TO
58 '17',
59 '18',
60 '19',
61 '20',
62 '21',
63 '22',
64 '23',
65 '24',
9099cab3
CW
66 ],
67 ],
eba243b1 68 // Include static group 5
9099cab3
CW
69 [
70 'fv' => ['group' => '5'],
71 'id' => [
92915c55
TO
72 '13',
73 '14',
74 '15',
75 '16',
76 '21',
77 '22',
78 '23',
79 '24',
9099cab3
CW
80 ],
81 ],
eba243b1 82 // Include static groups 3 and 5
9099cab3
CW
83 [
84 'fv' => ['group' => ['3', '5']],
85 'id' => [
92915c55
TO
86 '13',
87 '14',
88 '15',
89 '16',
90 '17',
91 '18',
92 '19',
93 '20',
94 '21',
95 '22',
96 '23',
97 '24',
9099cab3
CW
98 ],
99 ],
e34642c9 100 // Include static groups 3 and 5 in legacy format
9099cab3
CW
101 [
102 'fv' => ['group' => ['3' => 1, '5' => 1]],
103 'id' => [
e34642c9 104 '13',
105 '14',
106 '15',
107 '16',
108 '17',
109 '18',
110 '19',
111 '20',
112 '21',
113 '22',
114 '23',
115 '24',
9099cab3
CW
116 ],
117 ],
eba243b1 118 // Include tag 7
9099cab3
CW
119 [
120 'fv' => ['tag' => '7'],
121 'id' => [
92915c55
TO
122 '11',
123 '12',
124 '15',
125 '16',
126 '19',
127 '20',
128 '23',
129 '24',
9099cab3
CW
130 ],
131 ],
eba243b1 132 // Include tag 9
9099cab3
CW
133 [
134 'fv' => ['tag' => ['9' => 1]],
135 'id' => [
92915c55
TO
136 '10',
137 '12',
138 '14',
139 '16',
140 '18',
141 '20',
142 '22',
143 '24',
fe128a5a
MD
144 '25',
145 '26',
9099cab3
CW
146 ],
147 ],
eba243b1 148 // Include tags 7 and 9
9099cab3
CW
149 [
150 'fv' => ['tag' => ['7', '9']],
151 'id' => [
92915c55
TO
152 '10',
153 '11',
154 '12',
155 '14',
156 '15',
157 '16',
158 '18',
159 '19',
160 '20',
161 '22',
162 '23',
163 '24',
fe128a5a
MD
164 '25',
165 '26',
166 ],
167 ],
168 // Include tags 7 and 10
169 [
170 'fv' => ['tag' => ['7', '10']],
171 'id' => [
172 '11',
173 '12',
174 '15',
175 '16',
176 '19',
177 '20',
178 '23',
179 '24',
180 '25',
181 '26',
182 ],
183 ],
184 // Include tags 10 and 11
185 [
186 'fv' => ['tag' => ['10', '11']],
187 'id' => [
188 '25',
189 '26',
9099cab3
CW
190 ],
191 ],
f11f9737 192 // gender_id 1 = 'Female'
9099cab3
CW
193 [
194 'fv' => ['gender_id' => 1],
195 'id' => ['9', '20', '22'],
196 ],
f11f9737 197 // prefix_id 2 = 'Ms.'
9099cab3
CW
198 [
199 'fv' => ['prefix_id' => 2],
200 'id' => ['10', '13'],
201 ],
f11f9737 202 // suffix_id 6 = 'V'
9099cab3
CW
203 [
204 'fv' => ['suffix_id' => 6],
205 'id' => ['16', '19', '20', '21'],
206 ],
207 ];
6a488035
TO
208
209 public function _construct() {
210 $this->i = 0;
211 }
212
213 public function rewind() {
214 $this->i = 0;
215 }
216
4cbe18b8
EM
217 /**
218 * @return array
219 */
6a488035
TO
220 public function current() {
221 $count = count($this->dataset[$this->i]['id']);
92915c55 222 $ids = $this->dataset[$this->i]['id'];
9099cab3 223 $full = [];
6a488035 224 foreach ($this->dataset[$this->i]['id'] as $key => $value) {
9099cab3 225 $full[] = [
6a488035
TO
226 'contact_id' => $value,
227 'contact_type' => 'Individual',
228 'sort_name' => "Test Contact $value",
9099cab3 229 ];
6a488035 230 }
9099cab3 231 return [$this->dataset[$this->i]['fv'], $count, $ids, $full];
6a488035
TO
232 }
233
4cbe18b8
EM
234 /**
235 * @return int
236 */
6a488035
TO
237 public function key() {
238 return $this->i;
239 }
240
241 public function next() {
242 $this->i++;
243 }
244
4cbe18b8
EM
245 /**
246 * @return bool
247 */
6a488035
TO
248 public function valid() {
249 return isset($this->dataset[$this->i]);
250 }
96025800 251
6a488035
TO
252}
253// class CRM_Contact_BAO_QueryTestDataProvider