From 0f882f9b5041593b92af97c55cb217c92bf92b4b Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sat, 17 Aug 2013 20:45:49 -0700 Subject: [PATCH] CRM-12845 - CRM_Utils_Migrate_Import - Add test ---------------------------------------- * CRM-12845: CRM_Utils_Migrate - Handle CustomGroup subtypes http://issues.civicrm.org/jira/browse/CRM-12845 --- .../phpunit/CRM/Utils/Migrate/ExportTest.php | 52 +++++++++++++++---- .../Utils/Migrate/fixtures/Activity-text.xml | 8 +-- .../Migrate/fixtures/ActivityMeeting-text.xml | 8 +-- .../Utils/Migrate/fixtures/Contact-select.xml | 8 +-- .../Utils/Migrate/fixtures/Contact-text.xml | 8 +-- .../Migrate/fixtures/Individual-text.xml | 8 +-- .../fixtures/IndividualStudent-text.xml | 8 +-- 7 files changed, 67 insertions(+), 33 deletions(-) diff --git a/tests/phpunit/CRM/Utils/Migrate/ExportTest.php b/tests/phpunit/CRM/Utils/Migrate/ExportTest.php index 83727c71b0..dddc2d2d82 100644 --- a/tests/phpunit/CRM/Utils/Migrate/ExportTest.php +++ b/tests/phpunit/CRM/Utils/Migrate/ExportTest.php @@ -20,7 +20,9 @@ class CRM_Utils_Migrate_ExportTest extends CiviUnitTestCase { /** * Generate a list of basic XML test cases. Each test case creates a * custom-group and custom-field then compares the output to a pre-defined - * XML file. + * XML file. Then, for each test-case, we reverse the process -- we + * load the XML into a clean DB and see if it creates matching custom-group + * and custom-field. */ function basicXmlTestCases() { // a small library which we use to describe test cases @@ -69,7 +71,7 @@ class CRM_Utils_Migrate_ExportTest extends CiviUnitTestCase { // CustomGroup params array( 'extends' => 'Contact', - 'title' => 'contact_text_example', + 'title' => 'example', ), // CustomField params $fixtures['textField'], @@ -82,7 +84,7 @@ class CRM_Utils_Migrate_ExportTest extends CiviUnitTestCase { // CustomGroup params array( 'extends' => 'Contact', - 'title' => 'contact_select_example', + 'title' => 'example', ), // CustomField params $fixtures['selectField'], @@ -95,7 +97,7 @@ class CRM_Utils_Migrate_ExportTest extends CiviUnitTestCase { // CustomGroup params array( 'extends' => 'Individual', - 'title' => 'indiv_text_example', + 'title' => 'example', ), // CustomField params $fixtures['textField'], @@ -107,8 +109,8 @@ class CRM_Utils_Migrate_ExportTest extends CiviUnitTestCase { // CustomGroup params array( 'extends' => 'Individual', - 'extends_entity_column_value' => 'Student', - 'title' => 'indiv_text_example', + 'extends_entity_column_value' => array('Student'), + 'title' => 'example', ), // CustomField params $fixtures['textField'], @@ -120,7 +122,7 @@ class CRM_Utils_Migrate_ExportTest extends CiviUnitTestCase { // CustomGroup params array( 'extends' => 'Activity', - 'title' => 'activ_text_example', + 'title' => 'example', ), // CustomField params $fixtures['textField'], @@ -132,8 +134,8 @@ class CRM_Utils_Migrate_ExportTest extends CiviUnitTestCase { // CustomGroup params array( 'extends' => 'Activity', - 'extends_entity_column_value' => array_search('Meeting', CRM_Core_PseudoConstant::activityType()), - 'title' => 'activ_text_example', + 'extends_entity_column_value' => array(array_search('Meeting', CRM_Core_PseudoConstant::activityType())), + 'title' => 'example', ), // CustomField params $fixtures['textField'], @@ -154,6 +156,9 @@ class CRM_Utils_Migrate_ExportTest extends CiviUnitTestCase { * @dataProvider basicXmlTestCases */ function testBasicXMLExports($customGroupParams, $fieldParams, $expectedXmlFilePath) { + $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_custom_group WHERE title = %1', array( + 1 => array($customGroupParams['title'], 'String') + )); $customGroup = $this->customGroupCreate($customGroupParams); $fieldParams['custom_group_id'] = $customGroup['id']; $customField = $this->callAPISuccess('custom_field', 'create', $fieldParams); @@ -166,4 +171,33 @@ class CRM_Utils_Migrate_ExportTest extends CiviUnitTestCase { $this->callAPISuccess('custom_field', 'delete', array('id' => $customField['id'])); $this->callAPISuccess('custom_group', 'delete', array('id' => $customGroup['id'])); } + + /** + * @param $customGroupParams + * @param $fieldParams + * @param $expectedXmlFilePath + * @dataProvider basicXmlTestCases + */ + function testBasicXMLImports($expectCustomGroup, $expectCustomField, $inputXmlFilePath) { + $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_custom_group WHERE title = %1', array( + 1 => array($expectCustomGroup['title'], 'String') + )); + + $importer = new CRM_Utils_Migrate_Import(); + $importer->run($inputXmlFilePath); + + $customGroups = $this->callAPISuccess('custom_group', 'get', array('title' => $expectCustomGroup['title'])); + $this->assertEquals(1, $customGroups['count']); + $customGroup = array_shift($customGroups['values']); + foreach ($expectCustomGroup as $expectKey => $expectValue) { + $this->assertEquals($expectValue, $customGroup[$expectKey]); + } + + $customFields = $this->callAPISuccess('custom_field', 'get', array('label' => $expectCustomField['label'])); + $this->assertEquals(1, $customFields['count']); + $customField = array_shift($customFields['values']); + foreach ($expectCustomField as $expectKey => $expectValue) { + $this->assertEquals($expectValue, $customField[$expectKey]); + } + } } \ No newline at end of file diff --git a/tests/phpunit/CRM/Utils/Migrate/fixtures/Activity-text.xml b/tests/phpunit/CRM/Utils/Migrate/fixtures/Activity-text.xml index 7f6aa8ce2b..d5efc4e231 100644 --- a/tests/phpunit/CRM/Utils/Migrate/fixtures/Activity-text.xml +++ b/tests/phpunit/CRM/Utils/Migrate/fixtures/Activity-text.xml @@ -3,8 +3,8 @@ - activ_text_ex - activ_text_ex + example + example Activity 0 @@ -12,7 +12,7 @@ 1 1 - civicrm_value_activ_text_ex_1 + civicrm_value_example_1 0 0 0 @@ -32,7 +32,7 @@ 1 0 name1_1 - activ_text_ex + example diff --git a/tests/phpunit/CRM/Utils/Migrate/fixtures/ActivityMeeting-text.xml b/tests/phpunit/CRM/Utils/Migrate/fixtures/ActivityMeeting-text.xml index 3f18a7ce4b..f32c3c117f 100644 --- a/tests/phpunit/CRM/Utils/Migrate/fixtures/ActivityMeeting-text.xml +++ b/tests/phpunit/CRM/Utils/Migrate/fixtures/ActivityMeeting-text.xml @@ -3,8 +3,8 @@ - activ_text_ex - activ_text_ex + example + example Activity activity_type Meeting @@ -14,7 +14,7 @@ 1 1 - civicrm_value_activ_text_ex_1 + civicrm_value_example_1 0 0 0 @@ -34,7 +34,7 @@ 1 0 name1_1 - activ_text_ex + example diff --git a/tests/phpunit/CRM/Utils/Migrate/fixtures/Contact-select.xml b/tests/phpunit/CRM/Utils/Migrate/fixtures/Contact-select.xml index 339e230876..621e338d88 100644 --- a/tests/phpunit/CRM/Utils/Migrate/fixtures/Contact-select.xml +++ b/tests/phpunit/CRM/Utils/Migrate/fixtures/Contact-select.xml @@ -3,8 +3,8 @@ - contact_selec - contact_selec + example + example Contact 0 @@ -12,7 +12,7 @@ 1 1 - civicrm_value_contact_selec_1 + civicrm_value_example_1 0 0 0 @@ -32,7 +32,7 @@ 0 our_select_field_1 our_select_field_20130818044104 - contact_selec + example diff --git a/tests/phpunit/CRM/Utils/Migrate/fixtures/Contact-text.xml b/tests/phpunit/CRM/Utils/Migrate/fixtures/Contact-text.xml index 3ed01bab06..f78472ff52 100644 --- a/tests/phpunit/CRM/Utils/Migrate/fixtures/Contact-text.xml +++ b/tests/phpunit/CRM/Utils/Migrate/fixtures/Contact-text.xml @@ -3,8 +3,8 @@ - contact_text_ - contact_text_ + example + example Contact 0 @@ -12,7 +12,7 @@ 1 1 - civicrm_value_contact_text__1 + civicrm_value_example_1 0 0 0 @@ -32,7 +32,7 @@ 1 0 name1_1 - contact_text_ + example diff --git a/tests/phpunit/CRM/Utils/Migrate/fixtures/Individual-text.xml b/tests/phpunit/CRM/Utils/Migrate/fixtures/Individual-text.xml index 019131bdf7..e656f28c47 100644 --- a/tests/phpunit/CRM/Utils/Migrate/fixtures/Individual-text.xml +++ b/tests/phpunit/CRM/Utils/Migrate/fixtures/Individual-text.xml @@ -3,8 +3,8 @@ - indiv_text_ex - indiv_text_ex + example + example Individual 0 @@ -12,7 +12,7 @@ 1 1 - civicrm_value_indiv_text_ex_1 + civicrm_value_example_1 0 0 0 @@ -32,7 +32,7 @@ 1 0 name1_1 - indiv_text_ex + example diff --git a/tests/phpunit/CRM/Utils/Migrate/fixtures/IndividualStudent-text.xml b/tests/phpunit/CRM/Utils/Migrate/fixtures/IndividualStudent-text.xml index 5841cf78cc..0a4c15807c 100644 --- a/tests/phpunit/CRM/Utils/Migrate/fixtures/IndividualStudent-text.xml +++ b/tests/phpunit/CRM/Utils/Migrate/fixtures/IndividualStudent-text.xml @@ -3,8 +3,8 @@ - indiv_text_ex - indiv_text_ex + example + example Individual contact_type Student @@ -14,7 +14,7 @@ 1 1 - civicrm_value_indiv_text_ex_1 + civicrm_value_example_1 0 0 0 @@ -34,7 +34,7 @@ 1 0 name1_1 - indiv_text_ex + example -- 2.25.1