CRM-12845 - CRM_Utils_Migrate_Import - Add test
authorTim Otten <totten@civicrm.org>
Sun, 18 Aug 2013 03:45:49 +0000 (20:45 -0700)
committerTim Otten <totten@civicrm.org>
Sun, 18 Aug 2013 03:50:15 +0000 (20:50 -0700)
----------------------------------------
* CRM-12845: CRM_Utils_Migrate - Handle CustomGroup subtypes
  http://issues.civicrm.org/jira/browse/CRM-12845

tests/phpunit/CRM/Utils/Migrate/ExportTest.php
tests/phpunit/CRM/Utils/Migrate/fixtures/Activity-text.xml
tests/phpunit/CRM/Utils/Migrate/fixtures/ActivityMeeting-text.xml
tests/phpunit/CRM/Utils/Migrate/fixtures/Contact-select.xml
tests/phpunit/CRM/Utils/Migrate/fixtures/Contact-text.xml
tests/phpunit/CRM/Utils/Migrate/fixtures/Individual-text.xml
tests/phpunit/CRM/Utils/Migrate/fixtures/IndividualStudent-text.xml

index 83727c71b0b07a25d54311777cbb31c19a09944b..dddc2d2d82d9a0530de76c9affaef87caa55f705 100644 (file)
@@ -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
index 7f6aa8ce2bacf08e6670393ddfb13ff2ebbbf5ea..d5efc4e231ada2e712dd24751885927c3fe30c0e 100644 (file)
@@ -3,8 +3,8 @@
 <CustomData>
   <CustomGroups>
     <CustomGroup>
-      <name>activ_text_ex</name>
-      <title>activ_text_ex</title>
+      <name>example</name>
+      <title>example</title>
       <extends>Activity</extends>
       <style>Inline</style>
       <collapse_display>0</collapse_display>
@@ -12,7 +12,7 @@
       <help_post></help_post>
       <weight>1</weight>
       <is_active>1</is_active>
-      <table_name>civicrm_value_activ_text_ex_1</table_name>
+      <table_name>civicrm_value_example_1</table_name>
       <is_multiple>0</is_multiple>
       <collapse_adv_display>0</collapse_adv_display>
       <is_reserved>0</is_reserved>
@@ -32,7 +32,7 @@
       <is_active>1</is_active>
       <is_view>0</is_view>
       <column_name>name1_1</column_name>
-      <custom_group_name>activ_text_ex</custom_group_name>
+      <custom_group_name>example</custom_group_name>
     </CustomField>
   </CustomFields>
 </CustomData>
index 3f18a7ce4ba27b52b87de6abb270fa7d6e5cf4eb..f32c3c117fade6a61bbb5407bc7d1b0c4e446051 100644 (file)
@@ -3,8 +3,8 @@
 <CustomData>
   <CustomGroups>
     <CustomGroup>
-      <name>activ_text_ex</name>
-      <title>activ_text_ex</title>
+      <name>example</name>
+      <title>example</title>
       <extends>Activity</extends>
       <extends_entity_column_value_option_group>activity_type</extends_entity_column_value_option_group>
       <extends_entity_column_value>Meeting</extends_entity_column_value>
@@ -14,7 +14,7 @@
       <help_post></help_post>
       <weight>1</weight>
       <is_active>1</is_active>
-      <table_name>civicrm_value_activ_text_ex_1</table_name>
+      <table_name>civicrm_value_example_1</table_name>
       <is_multiple>0</is_multiple>
       <collapse_adv_display>0</collapse_adv_display>
       <is_reserved>0</is_reserved>
@@ -34,7 +34,7 @@
       <is_active>1</is_active>
       <is_view>0</is_view>
       <column_name>name1_1</column_name>
-      <custom_group_name>activ_text_ex</custom_group_name>
+      <custom_group_name>example</custom_group_name>
     </CustomField>
   </CustomFields>
 </CustomData>
index 339e23087670f2c6abbfbc7fd4d1132f28669a71..621e338d881e0ae63f80cdacd7ab45de31d4b1d9 100644 (file)
@@ -3,8 +3,8 @@
 <CustomData>
   <CustomGroups>
     <CustomGroup>
-      <name>contact_selec</name>
-      <title>contact_selec</title>
+      <name>example</name>
+      <title>example</title>
       <extends>Contact</extends>
       <style>Inline</style>
       <collapse_display>0</collapse_display>
@@ -12,7 +12,7 @@
       <help_post></help_post>
       <weight>1</weight>
       <is_active>1</is_active>
-      <table_name>civicrm_value_contact_selec_1</table_name>
+      <table_name>civicrm_value_example_1</table_name>
       <is_multiple>0</is_multiple>
       <collapse_adv_display>0</collapse_adv_display>
       <is_reserved>0</is_reserved>
@@ -32,7 +32,7 @@
       <is_view>0</is_view>
       <column_name>our_select_field_1</column_name>
       <option_group_name>our_select_field_20130818044104</option_group_name>
-      <custom_group_name>contact_selec</custom_group_name>
+      <custom_group_name>example</custom_group_name>
     </CustomField>
   </CustomFields>
   <OptionGroups>
index 3ed01bab0684dd79aa6e587b2741ab6defe85561..f78472ff52d24da32a33b1d886e4730b49533e30 100644 (file)
@@ -3,8 +3,8 @@
 <CustomData>
   <CustomGroups>
     <CustomGroup>
-      <name>contact_text_</name>
-      <title>contact_text_</title>
+      <name>example</name>
+      <title>example</title>
       <extends>Contact</extends>
       <style>Inline</style>
       <collapse_display>0</collapse_display>
@@ -12,7 +12,7 @@
       <help_post></help_post>
       <weight>1</weight>
       <is_active>1</is_active>
-      <table_name>civicrm_value_contact_text__1</table_name>
+      <table_name>civicrm_value_example_1</table_name>
       <is_multiple>0</is_multiple>
       <collapse_adv_display>0</collapse_adv_display>
       <is_reserved>0</is_reserved>
@@ -32,7 +32,7 @@
       <is_active>1</is_active>
       <is_view>0</is_view>
       <column_name>name1_1</column_name>
-      <custom_group_name>contact_text_</custom_group_name>
+      <custom_group_name>example</custom_group_name>
     </CustomField>
   </CustomFields>
 </CustomData>
index 019131bdf744f5f5b2e03dae27045c4e62680430..e656f28c47912fdc6c3ed6a59cb8e6bfa94061a2 100644 (file)
@@ -3,8 +3,8 @@
 <CustomData>
   <CustomGroups>
     <CustomGroup>
-      <name>indiv_text_ex</name>
-      <title>indiv_text_ex</title>
+      <name>example</name>
+      <title>example</title>
       <extends>Individual</extends>
       <style>Inline</style>
       <collapse_display>0</collapse_display>
@@ -12,7 +12,7 @@
       <help_post></help_post>
       <weight>1</weight>
       <is_active>1</is_active>
-      <table_name>civicrm_value_indiv_text_ex_1</table_name>
+      <table_name>civicrm_value_example_1</table_name>
       <is_multiple>0</is_multiple>
       <collapse_adv_display>0</collapse_adv_display>
       <is_reserved>0</is_reserved>
@@ -32,7 +32,7 @@
       <is_active>1</is_active>
       <is_view>0</is_view>
       <column_name>name1_1</column_name>
-      <custom_group_name>indiv_text_ex</custom_group_name>
+      <custom_group_name>example</custom_group_name>
     </CustomField>
   </CustomFields>
 </CustomData>
index 5841cf78cc2dfd3fd6bca8dc5e67537b0ab386fa..0a4c15807c94319e67a178f5625aeeb2f925dc2e 100644 (file)
@@ -3,8 +3,8 @@
 <CustomData>
   <CustomGroups>
     <CustomGroup>
-      <name>indiv_text_ex</name>
-      <title>indiv_text_ex</title>
+      <name>example</name>
+      <title>example</title>
       <extends>Individual</extends>
       <extends_entity_column_value_option_group>contact_type</extends_entity_column_value_option_group>
       <extends_entity_column_value>Student</extends_entity_column_value>
@@ -14,7 +14,7 @@
       <help_post></help_post>
       <weight>1</weight>
       <is_active>1</is_active>
-      <table_name>civicrm_value_indiv_text_ex_1</table_name>
+      <table_name>civicrm_value_example_1</table_name>
       <is_multiple>0</is_multiple>
       <collapse_adv_display>0</collapse_adv_display>
       <is_reserved>0</is_reserved>
@@ -34,7 +34,7 @@
       <is_active>1</is_active>
       <is_view>0</is_view>
       <column_name>name1_1</column_name>
-      <custom_group_name>indiv_text_ex</custom_group_name>
+      <custom_group_name>example</custom_group_name>
     </CustomField>
   </CustomFields>
 </CustomData>