Merge pull request #14279 from eileenmcnaughton/db_test2
[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-2019 |
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 * @var integer
37 */
38 private $i = 0;
39
40 /**
41 * @var mixed[]
42 * This dataset describes various form values and what contact
43 * IDs should be selected when the form values are applied to the
44 * database in dataset.xml
45 */
46 private $dataset = array(
47 // Search by Household name: 'Household 9'
48 array(
49 'fv' => array('household_name' => 'Household 9'),
50 'id' => array(
51 '9',
52 ),
53 ),
54 // Search by Household name: 'Household'
55 array(
56 'fv' => array('household_name' => 'Household'),
57 'id' => array(
58 '9',
59 '10',
60 '11',
61 '12',
62 ),
63 ),
64 // Search by State: California
65 array(
66 'fv' => array('state_province_id' => '1004'),
67 'id' => array(
68 '10',
69 '11',
70 ),
71 ),
72 // Search by State: New York
73 array(
74 'fv' => array('state_province_id' => '1031'),
75 'id' => array(
76 '12',
77 ),
78 ),
79 );
80
81 public function _construct() {
82 $this->i = 0;
83 }
84
85 public function rewind() {
86 $this->i = 0;
87 }
88
89 /**
90 * @return array
91 */
92 public function current() {
93 $count = count($this->dataset[$this->i]['id']);
94 $ids = $this->dataset[$this->i]['id'];
95 $full = array();
96 foreach ($this->dataset[$this->i]['id'] as $key => $value) {
97 $full[] = array(
98 'contact_id' => $value,
99 'contact_type' => 'Household',
100 'household_name' => "Household $value",
101 );
102 }
103 return array($this->dataset[$this->i]['fv'], $count, $ids, $full);
104 }
105
106 /**
107 * @return int
108 */
109 public function key() {
110 return $this->i;
111 }
112
113 public function next() {
114 $this->i++;
115 }
116
117 /**
118 * @return bool
119 */
120 public function valid() {
121 return isset($this->dataset[$this->i]);
122 }
123
124 }