Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-18048: keep civicrm_value table names to a minimum length to avoid report errors #11183

Merged
merged 1 commit into from
Jan 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CRM/Core/BAO/CustomGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public static function create(&$params) {
$group->save();
if (!isset($params['id'])) {
if (!isset($params['table_name'])) {
$munged_title = strtolower(CRM_Utils_String::munge($group->title, '_', 42));
$munged_title = strtolower(CRM_Utils_String::munge($group->title, '_', 13));
$tableName = "civicrm_value_{$munged_title}_{$group->id}";
}
$group->table_name = $tableName;
Expand Down
85 changes: 85 additions & 0 deletions tests/phpunit/CRM/Report/Form/ActivityTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
* Test Activity report outcome
*
* @package CiviCRM
*/
class CRM_Report_Form_ActivityTest extends CiviReportTestCase {
protected $_tablesToTruncate = array(
'civicrm_contact',
'civicrm_email',
'civicrm_phone',
'civicrm_address',
'civicrm_contribution',
);

public function setUp() {
parent::setUp();
$this->quickCleanup($this->_tablesToTruncate);
}

public function tearDown() {
parent::tearDown();
CRM_Core_DAO::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp1');
CRM_Core_DAO::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp2');
CRM_Core_DAO::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp3');
}

/**
* Ensure long custom field names don't result in errors.
*/
public function testLongCustomFieldNames() {
// Create custom group with long name and custom field with long name.
$long_name = 'this is a very very very very long name with 65 characters in it';
$group_params = array(
'title' => $long_name,
'extends' => 'Activity',
);
$result = $this->customGroupCreate($group_params);
$custom_group_id = $result['id'];
$field_params = array(
'custom_group_id' => $custom_group_id,
'label' => $long_name,
);
$result = $this->customFieldCreate($field_params);
$custom_field_id = $result['id'];
$input = array(
'fields' => array(
'custom_' . $custom_field_id,
),
);
$obj = $this->getReportObject('CRM_Report_Form_Activity', $input);
//$params = $obj->_params;
//$params['fields'] = array('custom_' . $custom_field_id);
//$obj->setParams($params);
$obj->getResultSet();
$this->assertTrue(TRUE, "Testo");
}

}
29 changes: 23 additions & 6 deletions tests/phpunit/CiviTest/CiviReportTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ public function tearDown() {
* @throws Exception
*/
public function getReportOutputAsCsv($reportClass, $inputParams) {

$reportObj = $this->getReportObject($reportClass, $inputParams);
try {
$rows = $reportObj->getResultSet();
$tmpFile = $this->createTempDir() . CRM_Utils_File::makeFileName('CiviReport.csv');
$csvContent = CRM_Report_Utils_Report::makeCsv($reportObj, $rows);
file_put_contents($tmpFile, $csvContent);
}
catch (Exception $e) {
throw $e;
}
return $tmpFile;
}

/**
* @param $reportClass
* @param array $inputParams
*
* @return array
* @throws Exception
*/
public function getReportObject($reportClass, $inputParams) {
$config = CRM_Core_Config::singleton();
$config->keyDisable = TRUE;
$controller = new CRM_Core_Controller_Simple($reportClass, ts('some title'));
Expand Down Expand Up @@ -83,11 +105,6 @@ public function getReportOutputAsCsv($reportClass, $inputParams) {
try {
$reportObj->storeResultSet();
$reportObj->buildForm();
$rows = $reportObj->getResultSet();

$tmpFile = $this->createTempDir() . CRM_Utils_File::makeFileName('CiviReport.csv');
$csvContent = CRM_Report_Utils_Report::makeCsv($reportObj, $rows);
file_put_contents($tmpFile, $csvContent);
}
catch (Exception $e) {
// print_r($e->getCause()->getUserInfo());
Expand All @@ -96,7 +113,7 @@ public function getReportOutputAsCsv($reportClass, $inputParams) {
}
CRM_Utils_GlobalStack::singleton()->pop();

return $tmpFile;
return $reportObj;
}

/**
Expand Down
4 changes: 0 additions & 4 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2074,10 +2074,6 @@ public function customGroupCreate($params = array()) {

$params = array_merge($defaults, $params);

if (strlen($params['title']) > 13) {
$params['title'] = substr($params['title'], 0, 13);
}

//have a crack @ deleting it first in the hope this will prevent derailing our tests
$this->callAPISuccess('custom_group', 'get', array(
'title' => $params['title'],
Expand Down