From eac4fc12dc3e674d8a48b78878461301a3dfff20 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sat, 17 Aug 2013 19:55:39 -0700 Subject: [PATCH] CRM-12845 - CRM_Utils_Migrate_Export - Add test ---------------------------------------- * CRM-12845: CRM_Utils_Migrate - Handle CustomGroup subtypes http://issues.civicrm.org/jira/browse/CRM-12845 --- .../phpunit/CRM/Utils/Migrate/ExportTest.php | 169 ++++++++++++++++++ .../Utils/Migrate/fixtures/Activity-text.xml | 38 ++++ .../Migrate/fixtures/ActivityMeeting-text.xml | 40 +++++ .../Utils/Migrate/fixtures/Contact-select.xml | 70 ++++++++ .../Utils/Migrate/fixtures/Contact-text.xml | 38 ++++ .../Migrate/fixtures/Individual-text.xml | 38 ++++ .../fixtures/IndividualStudent-text.xml | 40 +++++ 7 files changed, 433 insertions(+) create mode 100644 tests/phpunit/CRM/Utils/Migrate/ExportTest.php create mode 100644 tests/phpunit/CRM/Utils/Migrate/fixtures/Activity-text.xml create mode 100644 tests/phpunit/CRM/Utils/Migrate/fixtures/ActivityMeeting-text.xml create mode 100644 tests/phpunit/CRM/Utils/Migrate/fixtures/Contact-select.xml create mode 100644 tests/phpunit/CRM/Utils/Migrate/fixtures/Contact-text.xml create mode 100644 tests/phpunit/CRM/Utils/Migrate/fixtures/Individual-text.xml create mode 100644 tests/phpunit/CRM/Utils/Migrate/fixtures/IndividualStudent-text.xml diff --git a/tests/phpunit/CRM/Utils/Migrate/ExportTest.php b/tests/phpunit/CRM/Utils/Migrate/ExportTest.php new file mode 100644 index 0000000000..83727c71b0 --- /dev/null +++ b/tests/phpunit/CRM/Utils/Migrate/ExportTest.php @@ -0,0 +1,169 @@ +_apiversion = 3; + parent::setUp(); + } + + function tearDown() { + $tablesToTruncate = array( + 'civicrm_custom_group', + 'civicrm_custom_field', + ); + $this->quickCleanup($tablesToTruncate, TRUE); + } + + /** + * 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. + */ + function basicXmlTestCases() { + // a small library which we use to describe test cases + $fixtures = array(); + $fixtures['textField'] = array( + 'name' => 'test_textfield', + 'label' => 'Name1', + 'html_type' => 'Text', + 'data_type' => 'String', + 'default_value' => 'abc', + 'weight' => 4, + 'is_required' => 1, + 'is_searchable' => 0, + 'is_active' => 1, + ); + $fixtures['selectField'] = array( + // custom_group_id + 'label' => 'Our select field', + 'html_type' => 'Select', + 'data_type' => 'String', + 'weight' => 4, + 'is_required' => 1, + 'is_searchable' => 0, + 'is_active' => 1, + // 'option_group_name' => 'our_select_field_20130818044104', + 'option_values' => array( + array( + 'weight' => 1, + 'label' => 'Label1', + 'value' => 1, + 'is_active' => 1, + ), + array( + 'weight' => 2, + 'label' => 'Label2', + 'value' => 2, + 'is_active' => 1, + ), + ), + ); + + // the actual test cases + $cases = array(); + + $cases[] = array( + // CustomGroup params + array( + 'extends' => 'Contact', + 'title' => 'contact_text_example', + ), + // CustomField params + $fixtures['textField'], + // expectedXmlFilePath + __DIR__ . '/fixtures/Contact-text.xml', + ); + + /* + $cases[] = array( + // CustomGroup params + array( + 'extends' => 'Contact', + 'title' => 'contact_select_example', + ), + // CustomField params + $fixtures['selectField'], + // expectedXmlFilePath + __DIR__ . '/fixtures/Contact-select.xml', + ); + */ + + $cases[] = array( + // CustomGroup params + array( + 'extends' => 'Individual', + 'title' => 'indiv_text_example', + ), + // CustomField params + $fixtures['textField'], + // expectedXmlFilePath + __DIR__ . '/fixtures/Individual-text.xml', + ); + + $cases[] = array( + // CustomGroup params + array( + 'extends' => 'Individual', + 'extends_entity_column_value' => 'Student', + 'title' => 'indiv_text_example', + ), + // CustomField params + $fixtures['textField'], + // expectedXmlFilePath + __DIR__ . '/fixtures/IndividualStudent-text.xml', + ); + + $cases[] = array( + // CustomGroup params + array( + 'extends' => 'Activity', + 'title' => 'activ_text_example', + ), + // CustomField params + $fixtures['textField'], + // expectedXmlFilePath + __DIR__ . '/fixtures/Activity-text.xml', + ); + + $cases[] = array( + // CustomGroup params + array( + 'extends' => 'Activity', + 'extends_entity_column_value' => array_search('Meeting', CRM_Core_PseudoConstant::activityType()), + 'title' => 'activ_text_example', + ), + // CustomField params + $fixtures['textField'], + // expectedXmlFilePath + __DIR__ . '/fixtures/ActivityMeeting-text.xml', + ); + + return $cases; + } + + /** + * Execute a basic XML test case. Each test case creates a custom-group and + * custom-field then compares the output to a pre-defined XML file. + * + * @param $customGroupParams + * @param $fieldParams + * @param $expectedXmlFilePath + * @dataProvider basicXmlTestCases + */ + function testBasicXMLExports($customGroupParams, $fieldParams, $expectedXmlFilePath) { + $customGroup = $this->customGroupCreate($customGroupParams); + $fieldParams['custom_group_id'] = $customGroup['id']; + $customField = $this->callAPISuccess('custom_field', 'create', $fieldParams); + + $exporter = new CRM_Utils_Migrate_Export(); + $exporter->buildCustomGroups(array($customGroup['id'])); + // print $exporter->toXML(); + $this->assertEquals(file_get_contents($expectedXmlFilePath), $exporter->toXML()); + + $this->callAPISuccess('custom_field', 'delete', array('id' => $customField['id'])); + $this->callAPISuccess('custom_group', 'delete', array('id' => $customGroup['id'])); + } +} \ 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 new file mode 100644 index 0000000000..7f6aa8ce2b --- /dev/null +++ b/tests/phpunit/CRM/Utils/Migrate/fixtures/Activity-text.xml @@ -0,0 +1,38 @@ + + + + + + activ_text_ex + activ_text_ex + Activity + + 0 + + + 1 + 1 + civicrm_value_activ_text_ex_1 + 0 + 0 + 0 + + + + + test_textfield + + String + Text + abc + 1 + 0 + 0 + 4 + 1 + 0 + name1_1 + activ_text_ex + + + diff --git a/tests/phpunit/CRM/Utils/Migrate/fixtures/ActivityMeeting-text.xml b/tests/phpunit/CRM/Utils/Migrate/fixtures/ActivityMeeting-text.xml new file mode 100644 index 0000000000..3f18a7ce4b --- /dev/null +++ b/tests/phpunit/CRM/Utils/Migrate/fixtures/ActivityMeeting-text.xml @@ -0,0 +1,40 @@ + + + + + + activ_text_ex + activ_text_ex + Activity + activity_type + Meeting + + 0 + + + 1 + 1 + civicrm_value_activ_text_ex_1 + 0 + 0 + 0 + + + + + test_textfield + + String + Text + abc + 1 + 0 + 0 + 4 + 1 + 0 + name1_1 + activ_text_ex + + + diff --git a/tests/phpunit/CRM/Utils/Migrate/fixtures/Contact-select.xml b/tests/phpunit/CRM/Utils/Migrate/fixtures/Contact-select.xml new file mode 100644 index 0000000000..339e230876 --- /dev/null +++ b/tests/phpunit/CRM/Utils/Migrate/fixtures/Contact-select.xml @@ -0,0 +1,70 @@ + + + + + + contact_selec + contact_selec + Contact + + 0 + + + 1 + 1 + civicrm_value_contact_selec_1 + 0 + 0 + 0 + + + + + Our_select_field + + String + Select + 1 + 0 + 0 + 4 + 1 + 0 + our_select_field_1 + our_select_field_20130818044104 + contact_selec + + + + + our_select_field_20130818044104 + Our select field + 1 + 1 + + + + + + 1 + Label1 + 0 + 1 + 0 + 0 + 1 + our_select_field_20130818044104 + + + + 2 + Label2 + 0 + 2 + 0 + 0 + 1 + our_select_field_20130818044104 + + + diff --git a/tests/phpunit/CRM/Utils/Migrate/fixtures/Contact-text.xml b/tests/phpunit/CRM/Utils/Migrate/fixtures/Contact-text.xml new file mode 100644 index 0000000000..3ed01bab06 --- /dev/null +++ b/tests/phpunit/CRM/Utils/Migrate/fixtures/Contact-text.xml @@ -0,0 +1,38 @@ + + + + + + contact_text_ + contact_text_ + Contact + + 0 + + + 1 + 1 + civicrm_value_contact_text__1 + 0 + 0 + 0 + + + + + test_textfield + + String + Text + abc + 1 + 0 + 0 + 4 + 1 + 0 + name1_1 + contact_text_ + + + diff --git a/tests/phpunit/CRM/Utils/Migrate/fixtures/Individual-text.xml b/tests/phpunit/CRM/Utils/Migrate/fixtures/Individual-text.xml new file mode 100644 index 0000000000..019131bdf7 --- /dev/null +++ b/tests/phpunit/CRM/Utils/Migrate/fixtures/Individual-text.xml @@ -0,0 +1,38 @@ + + + + + + indiv_text_ex + indiv_text_ex + Individual + + 0 + + + 1 + 1 + civicrm_value_indiv_text_ex_1 + 0 + 0 + 0 + + + + + test_textfield + + String + Text + abc + 1 + 0 + 0 + 4 + 1 + 0 + name1_1 + indiv_text_ex + + + diff --git a/tests/phpunit/CRM/Utils/Migrate/fixtures/IndividualStudent-text.xml b/tests/phpunit/CRM/Utils/Migrate/fixtures/IndividualStudent-text.xml new file mode 100644 index 0000000000..5841cf78cc --- /dev/null +++ b/tests/phpunit/CRM/Utils/Migrate/fixtures/IndividualStudent-text.xml @@ -0,0 +1,40 @@ + + + + + + indiv_text_ex + indiv_text_ex + Individual + contact_type + Student + + 0 + + + 1 + 1 + civicrm_value_indiv_text_ex_1 + 0 + 0 + 0 + + + + + test_textfield + + String + Text + abc + 1 + 0 + 0 + 4 + 1 + 0 + name1_1 + indiv_text_ex + + + -- 2.25.1