From 70adffbaa145d68a05a0494d214b55ac0cea55df Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Fri, 5 Feb 2016 21:39:54 +0530 Subject: [PATCH] CRM-17313 fix --- CRM/Contact/BAO/Query.php | 56 ++++ CRM/Contact/BAO/SavedSearch.php | 79 ++++-- CRM/Contact/Form/Search/Advanced.php | 20 +- CRM/Contact/Form/Search/Custom/Group.php | 20 -- .../Form/Search/Custom/MultipleValues.php | 7 - CRM/Contact/Form/Search/Custom/PriceSet.php | 7 - CRM/Contact/Form/Search/Custom/Proximity.php | 3 + CRM/Contact/Form/Search/Custom/Sample.php | 4 +- .../Form/Search/Custom/ZipCodeRange.php | 7 - CRM/Contact/Selector.php | 2 +- CRM/Upgrade/Incremental/php/FourFour.php | 5 +- CRM/Utils/Array.php | 21 ++ .../Contact/Form/Search/Custom/GroupTest.php | 7 +- .../Contact/Form/Search/Custom/SampleTest.php | 253 ++++++++++++++++++ .../Search/Custom/SampleTestDataProvider.php | 124 +++++++++ .../group-dataset.xml} | 0 .../Search/Custom/datasets/sample-dataset.xml | 92 +++++++ 17 files changed, 623 insertions(+), 84 deletions(-) create mode 100644 tests/phpunit/CRM/Contact/Form/Search/Custom/SampleTest.php create mode 100644 tests/phpunit/CRM/Contact/Form/Search/Custom/SampleTestDataProvider.php rename tests/phpunit/CRM/Contact/Form/Search/Custom/{dataset.xml => datasets/group-dataset.xml} (100%) create mode 100644 tests/phpunit/CRM/Contact/Form/Search/Custom/datasets/sample-dataset.xml diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 881874dd48..a6e652d100 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -1474,6 +1474,14 @@ class CRM_Contact_BAO_Query { } foreach ($formValues as $id => $values) { + + if (self::isAlreadyProcessedForQueryFormat($values)) { + $params[] = $values; + continue; + } + + self::legacyConvertFormValues($id, $values); + if ($id == 'privacy') { if (is_array($formValues['privacy'])) { $op = !empty($formValues['privacy']['do_not_toggle']) ? '=' : '!='; @@ -1541,6 +1549,31 @@ class CRM_Contact_BAO_Query { return $params; } + /** + * Function to support legacy format for groups and tags. + * + * @param string $id + * @param array|int $values + * + */ + public static function legacyConvertFormValues($id, &$values) { + $legacyElements = array( + 'group', + 'tag', + 'contact_tags', + 'contact_type', + 'membership_type_id', + 'membership_status_id', + 'activity_type_id', + 'location_type', + ); + if (in_array($id, $legacyElements) && is_array($values)) { + // prior to 4.6, formValues for some attributes (e.g. group, tag) are stored in array(id1 => 1, id2 => 1), + // as per the recent Search fixes $values need to be in standard array(id1, id2) format + CRM_Utils_Array::formatArrayKeys($values); + } + } + /** * @param int $id * @param array $values @@ -4471,6 +4504,29 @@ civicrm_relationship.is_permission_a_b = 0 return TRUE; } return FALSE; + + /** + * Has this field already been reformatting to Query object syntax. + * + * The form layer passed formValues to this function in preProcess & postProcess. Reason unknown. This seems + * to come with associated double queries & is possibly damaging performance. + * + * However, here we add a tested function to ensure convertFormValues identifies pre-processed fields & returns + * them as they are. + * + * @param mixed $values + * Value in formValues for the field. + * + * @return bool; + */ + public static function isAlreadyProcessedForQueryFormat($values) { + if (!is_array($values)) { + return FALSE; + } + if (($operator = CRM_Utils_Array::value(1, $values)) == FALSE) { + return FALSE; + } + return in_array($operator, CRM_Core_DAO::acceptedSQLOperators()); } /** diff --git a/CRM/Contact/BAO/SavedSearch.php b/CRM/Contact/BAO/SavedSearch.php index dc50ae0d59..bb0766730c 100644 --- a/CRM/Contact/BAO/SavedSearch.php +++ b/CRM/Contact/BAO/SavedSearch.php @@ -94,7 +94,7 @@ class CRM_Contact_BAO_SavedSearch extends CRM_Contact_DAO_SavedSearch { * The id of the saved search. * * @return array - * the values of the posted saved search + * the values of the posted saved search used as default values in various Search Form */ public static function &getFormValues($id) { $fv = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $id, 'form_values'); @@ -104,27 +104,74 @@ class CRM_Contact_BAO_SavedSearch extends CRM_Contact_DAO_SavedSearch { $result = unserialize($fv); } - // check to see if we need to convert the old privacy array - // CRM-9180 - if (isset($result['privacy'])) { - if (is_array($result['privacy'])) { - $result['privacy_operator'] = 'AND'; - $result['privacy_toggle'] = 1; - if (isset($result['privacy']['do_not_toggle'])) { - if ($result['privacy']['do_not_toggle']) { - $result['privacy_toggle'] = 2; + $specialFields = array( + 'contact_type', + 'group', + 'contact_tags', + 'member_membership_type_id', + 'member_status_id', + 'activity_type_id', + 'location_type', + ); + foreach ($result as $element => $value) { + if (CRM_Contact_BAO_Query::isAlreadyProcessedForQueryFormat($value)) { + $id = CRM_Utils_Array::value(0, $value); + $value = CRM_Utils_Array::value(2, $value); + if (is_array($value) && in_array(key($value), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) { + $value = CRM_Utils_Array::value(key($value), $value); + } + $result[$id] = $value; + unset($result[$element]); + continue; + } + if (!empty($value) && is_array($value)) { + if (in_array($element, $specialFields)) { + $element = str_replace('member_membership_type_id', 'membership_type_id', $element); + $element = str_replace('member_status_id', 'membership_status_id', $element); + CRM_Contact_BAO_Query::legacyConvertFormValues($element, $value); + $result[$element] = $value; + } + // As per the OK (Operator as Key) value format, value array may contain key + // as an operator so to ensure the default is always set actual value + elseif (in_array(key($value), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) { + $result[$element] = CRM_Utils_Array::value(key($value), $value); + if (is_string($result[$element])) { + $result[$element] = str_replace("%", '', $result[$element]); } - unset($result['privacy']['do_not_toggle']); } + } + if (substr($element, 0, 7) == 'custom_' && + (substr($element, -5, 5) == '_from' || substr($element, -3, 3) == '_to') + ) { + // Ensure the _relative field is set if from or to are set to ensure custom date + // fields with 'from' or 'to' values are displayed when the are set in the smart group + // being loaded. (CRM-17116) + if (!isset($result[CRM_Contact_BAO_Query::getCustomFieldName($element) . '_relative'])) { + $result[CRM_Contact_BAO_Query::getCustomFieldName($element) . '_relative'] = 0; + } + } + // check to see if we need to convert the old privacy array + // CRM-9180 + if (!empty($result['privacy'])) { + if (is_array($result['privacy'])) { + $result['privacy_operator'] = 'AND'; + $result['privacy_toggle'] = 1; + if (isset($result['privacy']['do_not_toggle'])) { + if ($result['privacy']['do_not_toggle']) { + $result['privacy_toggle'] = 2; + } + unset($result['privacy']['do_not_toggle']); + } - $result['privacy_options'] = array(); - foreach ($result['privacy'] as $name => $value) { - if ($value) { - $result['privacy_options'][] = $name; + $result['privacy_options'] = array(); + foreach ($result['privacy'] as $name => $value) { + if ($value) { + $result['privacy_options'][] = $name; + } } } + unset($result['privacy']); } - unset($result['privacy']); } return $result; diff --git a/CRM/Contact/Form/Search/Advanced.php b/CRM/Contact/Form/Search/Advanced.php index e8d0b4ca73..7d06fc0a2e 100644 --- a/CRM/Contact/Form/Search/Advanced.php +++ b/CRM/Contact/Form/Search/Advanced.php @@ -424,25 +424,7 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search { } if ($this->_ssID && empty($_POST)) { - $specialFields = array('contact_type', 'group', 'contact_tags', 'member_membership_type_id', 'member_status_id'); - - foreach ($defaults as $element => $value) { - if (!empty($value) && is_array($value)) { - if (in_array($element, $specialFields)) { - $element = str_replace('member_membership_type_id', 'membership_type_id', $element); - $element = str_replace('member_status_id', 'membership_status_id', $element); - $defaults[$element] = array_keys($value); - } - // As per the OK (Operator as Key) value format, value array may contain key - // as an operator so to ensure the default is always set actual value - elseif (in_array(key($value), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) { - $defaults[$element] = CRM_Utils_Array::value(key($value), $value); - if (is_string($defaults[$element])) { - $defaults[$element] = str_replace("%", '', $defaults[$element]); - } - } - } - } + $defaults = array_merge($defaults, CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID)); } return $defaults; } diff --git a/CRM/Contact/Form/Search/Custom/Group.php b/CRM/Contact/Form/Search/Custom/Group.php index 7bc79e1580..123cc31a2c 100644 --- a/CRM/Contact/Form/Search/Custom/Group.php +++ b/CRM/Contact/Form/Search/Custom/Group.php @@ -150,26 +150,6 @@ class CRM_Contact_Form_Search_Custom_Group extends CRM_Contact_Form_Search_Custo $form->assign('elements', array('includeGroups', 'excludeGroups', 'andOr', 'includeTags', 'excludeTags')); } - /** - * Set search form field defaults here. - * @return array - */ - public function setDefaultValues() { - $defaults = array('andOr' => '1'); - - if (!empty($this->_formValues)) { - $defaults['andOr'] = CRM_Utils_Array::value('andOr', $this->_formValues, '1'); - - $defaults['includeGroups'] = CRM_Utils_Array::value('includeGroups', $this->_formValues); - $defaults['excludeGroups'] = CRM_Utils_Array::value('excludeGroups', $this->_formValues); - - $defaults['includeTags'] = CRM_Utils_Array::value('includeTags', $this->_formValues); - $defaults['excludeTags'] = CRM_Utils_Array::value('excludeTags', $this->_formValues); - } - - return $defaults; - } - /** * @param int $offset * @param int $rowcount diff --git a/CRM/Contact/Form/Search/Custom/MultipleValues.php b/CRM/Contact/Form/Search/Custom/MultipleValues.php index bac549225f..952b03c386 100644 --- a/CRM/Contact/Form/Search/Custom/MultipleValues.php +++ b/CRM/Contact/Form/Search/Custom/MultipleValues.php @@ -292,13 +292,6 @@ contact_a.sort_name as sort_name, return 'CRM/Contact/Form/Search/Custom/MultipleValues.tpl'; } - /** - * @return array - */ - public function setDefaultValues() { - return array(); - } - /** * @param $row */ diff --git a/CRM/Contact/Form/Search/Custom/PriceSet.php b/CRM/Contact/Form/Search/Custom/PriceSet.php index 2436b8ca50..3e6b26eba5 100644 --- a/CRM/Contact/Form/Search/Custom/PriceSet.php +++ b/CRM/Contact/Form/Search/Custom/PriceSet.php @@ -338,13 +338,6 @@ INNER JOIN {$this->_tableName} tempTable ON ( tempTable.contact_id = contact_a.i return 'CRM/Contact/Form/Search/Custom.tpl'; } - /** - * @return array - */ - public function setDefaultValues() { - return array(); - } - /** * @param $row */ diff --git a/CRM/Contact/Form/Search/Custom/Proximity.php b/CRM/Contact/Form/Search/Custom/Proximity.php index 78015b2f91..fec178fc69 100644 --- a/CRM/Contact/Form/Search/Custom/Proximity.php +++ b/CRM/Contact/Form/Search/Custom/Proximity.php @@ -271,6 +271,9 @@ AND cgc.group_id = {$this->_group} * @return array|null */ public function setDefaultValues() { + if (!empty($this->_formValues)) { + return $this->_formValues; + } $config = CRM_Core_Config::singleton(); $countryDefault = $config->defaultContactCountry; $stateprovinceDefault = $config->defaultContactStateProvince; diff --git a/CRM/Contact/Form/Search/Custom/Sample.php b/CRM/Contact/Form/Search/Custom/Sample.php index 0d1afb1582..f4634b9656 100644 --- a/CRM/Contact/Form/Search/Custom/Sample.php +++ b/CRM/Contact/Form/Search/Custom/Sample.php @@ -211,9 +211,7 @@ LEFT JOIN civicrm_state_province state_province ON state_province.id = address.s * @return array */ public function setDefaultValues() { - return array( - 'household_name' => '', - ); + return array_merge(array('household_name' => ''), $this->_formValues); } /** diff --git a/CRM/Contact/Form/Search/Custom/ZipCodeRange.php b/CRM/Contact/Form/Search/Custom/ZipCodeRange.php index 2b5c7571fa..68214077f8 100644 --- a/CRM/Contact/Form/Search/Custom/ZipCodeRange.php +++ b/CRM/Contact/Form/Search/Custom/ZipCodeRange.php @@ -178,13 +178,6 @@ LEFT JOIN civicrm_email email ON ( email.contact_id = contact_a.id AND return $this->whereClause($where, $params); } - /** - * @return array - */ - public function setDefaultValues() { - return array(); - } - /** * @return string */ diff --git a/CRM/Contact/Selector.php b/CRM/Contact/Selector.php index d8920ae59f..5191bfbaec 100644 --- a/CRM/Contact/Selector.php +++ b/CRM/Contact/Selector.php @@ -630,7 +630,7 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se $links = self::links($this->_context, $this->_contextMenu, $this->_key); //check explicitly added contact to a Smart Group. - $groupID = CRM_Utils_Array::key('1', $this->_formValues['group']); + $groupID = CRM_Utils_Array::value('group', $this->_formValues); $pseudoconstants = array(); // for CRM-3157 purposes diff --git a/CRM/Upgrade/Incremental/php/FourFour.php b/CRM/Upgrade/Incremental/php/FourFour.php index c6357d1cb3..81a0e8be09 100644 --- a/CRM/Upgrade/Incremental/php/FourFour.php +++ b/CRM/Upgrade/Incremental/php/FourFour.php @@ -436,7 +436,10 @@ ALTER TABLE civicrm_dashboard $dao = new CRM_Contact_DAO_SavedSearch(); $dao->find(); while ($dao->fetch()) { - $formValues = CRM_Contact_BAO_SavedSearch::getFormValues($dao->id); + $formValues = NULL; + if (!empty($dao->form_values)) { + $formValues = unserialize($dao->form_values); + } if (!empty($formValues['mapper'])) { foreach ($formValues['mapper'] as $key => $value) { foreach ($value as $k => $v) { diff --git a/CRM/Utils/Array.php b/CRM/Utils/Array.php index d82ff2df4c..9ac18f90ab 100644 --- a/CRM/Utils/Array.php +++ b/CRM/Utils/Array.php @@ -964,4 +964,25 @@ class CRM_Utils_Array { $r[$last] = $value; } + /** + * Convert array where key(s) holds the actual value and value(s) as 1 into array of actual values + * Ex: array('foobar' => 1, 4 => 1) formatted into array('foobar', 4) + * + * @param array $array + * @return void + */ + public static function formatArrayKeys(&$array) { + $keys = array_keys($array, 1); + if (count($keys) > 1 || + (count($keys) == 1 && + (current($keys) > 1 || + is_string(current($keys)) || + (current($keys) == 1 && $array[1] == 1) // handle (0 => 4), (1 => 1) + ) + ) + ) { + $array = $keys; + } + } + } diff --git a/tests/phpunit/CRM/Contact/Form/Search/Custom/GroupTest.php b/tests/phpunit/CRM/Contact/Form/Search/Custom/GroupTest.php index cde44bd2ed..386771a0db 100644 --- a/tests/phpunit/CRM/Contact/Form/Search/Custom/GroupTest.php +++ b/tests/phpunit/CRM/Contact/Form/Search/Custom/GroupTest.php @@ -97,11 +97,12 @@ class CRM_Contact_Form_Search_Custom_GroupTest extends CiviUnitTestCase { $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, $this->createFlatXMLDataSet( - dirname(__FILE__) . '/dataset.xml' + dirname(__FILE__) . '/datasets/group-dataset.xml' ) ); $obj = new CRM_Contact_Form_Search_Custom_Group($fv); + $sql = $obj->all(); $dao = CRM_Core_DAO::executeQuery($sql); @@ -133,7 +134,7 @@ class CRM_Contact_Form_Search_Custom_GroupTest extends CiviUnitTestCase { $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, $this->createFlatXMLDataSet( - dirname(__FILE__) . '/dataset.xml' + dirname(__FILE__) . '/datasets/group-dataset.xml' ) ); $obj = new CRM_Contact_Form_Search_Custom_Group($fv); @@ -169,7 +170,7 @@ class CRM_Contact_Form_Search_Custom_GroupTest extends CiviUnitTestCase { $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, $this->createFlatXMLDataSet( - dirname(__FILE__) . '/dataset.xml' + dirname(__FILE__) . '/datasets/group-dataset.xml' ) ); $obj = new CRM_Contact_Form_Search_Custom_Group($fv); diff --git a/tests/phpunit/CRM/Contact/Form/Search/Custom/SampleTest.php b/tests/phpunit/CRM/Contact/Form/Search/Custom/SampleTest.php new file mode 100644 index 0000000000..53c0339b9e --- /dev/null +++ b/tests/phpunit/CRM/Contact/Form/Search/Custom/SampleTest.php @@ -0,0 +1,253 @@ +foreignKeyChecksOff(); + + $this->quickCleanup($this->_tablesToTruncate); + + // echo "testCount\n"; + $op = new PHPUnit_Extensions_Database_Operation_Insert(); + $op->execute($this->_dbconn, + $this->createFlatXMLDataSet( + dirname(__FILE__) . '/datasets/sample-dataset.xml' + ) + ); + + $obj = new CRM_Contact_Form_Search_Custom_Sample($fv); + + $this->assertEquals($count, $obj->count(), + 'In line ' . __LINE__ + ); + } + + /** + * Test CRM_Contact_Form_Search_Custom_Sample::all() + * @dataProvider dataProvider + * @param $fv + * @param $count + * @param $ids + * @param $full + * @throws \Exception + */ + public function testAll($fv, $count, $ids, $full) { + // Truncate affected tables + $this->quickCleanup($this->_tablesToTruncate); + + // echo "testAll\n"; + $op = new PHPUnit_Extensions_Database_Operation_Insert(); + $op->execute($this->_dbconn, + $this->createFlatXMLDataSet( + dirname(__FILE__) . '/datasets/sample-dataset.xml' + ) + ); + $obj = new CRM_Contact_Form_Search_Custom_Sample($fv); + $sql = $obj->all(); + $this->assertTrue(is_string($sql)); + $dao = CRM_Core_DAO::executeQuery($sql); + $all = array(); + while ($dao->fetch()) { + $all[] = array( + 'contact_id' => $dao->contact_id, + 'contact_type' => $dao->contact_type, + 'household_name' => $dao->sort_name, + ); + } + asort($all); + $this->assertEquals($full, $all); + } + + /** + * Test CRM_Contact_Form_Search_Custom_Sample::contactIDs() + * @dataProvider dataProvider + * @param $fv + * @param $count + * @param $ids + * @param $full + * @throws \Exception + */ + public function testContactIDs($fv, $count, $ids, $full) { + // Truncate affected tables + $this->quickCleanup($this->_tablesToTruncate); + + // echo "testContactIDs\n"; + $op = new PHPUnit_Extensions_Database_Operation_Insert(); + $op->execute($this->_dbconn, + $this->createFlatXMLDataSet( + dirname(__FILE__) . '/datasets/sample-dataset.xml' + ) + ); + $obj = new CRM_Contact_Form_Search_Custom_Sample($fv); + $sql = $obj->contactIDs(); + $this->assertTrue(is_string($sql)); + $dao = CRM_Core_DAO::executeQuery($sql); + $contacts = array(); + while ($dao->fetch()) { + $contacts[$dao->contact_id] = 1; + } + $contacts = array_keys($contacts); + sort($contacts, SORT_NUMERIC); + $this->assertEquals($ids, $contacts); + } + + /** + * Test CRM_Contact_Form_Search_Custom_Group::columns() + * It returns an array of translated name => keys + */ + public function testColumns() { + $formValues = array(); + $obj = new CRM_Contact_Form_Search_Custom_Sample($formValues); + $columns = $obj->columns(); + $this->assertTrue(is_array($columns)); + foreach ($columns as $key => $value) { + $this->assertTrue(is_string($key)); + $this->assertTrue(is_string($value)); + } + } + + /** + * Test CRM_Contact_Form_Search_Custom_Group::from() + * @todo write this test + */ + public function SKIPPED_testFrom() { + } + + /** + * Test CRM_Contact_Form_Search_Custom_Group::summary() + * It returns NULL + */ + public function testSummary() { + $formValues = array(); + $obj = new CRM_Contact_Form_Search_Custom_Group($formValues); + $this->assertNull($obj->summary()); + } + + /** + * Test CRM_Contact_Form_Search_Custom_Sample::templateFile() + * Returns the path to the file as a string + */ + public function testTemplateFile() { + $formValues = array(); + $obj = new CRM_Contact_Form_Search_Custom_Group($formValues); + $fileName = $obj->templateFile(); + $this->assertTrue(is_string($fileName)); + //FIXME: we would need to search the include path to do the following + //$this->assertTrue( file_exists( $fileName ) ); + } + + /** + * Test CRM_Contact_Form_Search_Custom_Sample with saved_search_id + * With true argument it returns list of contact IDs + */ + public function testSavedSearch() { + $this->quickCleanup($this->_tablesToTruncate); + + $op = new PHPUnit_Extensions_Database_Operation_Insert(); + $op->execute($this->_dbconn, + $this->createFlatXMLDataSet( + dirname(__FILE__) . '/datasets/sample-dataset.xml' + ) + ); + + $dataset[1] = array('id' => array(12)); + $dataset[2] = array('id' => array(10, 11)); + + $ssdao = CRM_Core_DAO::executeQuery("SELECT * FROM civicrm_saved_search"); + while ($ssdao->fetch()) { + $fv = CRM_Contact_BAO_SavedSearch::getFormValues($ssdao->id); + $obj = new CRM_Contact_Form_Search_Custom_Sample($fv); + $sql = $obj->contactIDs(); + $this->assertTrue(is_string($sql)); + $dao = CRM_Core_DAO::executeQuery($sql); + $contacts = array(); + while ($dao->fetch()) { + $contacts[] = $dao->contact_id; + } + sort($contacts, SORT_NUMERIC); + $this->assertEquals($dataset[$ssdao->id]['id'], $contacts); + } + } + +} diff --git a/tests/phpunit/CRM/Contact/Form/Search/Custom/SampleTestDataProvider.php b/tests/phpunit/CRM/Contact/Form/Search/Custom/SampleTestDataProvider.php new file mode 100644 index 0000000000..48075109e1 --- /dev/null +++ b/tests/phpunit/CRM/Contact/Form/Search/Custom/SampleTestDataProvider.php @@ -0,0 +1,124 @@ + array('household_name' => 'Household 9'), + 'id' => array( + '9', + ), + ), + // Search by Household name: 'Household' + array( + 'fv' => array('household_name' => 'Household'), + 'id' => array( + '9', + '10', + '11', + '12', + ), + ), + // Search by State: California + array( + 'fv' => array('state_province_id' => '1004'), + 'id' => array( + '10', + '11', + ), + ), + // Search by State: New York + array( + 'fv' => array('state_province_id' => '1031'), + 'id' => array( + '12', + ), + ), + ); + + public function _construct() { + $this->i = 0; + } + + public function rewind() { + $this->i = 0; + } + + /** + * @return array + */ + public function current() { + $count = count($this->dataset[$this->i]['id']); + $ids = $this->dataset[$this->i]['id']; + $full = array(); + foreach ($this->dataset[$this->i]['id'] as $key => $value) { + $full[] = array( + 'contact_id' => $value, + 'contact_type' => 'Household', + 'household_name' => "Household $value", + ); + } + return array($this->dataset[$this->i]['fv'], $count, $ids, $full); + } + + /** + * @return int + */ + public function key() { + return $this->i; + } + + public function next() { + $this->i++; + } + + /** + * @return bool + */ + public function valid() { + return isset($this->dataset[$this->i]); + } + +} diff --git a/tests/phpunit/CRM/Contact/Form/Search/Custom/dataset.xml b/tests/phpunit/CRM/Contact/Form/Search/Custom/datasets/group-dataset.xml similarity index 100% rename from tests/phpunit/CRM/Contact/Form/Search/Custom/dataset.xml rename to tests/phpunit/CRM/Contact/Form/Search/Custom/datasets/group-dataset.xml diff --git a/tests/phpunit/CRM/Contact/Form/Search/Custom/datasets/sample-dataset.xml b/tests/phpunit/CRM/Contact/Form/Search/Custom/datasets/sample-dataset.xml new file mode 100644 index 0000000000..114272ef63 --- /dev/null +++ b/tests/phpunit/CRM/Contact/Form/Search/Custom/datasets/sample-dataset.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + -- 2.25.1