From: Eileen McNaughton Date: Tue, 12 May 2015 05:23:04 +0000 (+1200) Subject: update MembershipForm test to be less clobbery X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=cb447e7a970018ad7303b73565f2dc4eae94b639;p=civicrm-core.git update MembershipForm test to be less clobbery Conflicts: tests/phpunit/CRM/Member/Form/MembershipTest.php --- diff --git a/tests/phpunit/CRM/Member/Form/MembershipTest.php b/tests/phpunit/CRM/Member/Form/MembershipTest.php index 4fa0c4e3ee..0c09c2f990 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipTest.php @@ -49,152 +49,12 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { * and redirect stdin to a temporary file */ public function setUp() { + $this->_apiversion = 3; // Connect to the database parent::setUp(); - $this->quickCleanup( - array( - 'civicrm_address_format', - 'civicrm_currency', - 'civicrm_domain', - 'civicrm_file', - 'civicrm_financial_account', - 'civicrm_financial_trxn', - 'civicrm_job', - 'civicrm_job_log', - 'civicrm_location_type', - 'civicrm_mail_settings', - 'civicrm_mapping', - 'civicrm_navigation', - 'civicrm_option_group', - 'civicrm_payment_processor', - 'civicrm_payment_processor_type', - 'civicrm_preferences_date', - 'civicrm_worldregion', - 'civicrm_component', - 'civicrm_persistent', - 'civicrm_prevnext_cache', - 'civicrm_action_mapping', - 'civicrm_acl', - 'civicrm_acl_entity_role', - 'civicrm_contact', - 'civicrm_acl_contact_cache', - 'civicrm_relationship_type', - 'civicrm_saved_search', - 'civicrm_mailing_component', - 'civicrm_mailing_bounce_type', - 'civicrm_mailing_bounce_pattern', - 'civicrm_financial_type', - 'civicrm_premiums', - 'civicrm_product', - 'civicrm_premiums_product', - 'civicrm_sms_provider', - 'civicrm_membership_status', - 'civicrm_campaign', - 'civicrm_campaign_group', - 'civicrm_survey', - 'civicrm_participant_status_type', - 'civicrm_event_carts', - 'civicrm_dedupe_rule_group', - 'civicrm_dedupe_rule', - 'civicrm_dedupe_exception', - 'civicrm_case', - 'civicrm_case_contact', - 'civicrm_grant', - 'civicrm_tell_friend', - 'civicrm_pledge_block', - 'civicrm_queue_item', - 'civicrm_report_instance', - 'civicrm_price_set', - 'civicrm_price_set_entity', - 'civicrm_pcp', - 'civicrm_batch', - 'civicrm_cache', - 'civicrm_country', - 'civicrm_custom_group', - 'civicrm_custom_field', - 'civicrm_dashboard', - 'civicrm_email', - 'civicrm_entity_batch', - 'civicrm_entity_file', - 'civicrm_entity_financial_trxn', - 'civicrm_im', - 'civicrm_log', - 'civicrm_mapping_field', - 'civicrm_menu', - 'civicrm_note', - 'civicrm_option_value', - 'civicrm_phone', - 'civicrm_state_province', - 'civicrm_tag', - 'civicrm_uf_match', - 'civicrm_timezone', - 'civicrm_openid', - 'civicrm_discount', - 'civicrm_website', - 'civicrm_setting', - 'civicrm_acl_cache', - 'civicrm_dashboard_contact', - 'civicrm_group', - 'civicrm_subscription_history', - 'civicrm_group_contact_cache', - 'civicrm_group_nesting', - 'civicrm_group_organization', - 'civicrm_relationship', - 'civicrm_mailing_event_subscribe', - 'civicrm_mailing_event_confirm', - 'civicrm_contribution_recur', - 'civicrm_contribution_page', - 'civicrm_contribution_widget', - 'civicrm_activity', - 'civicrm_activity_contact', - 'civicrm_case_activity', - 'civicrm_pledge', - 'civicrm_price_field', - 'civicrm_county', - 'civicrm_entity_tag', - 'civicrm_msg_template', - 'civicrm_uf_group', - 'civicrm_uf_field', - 'civicrm_uf_join', - 'civicrm_action_schedule', - 'civicrm_action_log', - 'civicrm_mailing', - 'civicrm_mailing_group', - 'civicrm_mailing_trackable_url', - 'civicrm_mailing_job', - 'civicrm_mailing_recipients', - 'civicrm_mailing_spool', - 'civicrm_mailing_event_queue', - 'civicrm_mailing_event_bounce', - 'civicrm_mailing_event_delivered', - 'civicrm_mailing_event_forward', - 'civicrm_mailing_event_opened', - 'civicrm_mailing_event_reply', - 'civicrm_mailing_event_trackable_url_open', - 'civicrm_mailing_event_unsubscribe', - 'civicrm_membership_type', - 'civicrm_membership', - 'civicrm_membership_block', - 'civicrm_membership_log', - 'civicrm_price_field_value', - 'civicrm_line_item', - 'civicrm_pcp_block', - 'civicrm_address', - 'civicrm_loc_block', - 'civicrm_group_contact', - 'civicrm_contribution', - 'civicrm_contribution_product', - 'civicrm_contribution_soft', - 'civicrm_membership_payment', - 'civicrm_event', - 'civicrm_participant', - 'civicrm_participant_payment', - 'civicrm_events_in_carts', - 'civicrm_pledge_payment', - ) - ); - + $this->_individualId = $this->individualCreate(); + $this->_paymentProcessorID = $this->processorCreate(); // Insert test data $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, @@ -204,6 +64,23 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { ); } + /** + * Clean up after each test. + */ + public function tearDown() { + $this->quickCleanUpFinancialEntities(); + $this->quickCleanup( + array( + 'civicrm_relationship', + 'civicrm_membership_type', + 'civicrm_membership', + ) + ); + $this->callAPISuccess('contact', 'delete', array('id' => 17, 'skip_undelete' => TRUE)); + $this->callAPISuccess('contact', 'delete', array('id' => 23, 'skip_undelete' => TRUE)); + $this->callAPISuccess('relationship_type', 'delete', array('id' => 20)); + } + /** * Test CRM_Member_Form_Membership::buildQuickForm() */ @@ -224,27 +101,21 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { $files = array(); $obj = new CRM_Member_Form_Membership(); $rc = $obj->formRule($params, $files, $obj); - $this->assertType('array', $rc, - 'In line ' . __LINE__ - ); - $this->assertTrue(array_key_exists('membership_type_id', $rc), - 'In line ' . __LINE__ - ); + $this->assertType('array', $rc); + $this->assertTrue(array_key_exists('membership_type_id', $rc)); $params['membership_type_id'] = array(1 => 3); $rc = $obj->formRule($params, $files, $obj); - $this->assertType('array', $rc, - 'In line ' . __LINE__ - ); - $this->assertTrue(array_key_exists('join_date', $rc), - 'In line ' . __LINE__ - ); + $this->assertType('array', $rc); + $this->assertTrue(array_key_exists('join_date', $rc)); } /** - * Test CRM_Member_Form_Membership::formRule() with a parameter - * that has an start date before the join date and a rolling - * membership type + * Test that form rule fails if start date is before join date. + * + * Test CRM_Member_Form_Membership::formRule() with a parameter + * that has an start date before the join date and a rolling + * membership type. */ public function testFormRuleRollingEarlyStart() { $unixNow = time(); @@ -255,19 +126,15 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { 'join_date' => $ymdNow, 'start_date' => $ymdYesterday, 'end_date' => '', - 'membership_type_id' => array('23', '3'), + 'membership_type_id' => array('23', '15'), ); $files = array(); $obj = new CRM_Member_Form_Membership(); $rc = call_user_func(array('CRM_Member_Form_Membership', 'formRule'), $params, $files, $obj ); - $this->assertType('array', $rc, - 'In line ' . __LINE__ - ); - $this->assertTrue(array_key_exists('start_date', $rc), - 'In line ' . __LINE__ - ); + $this->assertType('array', $rc); + $this->assertTrue(array_key_exists('start_date', $rc)); } /** @@ -284,7 +151,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { 'join_date' => $ymdNow, 'start_date' => $ymdNow, 'end_date' => $ymdYesterday, - 'membership_type_id' => array('23', '3'), + 'membership_type_id' => array('23', '15'), ); $files = array(); $obj = new CRM_Member_Form_Membership(); @@ -311,7 +178,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { 'join_date' => $ymdNow, 'start_date' => '', 'end_date' => $ymdYearFromNow, - 'membership_type_id' => array('23', '3'), + 'membership_type_id' => array('23', '15'), ); $files = array(); $obj = new CRM_Member_Form_Membership(); @@ -337,7 +204,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { 'end_date' => date('m/d/Y', $unixYearFromNow ), - 'membership_type_id' => array('23', '13'), + 'membership_type_id' => array('23', '25'), ); $files = array(); $obj = new CRM_Member_Form_Membership(); @@ -355,7 +222,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { $unixYearFromNow = $unixNow + (365 * 24 * 60 * 60); $params = array( 'join_date' => date('m/d/Y', $unixNow), - 'membership_type_id' => array('23', '13'), + 'membership_type_id' => array('23', '25'), 'is_override' => TRUE, ); $files = array(); @@ -380,7 +247,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { 'join_date' => date('m/d/Y', $unix1MFmNow), 'start_date' => '', 'end_date' => '', - 'membership_type_id' => array('23', '3'), + 'membership_type_id' => array('23', '15'), ); $files = array(); $obj = new CRM_Member_Form_Membership(); @@ -405,7 +272,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { 'join_date' => date('m/d/Y', $unixNow), 'start_date' => '', 'end_date' => '', - 'membership_type_id' => array('23', '3'), + 'membership_type_id' => array('23', '15'), ); $files = array(); $obj = new CRM_Member_Form_Membership(); @@ -426,7 +293,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { 'join_date' => date('m/d/Y', $unix1MAgo), 'start_date' => '', 'end_date' => '', - 'membership_type_id' => array('23', '3'), + 'membership_type_id' => array('23', '15'), ); $files = array(); $obj = new CRM_Member_Form_Membership(); @@ -447,7 +314,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { 'join_date' => date('m/d/Y', $unix6MAgo), 'start_date' => '', 'end_date' => '', - 'membership_type_id' => array('23', '3'), + 'membership_type_id' => array('23', '15'), ); $files = array(); $obj = new CRM_Member_Form_Membership(); @@ -468,7 +335,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { 'join_date' => date('m/d/Y', $unix1YAgo), 'start_date' => '', 'end_date' => '', - 'membership_type_id' => array('23', '3'), + 'membership_type_id' => array('23', '15'), ); $files = array(); $obj = new CRM_Member_Form_Membership(); @@ -489,7 +356,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { 'join_date' => date('m/d/Y', $unix2YAgo), 'start_date' => '', 'end_date' => '', - 'membership_type_id' => array('23', '3'), + 'membership_type_id' => array('23', '15'), ); $files = array(); $obj = new CRM_Member_Form_Membership(); @@ -517,7 +384,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { $rc = $obj->formRule($params, $files, $obj); // Should have found Current membership status - $this->assertTrue($rc, 'In line ' . __LINE__); + $this->assertTrue($rc); } } diff --git a/tests/phpunit/CRM/Member/Form/dataset/data.xml b/tests/phpunit/CRM/Member/Form/dataset/data.xml index b16145cf2f..098bd0ee89 100644 --- a/tests/phpunit/CRM/Member/Form/dataset/data.xml +++ b/tests/phpunit/CRM/Member/Form/dataset/data.xml @@ -1,10 +1,6 @@ - - - - - - + relationship_type_id="20" + financial_type_id="2" + />