From: monishdeb Date: Tue, 8 Sep 2015 11:19:12 +0000 (+0530) Subject: 4.6 Test Failure fix X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=872a35c1b074d47e3a75ca404b1df0232eb196a6;p=civicrm-core.git 4.6 Test Failure fix --- diff --git a/tests/phpunit/CRM/Financial/Page/AjaxTest.php b/tests/phpunit/CRM/Financial/Page/AjaxTest.php index 42a5b6c508..d7b64e92b4 100644 --- a/tests/phpunit/CRM/Financial/Page/AjaxTest.php +++ b/tests/phpunit/CRM/Financial/Page/AjaxTest.php @@ -48,7 +48,7 @@ class CRM_Financial_Page_AjaxTest extends CiviUnitTestCase { $_REQUEST['entityID'] = $batch['id']; $json = CRM_Financial_Page_AJAX::getFinancialTransactionsList(TRUE); $this->assertEquals($json, '{"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["","","Anderson, Anthony","$ 100.00","12345","September 3rd, 2015 12:00 AM",' + . ' class=\"icon crm-icon Individual-icon\">","Anderson, Anthony","$ 100.00","12345","' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM",' . '"Credit Card","Completed","Donation","View"]] }'); } diff --git a/tests/phpunit/api/v3/CustomValueTest.php b/tests/phpunit/api/v3/CustomValueTest.php index 1997b9547e..05dde076c5 100644 --- a/tests/phpunit/api/v3/CustomValueTest.php +++ b/tests/phpunit/api/v3/CustomValueTest.php @@ -46,10 +46,11 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { 'integer' => array(1, 2, 3), 'number' => array(10.11, 20.22, 30.33), 'string' => array(substr(sha1(rand()), 0, 4), substr(sha1(rand()), 0, 3), substr(sha1(rand()), 0, 2)), - //'country' => array_rand(CRM_Core_PseudoConstant::country(FALSE, FALSE), 3), + 'country' => array_rand(CRM_Core_PseudoConstant::country(FALSE, FALSE), 3), 'state_province' => array_rand(CRM_Core_PseudoConstant::stateProvince(FALSE, FALSE), 3), 'date' => NULL, 'contact' => NULL, + 'boolean' => NULL, ); $dataValues = !empty($type) ? array($type => $dataValues[$type]) : $dataValues; @@ -108,19 +109,30 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { foreach ($customFieldDataType as $dataType => $label) { switch ($dataType) { - case 'Date': - case 'StateProvince'; case 'String': case 'Link': case 'Int': case 'Float': case 'Money': + case 'Date': + case 'Country': + case 'StateProvince': + case 'Boolean': + + //Based on the custom field data-type choose desired SQL operators(to test with) and basic $type if (in_array($dataType, array('String', 'Link'))) { - $validSQLOperator = array('=', '!=', 'IN', 'NOT IN', 'LIKE', 'NOT LIKE', 'IS NOT NULL', 'IS NULL'); + $validSQLOperators = array('=', '!=', 'IN', 'NOT IN', 'LIKE', 'NOT LIKE', 'IS NOT NULL', 'IS NULL'); $type = 'string'; } + elseif ($dataType == 'Boolean') { + $validSQLOperators = array('=', '!=', 'IS NOT NULL', 'IS NULL'); + $type = 'boolean'; + } else { - if ($dataType == 'StateProvince') { + if ($dataType == 'Country') { + $type = 'country'; + } + elseif ($dataType == 'StateProvince') { $type = 'state_province'; } elseif ($dataType == 'ContactReference') { @@ -132,9 +144,10 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { else { $type = $dataType == 'Int' ? 'integer' : 'number'; } - $validSQLOperator = array('=', '!=', 'IN', 'NOT IN', '<=', '>=', '>', '<', 'IS NOT NULL', 'IS NULL'); + $validSQLOperators = array('=', '!=', 'IN', 'NOT IN', '<=', '>=', '>', '<', 'IS NOT NULL', 'IS NULL'); } + //Create custom field of $dataType and html-type $html foreach ($dataToHtmlTypes[$count] as $html) { $params = array( 'custom_group_id' => $this->ids[$type]['custom_group_id'], @@ -143,17 +156,18 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { 'html_type' => $html, 'default_value' => NULL, ); - if (!in_array($html, array('Text', 'TextArea')) && !in_array($dataType, array('Link', 'Date', 'ContactReference'))) { + if (!in_array($html, array('Text', 'TextArea')) && !in_array($dataType, array('Link', 'Date', 'ContactReference', 'Boolean'))) { $params += array('option_group_id' => $this->optionGroup[$type]['id']); } $customField = $this->customFieldCreate($params); - $this->_testCustomValue($customField['values'][$customField['id']], $validSQLOperator, $type); + //Now test with $validSQLOperator SQL operators against its custom value(s) + $this->_testCustomValue($customField['values'][$customField['id']], $validSQLOperators, $type); } $count++; break; default: - //TODO: Test case of Country fields remain as it throws foreign key contraint ONLY in test environment + // skipping File data-type $count++; break; } @@ -190,6 +204,10 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { $selectedValue = $this->optionGroup[$type]['values'][1]; $notselectedValue = $this->optionGroup[$type]['values'][0]; } + elseif ($type == 'boolean') { + $selectedValue = 1; + $notselectedValue = 0; + } else { $selectedValue = $this->optionGroup[$type]['values'][0]; $notselectedValue = $this->optionGroup[$type]['values'][$count]; @@ -204,18 +222,15 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { foreach ($sqlOps as $op) { $qillOp = CRM_Utils_Array::value($op, CRM_Core_SelectValues::getSearchBuilderOperators(), $op); - $description = "\nFind Contact where '$customField[label]' $qillOp "; switch ($op) { case '=': $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => (is_array($selectedValue) ? implode(CRM_Core_DAO::VALUE_SEPARATOR, $selectedValue) : $selectedValue))); $this->assertEquals($contactId, $result['id']); - echo $description . implode("[separator]", (array) $selectedValue); break; case '!=': $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => $notselectedValue))); $this->assertEquals(TRUE, array_key_exists($contactId, $result['values'])); - echo $description . $notselectedValue; break; case '>': @@ -234,12 +249,10 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { if ($op == '>') { $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => $lesserSelectedValue))); $this->assertEquals($contactId, $result['id']); - echo $description . $lesserSelectedValue; } elseif ($op == '<') { $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => $selectedValue))); $this->assertEquals($contactId2, $result['id']); - echo $description . $selectedValue; } else { $result = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'email' => substr(sha1(rand()), 0, 7) . 'man3@yahoo.com')); @@ -247,7 +260,6 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { $this->callAPISuccess('CustomValue', 'create', array('entity_id' => $contactId3, 'custom_' . $customId => $greaterSelectedValue)); $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => $selectedValue))); - echo $description . $selectedValue; $this->assertEquals($contactId, $result['values'][$contactId]['id']); if ($op == '>=') { @@ -265,38 +277,32 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { case 'IN': $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => (array) $selectedValue))); $this->assertEquals($contactId, $result['id']); - echo $description . implode(",", (array) $selectedValue); break; case 'NOT IN': $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => (array) $notselectedValue))); $this->assertEquals($contactId, $result['id']); - echo $description . implode(",", (array) $notselectedValue); break; case 'LIKE': $selectedValue = is_array($selectedValue) ? $selectedValue[0] : $selectedValue; $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => "%$selectedValue%"))); $this->assertEquals($contactId, $result['id']); - echo $description . "%$selectedValue%"; break; case 'NOT LIKE': $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => $notselectedValue))); $this->assertEquals($contactId, $result['id']); - echo $description . "'$notselectedValue'"; break; case 'IS NULL': $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => 1))); $this->assertEquals(FALSE, array_key_exists($contactId, $result['values'])); - echo $description; break; case 'IS NOT NULL': $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => 1))); $this->assertEquals($contactId, $result['id']); - echo $description; break; } }