Merge pull request #14422 from civicrm/5.14
[civicrm-core.git] / tests / phpunit / CRM / Contact / BAO / QueryTestDataProvider.php
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 *
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
12 * GNU Affero General Public License version 3
13 * @version $Id: GroupTestDataProvider.php 23715 2009-09-21 06:35:47Z shot $
14 * @package CiviCRM
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 *
36 * @package CiviCRM
37 */
38 class CRM_Contact_BAO_QueryTestDataProvider implements Iterator {
39
40 /**
41 * Current count.
42 *
43 * @var int
44 */
45 private $i = 0;
46
47 /**
48 * @var mixed[]
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 */
53 private $dataset = array(
54 // Include static group 3
55 array(
56 'fv' => array('group' => '3'),
57 'id' => array(
58 '17',
59 '18',
60 '19',
61 '20',
62 '21',
63 '22',
64 '23',
65 '24',
66 ),
67 ),
68 // Include static group 5
69 array(
70 'fv' => array('group' => '5'),
71 'id' => array(
72 '13',
73 '14',
74 '15',
75 '16',
76 '21',
77 '22',
78 '23',
79 '24',
80 ),
81 ),
82 // Include static groups 3 and 5
83 array(
84 'fv' => array('group' => array('3', '5')),
85 'id' => array(
86 '13',
87 '14',
88 '15',
89 '16',
90 '17',
91 '18',
92 '19',
93 '20',
94 '21',
95 '22',
96 '23',
97 '24',
98 ),
99 ),
100 // Include static groups 3 and 5 in legacy format
101 array(
102 'fv' => array('group' => array('3' => 1, '5' => 1)),
103 'id' => array(
104 '13',
105 '14',
106 '15',
107 '16',
108 '17',
109 '18',
110 '19',
111 '20',
112 '21',
113 '22',
114 '23',
115 '24',
116 ),
117 ),
118 // Include tag 7
119 array(
120 'fv' => array('tag' => '7'),
121 'id' => array(
122 '11',
123 '12',
124 '15',
125 '16',
126 '19',
127 '20',
128 '23',
129 '24',
130 ),
131 ),
132 // Include tag 9
133 array(
134 'fv' => array('tag' => array('9' => 1)),
135 'id' => array(
136 '10',
137 '12',
138 '14',
139 '16',
140 '18',
141 '20',
142 '22',
143 '24',
144 ),
145 ),
146 // Include tags 7 and 9
147 array(
148 'fv' => array('tag' => array('7', '9')),
149 'id' => array(
150 '10',
151 '11',
152 '12',
153 '14',
154 '15',
155 '16',
156 '18',
157 '19',
158 '20',
159 '22',
160 '23',
161 '24',
162 ),
163 ),
164 // gender_id 1 = 'Female'
165 array(
166 'fv' => array('gender_id' => 1),
167 'id' => array('9', '20', '22'),
168 ),
169 // prefix_id 2 = 'Ms.'
170 array(
171 'fv' => array('prefix_id' => 2),
172 'id' => array('10', '13'),
173 ),
174 // suffix_id 6 = 'V'
175 array(
176 'fv' => array('suffix_id' => 6),
177 'id' => array('16', '19', '20', '21'),
178 ),
179 );
180
181 public function _construct() {
182 $this->i = 0;
183 }
184
185 public function rewind() {
186 $this->i = 0;
187 }
188
189 /**
190 * @return array
191 */
192 public function current() {
193 $count = count($this->dataset[$this->i]['id']);
194 $ids = $this->dataset[$this->i]['id'];
195 $full = array();
196 foreach ($this->dataset[$this->i]['id'] as $key => $value) {
197 $full[] = array(
198 'contact_id' => $value,
199 'contact_type' => 'Individual',
200 'sort_name' => "Test Contact $value",
201 );
202 }
203 return array($this->dataset[$this->i]['fv'], $count, $ids, $full);
204 }
205
206 /**
207 * @return int
208 */
209 public function key() {
210 return $this->i;
211 }
212
213 public function next() {
214 $this->i++;
215 }
216
217 /**
218 * @return bool
219 */
220 public function valid() {
221 return isset($this->dataset[$this->i]);
222 }
223
224 }
225 // class CRM_Contact_BAO_QueryTestDataProvider