Update copyright date for 2020
[civicrm-core.git] / tests / phpunit / CRM / Contact / Form / Search / Custom / SampleTestDataProvider.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * Provide data to the CRM_Contact_Form_Search_Custom_SampleTest class
30 *
31 * @package CiviCRM
32 */
33 class CRM_Contact_Form_Search_Custom_SampleTestDataProvider implements Iterator {
34
35 /**
36 * Current count.
37 *
38 * @var int
39 */
40 private $i = 0;
41
42 /**
43 * @var mixed[]
44 * This dataset describes various form values and what contact
45 * IDs should be selected when the form values are applied to the
46 * database in dataset.xml
47 */
48 private $dataset = [
49 // Search by Household name: 'Household 9'
50 [
51 'fv' => ['household_name' => 'Household 9'],
52 'id' => [
53 '9',
54 ],
55 ],
56 // Search by Household name: 'Household'
57 [
58 'fv' => ['household_name' => 'Household'],
59 'id' => [
60 '9',
61 '10',
62 '11',
63 '12',
64 ],
65 ],
66 // Search by State: California
67 [
68 'fv' => ['state_province_id' => '1004'],
69 'id' => [
70 '10',
71 '11',
72 ],
73 ],
74 // Search by State: New York
75 [
76 'fv' => ['state_province_id' => '1031'],
77 'id' => [
78 '12',
79 ],
80 ],
81 ];
82
83 public function _construct() {
84 $this->i = 0;
85 }
86
87 public function rewind() {
88 $this->i = 0;
89 }
90
91 /**
92 * @return array
93 */
94 public function current() {
95 $count = count($this->dataset[$this->i]['id']);
96 $ids = $this->dataset[$this->i]['id'];
97 $full = [];
98 foreach ($this->dataset[$this->i]['id'] as $key => $value) {
99 $full[] = [
100 'contact_id' => $value,
101 'contact_type' => 'Household',
102 'household_name' => "Household $value",
103 ];
104 }
105 return [$this->dataset[$this->i]['fv'], $count, $ids, $full];
106 }
107
108 /**
109 * @return int
110 */
111 public function key() {
112 return $this->i;
113 }
114
115 public function next() {
116 $this->i++;
117 }
118
119 /**
120 * @return bool
121 */
122 public function valid() {
123 return isset($this->dataset[$this->i]);
124 }
125
126 }