From 23ead8721b111df1409aeb42f11eed6dff703c8d Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 6 Jul 2016 20:25:01 +1200 Subject: [PATCH] [NFC] CRM-19033 improve standardisation of tests NB jenkins is doing wierd things here so trying a small subset to see what jenkins does --- tests/phpunit/CRM/Contact/BAO/ContactTest.php | 22 ++- .../Contribute/BAO/ContributionPageTest.php | 23 ++-- .../phpunit/CRM/Core/BAO/CustomValueTest.php | 17 +-- .../phpunit/CRM/Core/BAO/OptionValueTest.php | 2 - .../phpunit/CRM/Event/BAO/ParticipantTest.php | 4 +- .../CRM/Pledge/BAO/PledgeBlockTest.php | 7 +- tests/phpunit/CiviTest/CiviUnitTestCase.php | 10 +- tests/phpunit/CiviTest/Contact.php | 89 ------------ tests/phpunit/CiviTest/ContributionPage.php | 61 --------- tests/phpunit/CiviTest/Custom.php | 127 ------------------ tests/phpunit/CiviTest/Event.php | 47 ------- tests/phpunit/CiviTest/Participant.php | 46 ------- tests/phpunit/CiviTest/PaypalPro.php | 60 --------- 13 files changed, 39 insertions(+), 476 deletions(-) delete mode 100644 tests/phpunit/CiviTest/Contact.php delete mode 100644 tests/phpunit/CiviTest/ContributionPage.php delete mode 100644 tests/phpunit/CiviTest/Custom.php delete mode 100644 tests/phpunit/CiviTest/Event.php delete mode 100644 tests/phpunit/CiviTest/Participant.php delete mode 100644 tests/phpunit/CiviTest/PaypalPro.php diff --git a/tests/phpunit/CRM/Contact/BAO/ContactTest.php b/tests/phpunit/CRM/Contact/BAO/ContactTest.php index a6e7a66f7f..a13fb9c5d5 100644 --- a/tests/phpunit/CRM/Contact/BAO/ContactTest.php +++ b/tests/phpunit/CRM/Contact/BAO/ContactTest.php @@ -638,14 +638,12 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { public function testDeleteContact() { $contactParams = $this->contactParams(); - //create custom data - require_once 'CiviTest/Custom.php'; - $customGroup = Custom::createGroup(array(), 'Individual'); + $customGroup = $this->customGroupCreate(); $fields = array( 'label' => 'testFld', 'data_type' => 'String', 'html_type' => 'Text', - 'custom_group_id' => $customGroup->id, + 'custom_group_id' => $customGroup['id'], ); $customField = CRM_Core_BAO_CustomField::create($fields); $contactParams['custom'] = array( @@ -654,8 +652,8 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { 'value' => 'Test custom value', 'type' => 'String', 'custom_field_id' => $customField->id, - 'custom_group_id' => $customGroup->id, - 'table_name' => $customGroup->table_name, + 'custom_group_id' => $customGroup['id'], + 'table_name' => $customGroup['values'][$customGroup['id']]['table_name'], 'column_name' => $customField->column_name, 'file_id' => NULL, ), @@ -713,7 +711,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { 'id', 'sort_name', 'Database check, contact deleted successfully.' ); $this->quickCleanup(array('civicrm_contact', 'civicrm_note')); - Custom::deleteGroup($customGroup); + $this->customGroupDelete($customGroup['id']); } /** @@ -1491,10 +1489,10 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { * Looking at it when contact-related custom data is updated. */ public function testTimestampsCustom() { - $customGroup = Custom::createGroup(array(), 'Individual'); - $this->assertNotNull($customGroup); + $customGroup = $this->customGroupCreate(); + $customGroup = $customGroup['values'][$customGroup['id']]; $fields = array( - 'custom_group_id' => $customGroup->id, + 'custom_group_id' => $customGroup['id'], 'data_type' => 'String', 'html_type' => 'Text', ); @@ -1510,13 +1508,13 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { }, 'UPDATE' => function ($contactId) use ($test, $customGroup, $customField) { CRM_Core_DAO::executeQuery( - "UPDATE {$customGroup->table_name} SET {$customField['column_name']} = 'test-2' WHERE entity_id = %1", + "UPDATE {$customGroup['table_name']} SET {$customField['column_name']} = 'test-2' WHERE entity_id = %1", array(1 => array($contactId, 'Integer')) ); }, 'DELETE' => function ($contactId) use ($test, $customGroup, $customField) { CRM_Core_DAO::executeQuery( - "DELETE FROM {$customGroup->table_name} WHERE entity_id = %1", + "DELETE FROM {$customGroup['table_name']} WHERE entity_id = %1", array(1 => array($contactId, 'Integer')) ); }, diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionPageTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionPageTest.php index a9d0f5891f..70a921b728 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionPageTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionPageTest.php @@ -25,9 +25,6 @@ +--------------------------------------------------------------------+ */ -require_once 'CiviTest/Custom.php'; -require_once 'CiviTest/PaypalPro.php'; - /** * Class CRM_Contribute_BAO_ContributionPageTest * @group headless @@ -103,16 +100,16 @@ class CRM_Contribute_BAO_ContributionPageTest extends CiviUnitTestCase { 'is_active' => 1, ); - $contributionpage = CRM_Contribute_BAO_ContributionPage::create($params); + $contributionPage = CRM_Contribute_BAO_ContributionPage::create($params); - $id = $contributionpage->id; + $id = $contributionPage->id; $values = array(); - $setValues = CRM_Contribute_BAO_ContributionPage::setValues($id, $values); + CRM_Contribute_BAO_ContributionPage::setValues($id, $values); $this->assertEquals($params['title'], $values['title'], 'Verify contribution title.'); $this->assertEquals($this->_financialTypeID, $values['financial_type_id'], 'Verify financial types id.'); $this->assertEquals(1, $values['is_active'], 'Verify contribution is_active value.'); - $this->callAPISuccess('ContributionPage', 'delete', array('id' => $contributionpage->id)); + $this->callAPISuccess('ContributionPage', 'delete', array('id' => $contributionPage->id)); } /** @@ -138,12 +135,12 @@ class CRM_Contribute_BAO_ContributionPageTest extends CiviUnitTestCase { 'is_credit_card_only' => '', ); - $contributionpage = CRM_Contribute_BAO_ContributionPage::create($params); - $copycontributionpage = CRM_Contribute_BAO_ContributionPage::copy($contributionpage->id); - $this->assertEquals($copycontributionpage->financial_type_id, $this->_financialTypeID, 'Check for Financial type id.'); - $this->assertEquals($copycontributionpage->goal_amount, 400, 'Check for goal amount.'); - $this->callAPISuccess('ContributionPage', 'delete', array('id' => $contributionpage->id)); - $this->callAPISuccess('ContributionPage', 'delete', array('id' => $copycontributionpage->id)); + $contributionPage = CRM_Contribute_BAO_ContributionPage::create($params); + $copyContributionPage = CRM_Contribute_BAO_ContributionPage::copy($contributionPage->id); + $this->assertEquals($copyContributionPage->financial_type_id, $this->_financialTypeID, 'Check for Financial type id.'); + $this->assertEquals($copyContributionPage->goal_amount, 400, 'Check for goal amount.'); + $this->callAPISuccess('ContributionPage', 'delete', array('id' => $contributionPage->id)); + $this->callAPISuccess('ContributionPage', 'delete', array('id' => $copyContributionPage->id)); } } diff --git a/tests/phpunit/CRM/Core/BAO/CustomValueTest.php b/tests/phpunit/CRM/Core/BAO/CustomValueTest.php index 86bc41d3a1..8d8c6454a9 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomValueTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomValueTest.php @@ -113,17 +113,18 @@ class CRM_Core_BAO_CustomValueTest extends CiviUnitTestCase { } public function fixCustomFieldValue() { - $customGroup = Custom::createGroup(array(), 'Individual'); + $customGroup = $this->customGroupCreate(array('extends' => 'Individual')); $fields = array( - 'groupId' => $customGroup->id, - 'dataType' => 'Memo', - 'htmlType' => 'TextArea', + 'custom_group_id' => $customGroup['id'], + 'data_type' => 'Memo', + 'html_type' => 'TextArea', + 'default_value' => '', ); - $customField = Custom::createField(array(), $fields); + $customField = $this->customFieldCreate($fields); - $custom = 'custom_' . $customField->id; + $custom = 'custom_' . $customField['id']; $params = array( 'email' => 'abc@webaccess.co.in', $custom => 'note', @@ -132,8 +133,8 @@ class CRM_Core_BAO_CustomValueTest extends CiviUnitTestCase { CRM_Core_BAO_CustomValue::fixCustomFieldValue($params); $this->assertEquals($params[$custom], '%note%', 'Checking the returned value of type Memo.'); - Custom::deleteField($customField); - Custom::deleteGroup($customGroup); + $this->customFieldDelete($customField['id']); + $this->customGroupDelete($customGroup['id']); } public function testFixCustomFieldValueWithEmptyParams() { diff --git a/tests/phpunit/CRM/Core/BAO/OptionValueTest.php b/tests/phpunit/CRM/Core/BAO/OptionValueTest.php index a13191af31..ae442c3dc7 100644 --- a/tests/phpunit/CRM/Core/BAO/OptionValueTest.php +++ b/tests/phpunit/CRM/Core/BAO/OptionValueTest.php @@ -25,8 +25,6 @@ +--------------------------------------------------------------------+ */ -require_once 'CiviTest/CiviUnitTestCase.php'; - /** * Class CRM_Core_BAO_SchemaHandlerTest. * diff --git a/tests/phpunit/CRM/Event/BAO/ParticipantTest.php b/tests/phpunit/CRM/Event/BAO/ParticipantTest.php index 3b3244149b..c0702a1fe0 100644 --- a/tests/phpunit/CRM/Event/BAO/ParticipantTest.php +++ b/tests/phpunit/CRM/Event/BAO/ParticipantTest.php @@ -234,7 +234,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { //Creating 3 new participants for ($i = 0; $i < 3; $i++) { - $partiId[] = Participant::create($this->_contactId, $this->_eventId); + $partiId[] = $this->participantCreate(array('contact_id' => $this->_contactId, 'event_id' => $this->_eventId)); } $params = array('event_id' => $this->_eventId, 'contact_id' => $this->_contactId); @@ -316,7 +316,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { } //Deleting the Participant created by create function in this function - $deleteParticipant = CRM_Event_BAO_Participant::deleteParticipant($participant->id); + CRM_Event_BAO_Participant::deleteParticipant($participant->id); $this->assertDBNull('CRM_Event_DAO_Participant', $this->_contactId, 'id', 'contact_id', 'Check DB for deleted participant. Should be NULL.' ); diff --git a/tests/phpunit/CRM/Pledge/BAO/PledgeBlockTest.php b/tests/phpunit/CRM/Pledge/BAO/PledgeBlockTest.php index a9da125fe9..e5918386aa 100644 --- a/tests/phpunit/CRM/Pledge/BAO/PledgeBlockTest.php +++ b/tests/phpunit/CRM/Pledge/BAO/PledgeBlockTest.php @@ -39,7 +39,8 @@ class CRM_Pledge_BAO_PledgeBlockTest extends CiviUnitTestCase { */ protected function setUp() { parent::setUp(); - $this->_contributionPageId = ContributionPage::create(); + $contributionPage = $this->contributionPageCreate(); + $this->_contributionPageId = $contributionPage['id']; } /** @@ -71,13 +72,13 @@ class CRM_Pledge_BAO_PledgeBlockTest extends CiviUnitTestCase { //Checking for pledgeBlock id in the Pledge_block table. $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::create($params); - $pledgeBlockId = $this->assertDBNotNull('CRM_Pledge_DAO_PledgeBlock', $pledgeBlock->id, 'id', + $this->assertDBNotNull('CRM_Pledge_DAO_PledgeBlock', $pledgeBlock->id, 'id', 'id', 'Check DB for Pledge block id' ); //Checking for pledgeBlock id after delete. CRM_Pledge_BAO_PledgeBlock::deletePledgeBlock($pledgeBlock->id); - $pledgeBlockId = $this->assertDBNull('CRM_Pledge_DAO_PledgeBlock', $pledgeBlock->id, 'id', + $this->assertDBNull('CRM_Pledge_DAO_PledgeBlock', $pledgeBlock->id, 'id', 'id', 'Check DB for Pledge block id' ); } diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 887c8066d4..27dd1118b0 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -1387,20 +1387,18 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * @return array * Array of contribution page */ - public function contributionPageCreate($params) { - $this->_pageParams = array( + public function contributionPageCreate($params = array()) { + $this->_pageParams = array_merge(array( 'title' => 'Test Contribution Page', 'financial_type_id' => 1, 'currency' => 'USD', 'financial_account_id' => 1, - 'payment_processor' => $params['processor_id'], 'is_active' => 1, 'is_allow_other_amount' => 1, 'min_amount' => 10, 'max_amount' => 1000, - ); - $contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams); - return $contributionPage; + ), $params); + return $this->callAPISuccess('contribution_page', 'create', $this->_pageParams); } /** diff --git a/tests/phpunit/CiviTest/Contact.php b/tests/phpunit/CiviTest/Contact.php deleted file mode 100644 index 5724e657bb..0000000000 --- a/tests/phpunit/CiviTest/Contact.php +++ /dev/null @@ -1,89 +0,0 @@ - $first_name, - 'last_name' => $last_name, - 'contact_source' => $contact_source, - ); - } - return self::create($params); - } - - /** - * Helper function to create - * a contact of type Household - * - * @param array $params - * @return int - * id of created Household - */ - public static function createHousehold($params = NULL) { - //compose the params, when not passed - if (!$params) { - $household_name = "John Doe's home"; - $params = array( - 'household_name' => $household_name, - 'contact_type' => 'Household', - ); - } - require_once "CRM/Contact/BAO/Contact.php"; - $household = CRM_Contact_BAO_Contact::create($params); - return $household->id; - } - - /** - * Helper function to create - * a contact of type Organisation - * - * @param array $params - * @return int - * id of created Organisation - */ - public static function createOrganisation($params = NULL) { - //compose the params, when not passed - if (!$params) { - $organization_name = "My Organization"; - $params = array( - 'organization_name' => $organization_name, - 'contact_type' => 'Organization', - ); - } - require_once "CRM/Contact/BAO/Contact.php"; - $organization = CRM_Contact_BAO_Contact::create($params); - return $organization->id; - } - -} diff --git a/tests/phpunit/CiviTest/ContributionPage.php b/tests/phpunit/CiviTest/ContributionPage.php deleted file mode 100644 index 7c1cc1930b..0000000000 --- a/tests/phpunit/CiviTest/ContributionPage.php +++ /dev/null @@ -1,61 +0,0 @@ - 'Help Test CiviCRM!', - 'intro_text' => 'Created for Test Coverage Online Contribution Page', - 'financial_type_id' => 1, - 'payment_processor_id' => $id, - 'is_monetary' => 1, - 'is_allow_other_amount' => 1, - 'min_amount' => 10, - 'max_amount' => 10000, - 'goal_amount' => 100000, - 'thankyou_title' => 'Thank you for your support!', - 'thankyou_text' => 'Thank you for your support.', - 'is_email_receipt' => 1, - 'receipt_from_name' => 'From TEST', - 'receipt_from_email' => 'donations@civicrm.org', - 'cc_receipt' => 'receipt@example.com', - 'bcc_receipt' => 'bcc@example.com', - 'is_active' => 1, - ); - - $contributionPage = CRM_Contribute_BAO_ContributionPage::create($params); - return $contributionPage->id; - } - - /** - * Helper function to delete a Contribution Page. - * - * @param int $contributionPageId - * Id of the Contribution Page. - * to be deleted - * @return bool - * true if Contribution Page deleted, false otherwise - */ - public static function delete($contributionPageId) { - require_once "CRM/Contribute/DAO/ContributionPage.php"; - $cp = new CRM_Contribute_DAO_ContributionPage(); - $cp->id = $contributionPageId; - if ($cp->find(TRUE)) { - $result = $cp->delete(); - } - return $result; - } - -} diff --git a/tests/phpunit/CiviTest/Custom.php b/tests/phpunit/CiviTest/Custom.php deleted file mode 100644 index 73076f7a5d..0000000000 --- a/tests/phpunit/CiviTest/Custom.php +++ /dev/null @@ -1,127 +0,0 @@ - 'Test_Group', - 'name' => 'test_group', - 'extends' => $extends, - 'style' => 'Inline', - 'is_multiple' => $isMultiple, - 'is_active' => 1, - 'version' => 3, - ); - } - else { - // this is done for backward compatibility - // with tests older than 3.2.3 - if (isset($group['extends']) && - !is_array($group['extends']) - ) { - $group['extends'] = array($group['extends']); - } - } - - $result = civicrm_api('custom_group', 'create', $group); - - if ($result['is_error']) { - return NULL; - } - - // this is done for backward compatibility - // with tests older than 3.2.3 - require_once 'CRM/Core/BAO/CustomGroup.php'; - $group = new CRM_Core_BAO_CustomGroup(); - $group->id = $result['id']; - $group->find(TRUE); - - return $group; - } - - /** - * Helper function to create Custom Field. - * @deprecated use parent object create fn - * @param array $params - * @param null $fields - * @return object - * of created field - */ - public static function createField($params, $fields = NULL) { - if (empty($params)) { - $params = array( - 'custom_group_id' => $fields['groupId'], - 'label' => empty($fields['label']) ? 'test_' . CRM_Utils_Array::value('dataType', $fields) : $fields['label'], - 'html_type' => CRM_Utils_Array::value('htmlType', $fields), - 'data_type' => CRM_Utils_Array::value('dataType', $fields), - 'weight' => 4, - 'is_required' => 1, - 'is_searchable' => 0, - 'is_active' => 1, - 'version' => 3, - ); - } - - $result = civicrm_api('custom_field', 'create', $params); - - if ($result['is_error']) { - print_r($result); - return NULL; - } - - // this is done for backward compatibility - // with tests older than 3.2.3 - $customField = new CRM_Core_DAO_CustomField(); - $customField->id = $result['id']; - $customField->find(TRUE); - - return $customField; - } - - /** - * Helper function to delete custom field. - * - * @deprecated use function on parent class - * - * @param $params - */ - public static function deleteField($params) { - CRM_Core_BAO_CustomField::deleteField($params); - } - - /** - * Helper function to delete custom group. - * - * @deprecated use function on parent class - * - * @param $params - * - * @return bool - * true if Group deleted, false otherwise - */ - public static function deleteGroup($params) { - $deleteCustomGroup = CRM_Core_BAO_CustomGroup::deleteGroup($params, TRUE); - return $deleteCustomGroup; - } - -} diff --git a/tests/phpunit/CiviTest/Event.php b/tests/phpunit/CiviTest/Event.php deleted file mode 100644 index a8d8ce6e34..0000000000 --- a/tests/phpunit/CiviTest/Event.php +++ /dev/null @@ -1,47 +0,0 @@ - 'Test Event', - 'event_type_id' => 1, - 'default_role_id' => 1, - 'participant_listing_id' => 1, - 'summary' => 'Created for Test Coverage BAO', - 'description' => 'Test Coverage BAO', - 'is_public' => 1, - 'start_date' => '20080526200000', - 'end_date' => '20080530200000', - 'is_active' => 1, - 'contact_id' => $contactId, - ); - - $event = CRM_Event_BAO_Event::create($params); - return $event->id; - } - - /** - * Helper function to delete an Event. - * - * @param int $eventId - * @return bool - * true if event deleted, false otherwise - */ - public static function delete($eventId) { - return CRM_Event_BAO_Event::del($eventId); - } - -} diff --git a/tests/phpunit/CiviTest/Participant.php b/tests/phpunit/CiviTest/Participant.php deleted file mode 100644 index fd60bcf54b..0000000000 --- a/tests/phpunit/CiviTest/Participant.php +++ /dev/null @@ -1,46 +0,0 @@ - 1, - 'is_test' => 0, - 'is_pay_later' => 0, - 'event_id' => $eventId, - 'register_date' => date('Y-m-d') . " 00:00:00", - 'role_id' => 1, - 'status_id' => 1, - 'source' => 'Event_' . $eventId, - 'contact_id' => $contactId, - ); - - require_once 'CRM/Event/BAO/Participant.php'; - $participant = CRM_Event_BAO_Participant::add($params); - return $participant->id; - } - - /** - * Helper function to delete a participant. - * - * @param int $participantId - * @return bool - * true if participant deleted, false otherwise - */ - public static function delete($participantId) { - require_once 'CRM/Event/BAO/Participant.php'; - return CRM_Event_BAO_Participant::deleteParticipant($participantId); - } - -} diff --git a/tests/phpunit/CiviTest/PaypalPro.php b/tests/phpunit/CiviTest/PaypalPro.php deleted file mode 100644 index e9fd1c8ada..0000000000 --- a/tests/phpunit/CiviTest/PaypalPro.php +++ /dev/null @@ -1,60 +0,0 @@ - 'demo', - 'domain_id' => CRM_Core_Config::domainID(), - 'payment_processor_type' => 'PayPal', - 'is_active' => 1, - 'is_default' => 0, - 'is_test' => 1, - 'user_name' => 'sunil._1183377782_biz_api1.webaccess.co.in', - 'password' => '1183377788', - 'signature' => 'APixCoQ-Zsaj-u3IH7mD5Do-7HUqA9loGnLSzsZga9Zr-aNmaJa3WGPH', - 'url_site' => 'https://www.sandbox.paypal.com/', - 'url_api' => 'https://api-3t.sandbox.paypal.com/', - 'url_button' => 'https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif', - 'class_name' => 'Payment_PayPalImpl', - 'billing_mode' => 3, - 'financial_type_id' => 1, - ); - $paymentProcessor->copyValues($paymentParams); - $paymentProcessor->save(); - return $paymentProcessor->id; - } - - /** - * Helper function to delete a PayPal Pro - * payment processor - * @param int $id - * Id of the PayPal Pro payment processor. - * to be deleted - * @return bool - * true if payment processor deleted, false otherwise - */ - public static function delete($id) { - $pp = new CRM_Financial_DAO_PaymentProcessor(); - $pp->id = $id; - if ($pp->find(TRUE)) { - $result = $pp->delete(); - } - return $result; - } - -} -- 2.25.1