update MembershipForm test to be less clobbery
authorEileen McNaughton <eileen@fuzion.co.nz>
Tue, 12 May 2015 05:23:04 +0000 (17:23 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Tue, 12 May 2015 05:42:49 +0000 (17:42 +1200)
Conflicts:
tests/phpunit/CRM/Member/Form/MembershipTest.php

tests/phpunit/CRM/Member/Form/MembershipTest.php
tests/phpunit/CRM/Member/Form/dataset/data.xml

index 4fa0c4e3eed626e9478a5116819491e0aaf8fc93..0c09c2f990997e7c4f98aa7113b792eb90cf1f92 100644 (file)
@@ -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);
   }
 
 }
index b16145cf2f975fffabfe9fe740e8ca1352f69920..098bd0ee8964d28f6cf15bb8826adb7fed9a8794 100644 (file)
@@ -1,10 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!--  $Id: data.xml 43570 2012-11-09 12:03:45Z deepak $ -->
 <dataset>
-  <civicrm_domain
-    id="1"
-    name="Test domain"
-  />
   <civicrm_contact
     id="17"
     contact_type="Individual"
@@ -23,7 +19,7 @@
   />
 
   <civicrm_relationship_type
-    id="1"
+    id="20"
     name_a_b="Member of"
     label_a_b="Member of"
     name_b_a="Member is"
     contact_type_b="Organization"
     is_active="1"
   />
-  <civicrm_financial_type
-    id="5"
-    name="Member Dues"
-    is_active="1"
-  />
   <civicrm_membership_type
-    id="3"
+    id="15"
     domain_id="1"
     name="AnnualRolling"
     member_of_contact_id="23"
     duration_unit="year"
     duration_interval="1"
     period_type="rolling"
-    relationship_type_id="1"
-    financial_type_id="5"
+    relationship_type_id="20"
+    financial_type_id="2"
   />
   <civicrm_membership_type
-    id="7"
+    id="20"
     domain_id="1"
     name="AnnualFixed"
     member_of_contact_id="23"
     period_type="fixed"
     fixed_period_start_day="101"
     fixed_period_rollover_day="1231"
-    relationship_type_id="1"
-    financial_type_id="5"
+    relationship_type_id="20"
+    financial_type_id="2"
   />
   <civicrm_membership_type
-    id="13"
+    id="25"
     domain_id="1"
     name="Lifetime"
     member_of_contact_id="23"
     duration_unit="lifetime"
-    relationship_type_id="1"
-    financial_type_id="5"
-  />
-  <civicrm_membership_status
-    id="1"
-    name="New"
-    start_event="join_date"
-    end_event="join_date"
-    end_event_adjust_unit="month"
-    end_event_adjust_interval="3"
-    is_current_member="1"
-    is_admin="0"
-    weight="1"
-    is_default="0"
-    is_active="1"
-    is_reserved="0"
-  />
-  <civicrm_membership_status
-    id="2"
-    name="Current"
-    start_event="start_date"
-    end_event="end_date"
-    is_current_member="1"
-    is_admin="0"
-    weight="2"
-    is_default="1"
-    is_active="1"
-    is_reserved="0"
-  />
-  <civicrm_membership_status
-    id="3"
-    name="Grace"
-    start_event="end_date"
-    end_event="end_date"
-    end_event_adjust_unit="month"
-    end_event_adjust_interval="1"
-    is_current_member="1"
-    is_admin="0"
-    weight="3"
-    is_default="0"
-    is_active="1"
-    is_reserved="0"
-  />
-  <civicrm_membership_status
-    id="4"
-    name="Expired"
-    start_event="end_date"
-    start_event_adjust_unit="month"
-    start_event_adjust_interval="1"
-    is_current_member="0"
-    is_admin="0"
-    weight="4"
-    is_default="0"
-    is_active="1"
-    is_reserved="0"
-  />
+    relationship_type_id="20"
+    financial_type_id="2"
+   />
 
 </dataset>