--fixed webtest, crm test and upgrade script for CRM-12470
authorPradeep Nayak <pradeep@pradeep.(none)>
Mon, 20 May 2013 08:11:42 +0000 (13:41 +0530)
committerPradeep Nayak <pradeep@pradeep.(none)>
Mon, 20 May 2013 08:11:42 +0000 (13:41 +0530)
----------------------------------------
* CRM-12470: Creating new financial type without AR account leads to unbalanced transactions
  http://issues.civicrm.org/jira/browse/CRM-12470

12 files changed:
CRM/Upgrade/Incremental/sql/4.3.4.mysql.tpl
tests/phpunit/CRM/Contribute/BAO/ContributionPageTest.php
tests/phpunit/CRM/Contribute/BAO/ContributionTypeTest.php
tests/phpunit/CRM/Financial/BAO/FinancialAccountTest.php
tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php
tests/phpunit/CRM/Financial/BAO/FinancialTypeTest.php
tests/phpunit/CiviTest/CiviSeleniumTestCase.php
tests/phpunit/CiviTest/CiviUnitTestCase.php
tests/phpunit/WebTest/Contact/SearchBuilderTest.php
tests/phpunit/WebTest/Contribute/AddPricesetTest.php
tests/phpunit/WebTest/Contribute/UpdateContributionTest.php
tests/phpunit/WebTest/Financial/FinancialAccountTypeTest.php

index ea0b70fa5085cbe2eb3c428d9f8029a230f92e2f..fbb8167b4c2b6501572f15e966e8b1a1db4aa6bd 100644 (file)
@@ -1 +1,6 @@
 {* placeholder file for upgrade*}
+
+-- CRM-12470
+UPDATE civicrm_financial_account
+SET is_default = 1
+WHERE name IN ('{ts escape="sql"}Premiums{/ts}', '{ts escape="sql"}Banking Fees{/ts}', '{ts escape="sql"}Accounts Payable{/ts}', '{ts escape="sql"}Donation{/ts}');
index 450de66b94ddd96d6cb782619b83ccd2cd919300..d8fabb9637e12fb6babde8f4c5c4ddf25eb05c12 100644 (file)
@@ -57,7 +57,7 @@ class CRM_Contribute_BAO_ContributionPageTest extends CiviUnitTestCase {
     $params = array(
       'qfkey' => '9a3ef3c08879ad4c8c109b21c583400e',
       'title' => 'Test Contribution Page',
-                         'financial_type_id'   => $this->_contributionTypeID,
+      'financial_type_id' => $this->_contributionTypeID,
       'intro_text' => '',
       'footer_text' => 'Thanks',
       'is_for_organization' => 0,
@@ -88,7 +88,7 @@ class CRM_Contribute_BAO_ContributionPageTest extends CiviUnitTestCase {
 
     $params = array(
       'title' => 'Test Contribution Page',
-                         'financial_type_id'   => $this->_contributionTypeID,
+      'financial_type_id' => $this->_contributionTypeID,
       'is_active' => 1,
     );
 
@@ -96,7 +96,7 @@ class CRM_Contribute_BAO_ContributionPageTest extends CiviUnitTestCase {
     $id               = $contributionpage->id;
     $is_active        = 1;
     $pageActive       = CRM_Contribute_BAO_ContributionPage::setIsActive($id, $is_active);
-        $this->assertEquals( $pageActive, true, 'Verify financial types record deletion.');
+    $this->assertEquals($pageActive, true, 'Verify financial types record deletion.');
     ContributionPage::delete($contributionpage->id);
   }
 
@@ -107,7 +107,7 @@ class CRM_Contribute_BAO_ContributionPageTest extends CiviUnitTestCase {
 
     $params = array(
       'title' => 'Test Contribution Page',
-                         'financial_type_id'   => $this->_contributionTypeID,
+      'financial_type_id' => $this->_contributionTypeID,
       'is_active' => 1,
     );
 
@@ -118,7 +118,7 @@ class CRM_Contribute_BAO_ContributionPageTest extends CiviUnitTestCase {
     $setValues = CRM_Contribute_BAO_ContributionPage::setValues($id, $values);
 
     $this->assertEquals($params['title'], $values['title'], 'Verify contribution title.');
-        $this->assertEquals( $this->_contributionTypeID, $values['financial_type_id'], 'Verify financial types id.');
+    $this->assertEquals($this->_contributionTypeID, $values['financial_type_id'], 'Verify financial types id.');
     $this->assertEquals(1, $values['is_active'], 'Verify contribution is_active value.');
     ContributionPage::delete($contributionpage->id);
   }
@@ -130,7 +130,7 @@ class CRM_Contribute_BAO_ContributionPageTest extends CiviUnitTestCase {
     $params = array(
       'qfkey' => '9a3ef3c08879ad4c8c109b21c583400e',
       'title' => 'Test Contribution Page',
-                         'financial_type_id'   => $this->_contributionTypeID,
+      'financial_type_id' => $this->_contributionTypeID,
       'intro_text' => '',
       'footer_text' => 'Thanks',
       'is_for_organization' => 0,
@@ -149,7 +149,7 @@ class CRM_Contribute_BAO_ContributionPageTest extends CiviUnitTestCase {
 
     $contributionpage = CRM_Contribute_BAO_ContributionPage::create($params);
     $copycontributionpage = CRM_Contribute_BAO_ContributionPage::copy($contributionpage->id);
-         $this->assertEquals( $copycontributionpage->financial_type_id, $this->_contributionTypeID, 'Check for Financial type id.' );
+    $this->assertEquals($copycontributionpage->financial_type_id, $this->_contributionTypeID, 'Check for Financial type id.');
     $this->assertEquals($copycontributionpage->goal_amount, 400, 'Check for goal amount.');
     ContributionPage::delete($contributionpage->id);
     ContributionPage::delete($copycontributionpage->id);
index cbb08c0dbe912f4aaa32255bfeac216d7d5e97bf..82e81c641b9aad49036b31e5ba17cf111a3e5728 100644 (file)
@@ -29,7 +29,7 @@ require_once 'CiviTest/CiviUnitTestCase.php';
 class CRM_Contribute_BAO_ContributionTypeTest extends CiviUnitTestCase {
   function get_info() {
     return array(
-                     'name'        => 'FinancialAccount BAOs',
+      'name' => 'FinancialAccount BAOs',
       'description' => 'Test all Contribute_BAO_Contribution methods.',
       'group' => 'CiviCRM BAO Tests',
     );
@@ -37,6 +37,11 @@ class CRM_Contribute_BAO_ContributionTypeTest extends CiviUnitTestCase {
 
   function setUp() {
     parent::setUp();
+    $this->organizationCreate();
+  }
+  
+  function teardown() {
+    $this->financialAccountDelete('Donations');
   }
 
   /**
@@ -82,7 +87,7 @@ class CRM_Contribute_BAO_ContributionTypeTest extends CiviUnitTestCase {
    */
   function testSetIsActive() {
     $params = array(
-      'name' => 'testDonations',
+      'name' => 'Donations',
       'is_deductible' => 0,
       'is_active' => 1,
     );
@@ -103,7 +108,7 @@ class CRM_Contribute_BAO_ContributionTypeTest extends CiviUnitTestCase {
    */
   function testdel() {
     $params = array(
-      'name' => 'checkDonations',
+      'name' => 'Donations',
       'is_deductible' => 0,
       'is_active' => 1,
     );
index bcb17f61eaf72eba7bcea8de66ec1ae89c03f29c..78a75f0f51419e88239e2ca3faa4da17b3acb5ba 100644 (file)
@@ -25,8 +25,6 @@
  +--------------------------------------------------------------------+
 */
 require_once 'CiviTest/CiviUnitTestCase.php';
-require_once 'CRM/Financial/DAO/FinancialAccount.php';
-require_once 'CRM/Financial/BAO/FinancialAccount.php';
 
 class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase {
 
@@ -40,6 +38,11 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase {
 
   function setUp() {
     parent::setUp();
+    $this->organizationCreate();
+  }
+
+  function teardown() {
+    $this->financialAccountDelete('Donations');
   }
 
   /**
@@ -70,7 +73,7 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase {
    */
   function testRetrieve() {
     $params = array(
-      'name' => 'Donations_1',
+      'name' => 'Donations',
       'is_deductible' => 0,
       'is_active' => 1,
     );
@@ -79,7 +82,7 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase {
 
     $result = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults);
 
-    $this->assertEquals($result->name, 'Donations_1', 'Verify financial type name.');
+    $this->assertEquals($result->name, 'Donations', 'Verify financial type name.');
   }
 
   /**
@@ -87,7 +90,7 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase {
    */
   function testSetIsActive() {
     $params = array(
-      'name' => 'testDonations',
+      'name' => 'Donations',
       'is_deductible' => 0,
       'is_active' => 1,
     );
@@ -111,7 +114,7 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase {
    */
   function testdel() {
     $params = array(
-      'name' => 'checkDonations',
+      'name' => 'Donations',
       'is_deductible' => 0,
       'is_active' => 1,
     );
@@ -129,25 +132,15 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase {
    */
   function testGetAccountingCode() {
     $params = array(
-      'name' => 'TestFinancialAccount',
-      'accounting_code' => 4800,
-      'is_deductible' => 0,
+      'name' => 'Donations',
       'is_active' => 1,
       'is_reserved' => 0,
     );
 
     $ids = array();
-    $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
     $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids);
-    $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' "));
-    $financialParams = array(
-      'entity_table' => 'civicrm_financial_type',
-      'entity_id' => $financialType->id,
-      'account_relationship' => $relationTypeId,
-      'financial_account_id' => $financialAccount->id,
-    );
-
-    CRM_Financial_BAO_FinancialTypeAccount::add($financialParams, $ids);
+    $financialAccountid = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', 'Donations', 'id', 'name');
+    CRM_Core_DAO::setFieldValue('CRM_Financial_DAO_FinancialAccount', $financialAccountid, 'accounting_code', '4800');
     $accountingCode = CRM_Financial_BAO_FinancialAccount::getAccountingCode($financialType->id);
     $this->assertEquals( $accountingCode, 4800, 'Verify accounting code.');
   }
index f45793e05acff22858bcd509d0f491d8f13f784a..975ac1f849a7ccadffd301a879fb4031a1fce7c7 100755 (executable)
  +--------------------------------------------------------------------+
 */
 require_once 'CiviTest/CiviUnitTestCase.php';
-require_once 'CRM/Financial/DAO/FinancialAccount.php';
-require_once 'CRM/Financial/BAO/FinancialAccount.php';
-require_once 'CRM/Financial/BAO/FinancialTypeAccount.php';
 
 class CRM_Financial_BAO_FinancialTypeAccountTest extends CiviUnitTestCase {
 
   function get_info() {
     return array(
-      'name'        => 'FinancialTypeAccount BAOs',
+      'name' => 'FinancialTypeAccount BAOs',
       'description' => 'Test all Contribute_BAO_Contribution methods.',
-      'group'       => 'CiviCRM BAO Tests',
+      'group' => 'CiviCRM BAO Tests',
     );
   }
 
   function setUp() {
     parent::setUp();
+    $this->organizationCreate();
   }
 
   /**
@@ -58,6 +56,7 @@ class CRM_Financial_BAO_FinancialTypeAccountTest extends CiviUnitTestCase {
 
     $ids = array();
     $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
+    $params['name'] = 'test_financialType1';
     $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids);
     $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' "));
     $financialParams = array(
@@ -92,6 +91,7 @@ class CRM_Financial_BAO_FinancialTypeAccountTest extends CiviUnitTestCase {
     $ids = array();
     $defaults = array();
     $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
+    $params['name'] = 'test_financialType2';
     $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids);
     $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Expense Account is' "));
     $financialParams = array(
@@ -119,6 +119,7 @@ class CRM_Financial_BAO_FinancialTypeAccountTest extends CiviUnitTestCase {
     );
     $ids = array();
     $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
+    $params['name'] = 'test_financialType3';
     $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids);
     $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
     $financialParams = array(
@@ -148,20 +149,20 @@ class CRM_Financial_BAO_FinancialTypeAccountTest extends CiviUnitTestCase {
     );
     $ids = array();
     $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
-    $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids);
-    $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' "));
-    $financialParams = array(
-      'entity_table' => 'civicrm_financial_type',
-      'entity_id' => $financialType->id,
-      'account_relationship' => $relationTypeId,
+    $params = array(
       'financial_account_id' => $financialAccount->id,
+      'payment_processor_type_id' => 1,
+      'domain_id' => 1,
+      'billing_mode' => 1,
+      'name' => 'paymentProcessor',
     );
-    $financialAccountType = CRM_Financial_BAO_FinancialTypeAccount::add($financialParams, $ids);
+    $processor = CRM_Financial_BAO_PaymentProcessor::create($params);
+    
     $account = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount(
-      $financialAccountType->entity_id,
-      $financialAccountType->entity_table
+      $processor->id,
+      'civicrm_payment_processor'
     );
-    $this->assertEquals( $account, 'TestFinancialAccount', 'Verify Financial Account Name');
+    $this->assertEquals($account, 'TestFinancialAccount', 'Verify Financial Account Name');
   }
 
   /**
index f96a19df8eb3fa7d68a9ff2931bfd8eecf92d030..d25708d1553a51ce7b225de9454b42958c58d4df 100755 (executable)
  +--------------------------------------------------------------------+
 */
 require_once 'CiviTest/CiviUnitTestCase.php';
-require_once 'CRM/Financial/DAO/FinancialAccount.php';
-require_once 'CRM/Financial/BAO/FinancialAccount.php';
 
 class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase {
 
   function get_info() {
     return array(
-      'name'        => 'FinancialType BAOs',
+      'name' => 'FinancialType BAOs',
       'description' => 'Test all Contribute_BAO_Contribution methods.',
-      'group'       => 'CiviCRM BAO Tests',
+      'group' => 'CiviCRM BAO Tests',
     );
   }
 
@@ -42,6 +40,10 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase {
     parent::setUp();
   }
 
+  function teardown() {
+    $this->financialAccountDelete('Donations');
+  }
+
   /**
    * check method add()
    */
@@ -80,7 +82,7 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase {
 
     $defaults = array();
     $result = CRM_Financial_BAO_FinancialType::retrieve($params, $defaults);
-    $this->assertEquals( $result->name, 'Donations', 'Verify Name for Financial Type');
+    $this->assertEquals($result->name, 'Donations', 'Verify Name for Financial Type');
   }
 
   /**
@@ -88,14 +90,14 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase {
    */
   function testSetIsActive() {
     $params = array(
-      'name' => 'testDonations',
+      'name' => 'Donations',
       'is_deductible' => 0,
       'is_active' => 1,
     );
     $ids = array();
     $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids);
     $result = CRM_Financial_BAO_FinancialType::setIsActive($financialType->id, 0);
-    $this->assertEquals( $result, true , 'Verify financial type record updation for is_active.');
+    $this->assertEquals($result, true , 'Verify financial type record updation for is_active.');
     $isActive = $this->assertDBNotNull(
       'CRM_Financial_DAO_FinancialType',
       $financialType->id ,
@@ -103,7 +105,7 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase {
       'id',
       'Database check on updated for financial type is_active.'
     );
-    $this->assertEquals( $isActive, 0, 'Verify financial types is_active.');
+    $this->assertEquals($isActive, 0, 'Verify financial types is_active.');
   }
 
   /**
@@ -111,7 +113,7 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase {
    */
   function testDel() {
     $params = array(
-      'name' => 'checkDonations',
+      'name' => 'Donations',
       'is_deductible' => 0,
       'is_active' => 1,
     );
@@ -119,8 +121,8 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase {
     $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids);
 
     CRM_Financial_BAO_FinancialType::del($financialType->id);
-    $params = array('id' => $financialType->id );
+    $params = array('id' => $financialType->id);
     $result = CRM_Financial_BAO_FinancialType::retrieve($params, $defaults);
-    $this->assertEquals( empty($result), true, 'Verify financial types record deletion.');
+    $this->assertEquals(empty($result), true, 'Verify financial types record deletion.');
   }
 }
\ No newline at end of file
index c44c8c1baa12dabc563c5bfca37b82b1893c88ee..25fecd7e5dede66574ffc507c3a96b0efe6c56f6 100644 (file)
@@ -1649,7 +1649,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
     $this->click('_qf_FinancialType_next');
     $this->waitForPageToLoad($this->getTimeoutMsec());
     if ($option == 'new') {
-      $text = "The financial type '{$financialType['name']}' has been added. You can add Financial Accounts to this Financial Type now.";
+      $text = "Your Financial '{$financialType['name']}' Type has been created, along with a corresponding income account '{$financialType['name']}'. That income account, along with standard financial accounts 'Accounts Receivable', 'Banking Fees' and 'Premiums' have been linked to the financial type. You may edit or replace those relationships here.";
     }
     else {
       $text = "The financial type '{$financialType['name']}' has been saved.";
@@ -1702,63 +1702,6 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
     }
   }
 
-  function _testAddFinancialType() {
-    // Add new Financial Account
-    $orgName = 'Alberta ' . substr(sha1(rand()), 0, 7);
-    $financialAccountTitle = 'Financial Account ' . substr(sha1(rand()), 0, 4);
-    $financialAccountDescription = "{$financialAccountTitle} Description";
-    $accountingCode = 1033;
-    $financialAccountType = 'Revenue'; //Asset Revenue
-    $taxDeductible = FALSE;
-    $isActive = FALSE;
-    $isTax = TRUE;
-    $taxRate = 9.99999999;
-    $isDefault = FALSE;
-
-    //Add new organisation
-    if ($orgName) {
-      $this->webtestAddOrganization($orgName);
-    }
-
-    $this->_testAddFinancialAccount(
-      $financialAccountTitle,
-      $financialAccountDescription,
-      $accountingCode,
-      $orgName,
-      $financialAccountType,
-      $taxDeductible,
-      $isActive,
-      $isTax,
-      $taxRate,
-      $isDefault
-    );
-    $this->waitForElementPresent("xpath=//table/tbody//tr/td[1][text()='{$financialAccountTitle}']/../td[8]/span/a[text()='Edit']");
-
-    //Add new Financial Type
-    $financialType['name'] = 'FinancialType ' . substr(sha1(rand()), 0, 4);
-    $financialType['is_deductible'] = TRUE;
-    $financialType['is_reserved'] = FALSE;
-    $this->addeditFinancialType($financialType);
-
-    $accountRelationship = "Income Account is"; //Asset Account - of Income Account is
-    $expected[] = array(
-      'financial_account' => $financialAccountTitle,
-      'account_relationship' => $accountRelationship
-    );
-
-    $this->select('account_relationship', "label={$accountRelationship}");
-    // Because it tends to cause problems, all uses of sleep() must be justified in comments
-    // Sleep should never be used for wait for anything to load from the server
-    // Justification for this instance: FIXME
-    sleep(2);
-    $this->select('financial_account_id', "label={$financialAccountTitle}");
-    $this->click('_qf_FinancialTypeAccount_next');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-    $text = 'The financial type Account has been saved.';
-    $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text);
-    return $financialType['name'];
-  }
-
   function addPremium($name, $sku, $amount, $price, $cost, $financialType) {
     $this->waitForElementPresent("_qf_ManagePremiums_upload-bottom");
     $this->type("name", $name);
index 1b8304330c67b2b0113ef33da93d55ab0aa6369a..92a4d97b78b0cfe7815a5c93c4488ed6f64c76cc 100644 (file)
@@ -2305,6 +2305,17 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
       $this->origExtensionSystem = NULL;
     }
   }
+
+  function financialAccountDelete($name) {
+    $financialAccount = new CRM_Financial_DAO_FinancialAccount();
+    $financialAccount->name = $name;
+    if($financialAccount->find(TRUE)) {
+      $entityFinancialType = new CRM_Financial_DAO_EntityFinancialAccount();
+      $entityFinancialType->financial_account_id = $financialAccount->id;
+      $entityFinancialType->delete();
+      $financialAccount->delete();
+    }
+  }
 }
 
 function CiviUnitTestCase_fatalErrorHandler($message) {
index ef0a10b46f5e921e95b581152abd2978eb02cb83..1f8bea8a0bd2220286143afbac4b04291cfd77f9 100644 (file)
@@ -362,16 +362,8 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
       'is_deductible' => FALSE,
     );
     $this->addeditFinancialType($financialType);
-    $this->select('account_relationship', 'label=Income Account is');
-    $this->select('financial_account_id', 'label=Discounts');
-    $this->click('_qf_FinancialTypeAccount_next-botttom');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
     $financialType['name'] = $financialTypeName2;
     $this->addeditFinancialType($financialType);
-    $this->select('account_relationship', 'label=Income Account is');
-    $this->select('financial_account_id', 'label=Discounts');
-    $this->click('_qf_FinancialTypeAccount_next-botttom');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
     //create 6 contribution
     $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", "_qf_Contribution_upload");
     for ($i = 1; $i <= 6; $i++) {
index 3b29dd659b5e31b1b1ce11491dc1c7edef374eab..32490939c50e0ee21411c48320d0a54a9480c939 100644 (file)
@@ -163,58 +163,11 @@ class WebTest_Contribute_AddPricesetTest extends CiviSeleniumTestCase {
   }
 
   function _testAddFinancialType() {
-    // Add new Financial Account
-    $orgName = 'Alberta '.substr(sha1(rand()), 0, 7);
-    $financialAccountTitle = 'Financial Account '.substr(sha1(rand()), 0, 4);
-    $financialAccountDescription = "{$financialAccountTitle} Description";
-    $accountingCode = 1033;
-    $financialAccountType = 'Revenue';
-    $taxDeductible = FALSE;
-    $isActive = FALSE;
-    $isTax = TRUE;
-    $taxRate = 9;
-    $isDefault = FALSE;
-
-    //Add new organisation
-    if($orgName) {
-      $this->webtestAddOrganization($orgName);
-    }
-
-    $this->_testAddFinancialAccount($financialAccountTitle,
-      $financialAccountDescription,
-      $accountingCode,
-      $orgName,
-      $financialAccountType,
-      $taxDeductible,
-      $isActive,
-      $isTax,
-      $taxRate,
-      $isDefault
-    );
-    $this->waitForElementPresent("xpath=//table/tbody//tr/td[1][text()='{$financialAccountTitle}']/../td[9]/span/a[text()='Edit']");
-
     //Add new Financial Type
     $financialType['name'] = 'FinancialType '.substr(sha1(rand()), 0, 4);
     $financialType['is_deductible'] = TRUE;
     $financialType['is_reserved'] = FALSE;
     $this->addeditFinancialType($financialType);
-
-    $accountRelationship = "Income Account is";
-    $expected[] = array('financial_account' => $financialAccountTitle,
-
-      'account_relationship' => $accountRelationship
-    );
-
-    $this->select('account_relationship', "label={$accountRelationship}");
-    // Because it tends to cause problems, all uses of sleep() must be justified in comments
-    // Sleep should never be used for wait for anything to load from the server
-    // Justification for this instance: FIXME
-    sleep(2);
-    $this->select('financial_account_id', "label={$financialAccountTitle}");
-    $this->click('_qf_FinancialTypeAccount_next');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-    $text = 'The financial type Account has been saved.';
-    $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text);
     return $financialType['name'];
   }
 
index c9bb362ec17d7ced7791077898a72cb1533df2e9..dffa551ec9ff3bacd4539d1da676170ea43d6810 100644 (file)
@@ -121,12 +121,11 @@ class WebTest_Contribute_UpdateContributionTest extends CiviSeleniumTestCase {
      'is_deductible' => 1,
    );
    $this->addeditFinancialType($financialType);
-   $this->select("account_relationship", "label=Cost of Sales Account is");
-   $this->select("financial_account_id", "label=$from");
-   $this->clickLink("_qf_FinancialTypeAccount_next_new-botttom");
+   $this->clickLink("xpath=//a[@id='newfinancialTypeAccount']");
    $this->select("account_relationship", "label=Premiums Inventory Account is");
    $this->select("financial_account_id", "label=$to");
    $this->clickLink("_qf_FinancialTypeAccount_next-botttom");
+   
    $premiumName = 'Premium'.substr(sha1(rand()), 0, 7);
    $amount = 500;
    $sku = 'SKU';
@@ -187,18 +186,17 @@ class WebTest_Contribute_UpdateContributionTest extends CiviSeleniumTestCase {
    $from = 'Premiums';
    $to = 'Premiums inventory';
    $financialType = array(
-     'name' => 'Test Financial'.substr(sha1(rand()), 0, 7),
+     'name' => 'Test Financial' . substr(sha1(rand()), 0, 7),
      'is_reserved' => 1,
      'is_deductible' => 1,
    );
    $this->addeditFinancialType($financialType);
-   $this->select("account_relationship", "label=Cost of Sales Account is");
-   $this->select("financial_account_id", "label=$from");
-   $this->clickLink("_qf_FinancialTypeAccount_next_new-botttom");
+   $this->clickLink("xpath=//a[@id='newfinancialTypeAccount']");
+   
    $this->select("account_relationship", "label=Premiums Inventory Account is");
    $this->select("financial_account_id", "label=$to");
    $this->clickLink("_qf_FinancialTypeAccount_next-botttom");
-   $premiumName = 'Premium'.substr(sha1(rand()), 0, 7);
+   $premiumName = 'Premium' . substr(sha1(rand()), 0, 7);
    $amount = 500;
    $sku = 'SKU';
    $price = 300;
index f1f8ff7ca1f9ff6aba738f1941cd8d8ed0efc8cf..97fd00b216950119320f82ef9bb2b4faa254c0e6 100644 (file)
@@ -37,102 +37,35 @@ class WebTest_Financial_FinancialAccountTypeTest extends CiviSeleniumTestCase {
     // Log in using webtestLogin() method
     $this->webtestLogin();
 
-    // Add new Financial Account
-    $orgName = 'Alberta '.substr(sha1(rand()), 0, 7);
-    $financialAccountTitle = 'Financial Account '.substr(sha1(rand()), 0, 4);
-    $financialAccountDescription = "{$financialAccountTitle} Description";
-    $accountingCode = 1033;
-    $financialAccountType = 'Revenue';
-    $taxDeductible = FALSE;
-    $isActive = FALSE;
-    $isTax = TRUE;
-    $taxRate = 5.20;
-    $isDefault = FALSE;
-
-    //Add new organisation
-    if ($orgName) {
-      $this->webtestAddOrganization($orgName);
-    }
-
-    $this->_testAddFinancialAccount(
-
-      $financialAccountTitle,
-      $financialAccountDescription,
-      $accountingCode,
-      $orgName,
-      $financialAccountType,
-      $taxDeductible,
-      $isActive,
-      $isTax,
-      $taxRate,
-      $isDefault
-    );
-
-    $this->waitForElementPresent("xpath=//table/tbody//tr/td[1][text()='{$financialAccountTitle}']/../td[9]/span/a[text()='Edit']");
-
-    $this->clickLink("xpath=//table/tbody//tr/td[1][text()='{$financialAccountTitle}']/../td[9]/span/a[text()='Edit']", '_qf_FinancialAccount_cancel-botttom');
-
-    //Varify Data after Adding new Financial Account
-    $verifyData = array(
-
-      'name' => $financialAccountTitle,
-      'description' => $financialAccountDescription,
-      'accounting_code' => $accountingCode,
-      'contact_name' => $orgName,
-      'tax_rate' => $taxRate,
-      'is_tax' => 'on',
-      'is_deductible' => 'off',
-      'is_default' => 'off',
-    );
-
-    $this->_assertFinancialAccount($verifyData);
-    $verifySelectFieldData = array(
-      'financial_account_type_id' => $financialAccountType,
-    );
-    $this->_assertSelectVerify($verifySelectFieldData);
-    $this->click('_qf_FinancialAccount_cancel-botttom');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-
     //Add new Financial Type
     $financialType['name'] = 'FinancialType '.substr(sha1(rand()), 0, 4);
     $financialType['is_deductible'] = true;
     $financialType['is_reserved'] = false;
     $this->addeditFinancialType($financialType);
-    $accountRelationship = "Income Account is";
-    $expected[] = array(
-
-      'financial_account' => $financialAccountTitle,
-
-      'account_relationship' => $accountRelationship
-
-    );
-
-    $this->select('account_relationship', "label={$accountRelationship}");
-    $this->select('financial_account_id', "label={$financialAccountTitle}");
-    $this->click('_qf_FinancialTypeAccount_next_new');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-    $text = 'The financial type Account has been saved.';
-    $this->waitForText('crm-notification-container', $text);
-    $text = 'You can add another Financial Account Type.';
-    $this->waitForText('crm-notification-container', $text);
-    $accountRelationship = 'Expense Account is';
-    $expected[] = array(
-      'financial_account' => 'Banking Fees',
-      'account_relationship' => $accountRelationship
+    $expected = array(
+      array(
+        'financial_account' => $financialType['name'],
+        'account_relationship' => "Income Account is",
+      ),
+      array(
+        'financial_account' => 'Banking Fees',
+        'account_relationship' => 'Expense Account is',
+      ),
+      array(
+        'financial_account' => 'Accounts Receivable',
+        'account_relationship' => 'Accounts Receivable Account is',
+      ),
+      array(
+        'financial_account' => 'Premiums',
+        'account_relationship' => 'Cost of Sales Account is',
+      ),
     );
-
-    $this->select('account_relationship', "label={$accountRelationship}");
-    $this->select('financial_account_id', "label=Banking Fees");
-    $this->click('_qf_FinancialTypeAccount_next');
-    $this->waitForElementPresent('newfinancialTypeAccount');
-    $text = 'The financial type Account has been saved.';
-    $this->waitForText('crm-notification-container', $text);
-
+    
     foreach ($expected as  $value => $label) {
       $this->verifyText("xpath=id('ltype')/div/table/tbody/tr/td[2][text()='$label[financial_account]']/../td[1]", preg_quote($label['account_relationship']));
     }
     $this->openCiviPage('admin/financial/financialType', 'reset=1', 'newFinancialType');
-    $this->verifyText("xpath=id('ltype')/div/table/tbody/tr/td[1][text()='$financialType[name]']/../td[3]", $financialAccountTitle. ',Banking Fees');
+    $this->verifyText("xpath=id('ltype')/div/table/tbody/tr/td[1][text()='$financialType[name]']/../td[3]", 'Accounts Receivable,Banking Fees,Premiums,' . $financialType['name']);
     $this->click("xpath=id('ltype')/div/table/tbody/tr/td[1][text()='$financialType[name]']/../td[7]/span/a[text()='Accounts']");
     $this->waitForElementPresent('newfinancialTypeAccount');
     $this->click("xpath=id('ltype')/div/table/tbody/tr/td[2][text()='Banking Fees']/../td[7]/span/a[text()='Edit']");
@@ -142,12 +75,12 @@ class WebTest_Financial_FinancialAccountTypeTest extends CiviSeleniumTestCase {
     // Sleep should never be used for wait for anything to load from the server
     // Justification for this instance: FIXME
     sleep(1);
-    $this->select('account_relationship', "label=Accounts Receivable Account is");
-    $this->select('financial_account_id', "label=Accounts Receivable");
+    $this->select('account_relationship', "label=Premiums Inventory Account is");
+    $this->select('financial_account_id', "label=Premiums inventory");
     $this->click('_qf_FinancialTypeAccount_next');
-    $this->waitForElementPresent("xpath=id('ltype')/div/table/tbody/tr/td[2][text()='Accounts Receivable']/../td[7]/span/a[text()='Edit']");
-    $this->verifyText("xpath=id('ltype')/div/table/tbody/tr/td[2][text()='Accounts Receivable']/../td[1]", preg_quote('Accounts Receivable Account is'));
-    $this->clickLink("xpath=id('ltype')/div/table/tbody/tr/td[2][text()='Accounts Receivable']/../td[7]/span/a[text()='Delete']", '_qf_FinancialTypeAccount_next-botttom');
+    $this->waitForElementPresent("xpath=id('ltype')/div/table/tbody/tr/td[2][text()='Premiums inventory']/../td[7]/span/a[text()='Edit']");
+    $this->verifyText("xpath=id('ltype')/div/table/tbody/tr/td[2][text()='Premiums inventory']/../td[1]", preg_quote('Premiums Inventory Account is'));
+    $this->clickLink("xpath=id('ltype')/div/table/tbody/tr/td[2][text()='Premiums inventory']/../td[7]/span/a[text()='Delete']", '_qf_FinancialTypeAccount_next-botttom');
     $this->click('_qf_FinancialTypeAccount_next-botttom');
     $this->waitForPageToLoad($this->getTimeoutMsec());
     $this->waitForText('crm-notification-container', 'Selected financial type account has been deleted.');