From: eileen Date: Tue, 5 Jul 2016 23:09:46 +0000 (+1200) Subject: [NFC] CRM-19033 improve standardisation of tests X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6ae19242ee2b9d90e853248ae586f8727b1f61b6;p=civicrm-core.git [NFC] CRM-19033 improve standardisation of tests NB jenkins is doing wierd things here so trying a small subset to see what jenkins does --- diff --git a/tests/phpunit/CRM/Core/BAO/LocationTest.php b/tests/phpunit/CRM/Core/BAO/LocationTest.php index 2b541ae476..53f8371655 100644 --- a/tests/phpunit/CRM/Core/BAO/LocationTest.php +++ b/tests/phpunit/CRM/Core/BAO/LocationTest.php @@ -209,9 +209,8 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { * with civicrm_loc_block */ public function testCreateWithLocBlock() { - $this->_contactId = Contact::createIndividual(); - //create test event record. - $eventId = Event::create($this->_contactId); + $this->_contactId = $this->individualCreate(); + $event = $this->eventCreate(); $params = array( 'address' => array( '1' => array( @@ -258,7 +257,7 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { ), ); - $params['entity_id'] = $eventId; + $params['entity_id'] = $event['id']; $params['entity_table'] = 'civicrm_event'; //create location block. @@ -269,7 +268,7 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { //update event record with location block id $eventParams = array( - 'id' => $eventId, + 'id' => $event['id'], 'loc_block_id' => $locBlockId, ); @@ -278,7 +277,7 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { //Now check DB for location block $this->assertDBCompareValue('CRM_Event_DAO_Event', - $eventId, + $event['id'], 'loc_block_id', 'id', $locBlockId, @@ -346,11 +345,9 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { ); $this->assertDBCompareValues('CRM_Core_DAO_IM', $searchParams, $compareParams); - //delete the location block + // Cleanup. CRM_Core_BAO_Location::deleteLocBlock($locBlockId); - - //cleanup DB by deleting the record. - Event::delete($eventId); + $this->eventDelete($event['id']); $this->contactDelete($this->_contactId); } @@ -360,9 +357,9 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { * created with various elements. */ public function testDeleteLocBlock() { - $this->_contactId = Contact::createIndividual(); + $this->_contactId = $this->individualCreate(); //create test event record. - $eventId = Event::create($this->_contactId); + $event = $this->eventCreate(); $params['location'][1] = array( 'location_type_id' => 1, 'is_primary' => 1, @@ -397,7 +394,7 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { ), ), ); - $params['entity_id'] = $eventId; + $params['entity_id'] = $event['id']; $params['entity_table'] = 'civicrm_event'; //create location block. @@ -407,7 +404,7 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { $locBlockId = CRM_Utils_Array::value('id', $location); //update event record with location block id $eventParams = array( - 'id' => $eventId, + 'id' => $event['id'], 'loc_block_id' => $locBlockId, ); CRM_Event_BAO_Event::add($eventParams); @@ -438,11 +435,11 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { ); //cleanup DB by deleting the record. - Event::delete($eventId); + $this->eventDelete($event['id']); $this->contactDelete($this->_contactId); //Now check DB for Event - $this->assertDBNull('CRM_Event_DAO_Event', $eventId, 'id', 'id', + $this->assertDBNull('CRM_Event_DAO_Event', $event['id'], 'id', 'id', 'Database check, Event deleted successfully.' ); } @@ -452,7 +449,7 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { * get the values of various location elements */ public function testLocBlockgetValues() { - $contactId = Contact::createIndividual(); + $contactId = $this->individualCreate(); //create various element of location block //like address, phone, email, openid, im. diff --git a/tests/phpunit/CRM/Core/BAO/OpenIDTest.php b/tests/phpunit/CRM/Core/BAO/OpenIDTest.php index 3531bc8293..765aedc4fe 100644 --- a/tests/phpunit/CRM/Core/BAO/OpenIDTest.php +++ b/tests/phpunit/CRM/Core/BAO/OpenIDTest.php @@ -23,7 +23,7 @@ class CRM_Core_BAO_OpenIDTest extends CiviUnitTestCase { * Add() method (create and update modes) */ public function testAdd() { - $contactId = Contact::createIndividual(); + $contactId = $this->individualCreate(); $this->assertDBRowExist('CRM_Contact_DAO_Contact', $contactId); $openIdURL = "http://test-username.civicrm.org/"; @@ -67,7 +67,7 @@ class CRM_Core_BAO_OpenIDTest extends CiviUnitTestCase { * IfAllowedToLogin() method (set and reset allowed_to_login) */ public function testIfAllowedToLogin() { - $contactId = Contact::createIndividual(); + $contactId = $this->individualCreate(); $this->assertDBRowExist('CRM_Contact_DAO_Contact', $contactId); $openIdURL = "http://test-username.civicrm.org/"; @@ -112,7 +112,7 @@ class CRM_Core_BAO_OpenIDTest extends CiviUnitTestCase { * AllOpenIDs() method - get all OpenIDs for the given contact */ public function testAllOpenIDs() { - $contactId = Contact::createIndividual(); + $contactId = $this->individualCreate(); $this->assertDBRowExist('CRM_Contact_DAO_Contact', $contactId); // create first openid diff --git a/tests/phpunit/CRM/Core/BAO/PhoneTest.php b/tests/phpunit/CRM/Core/BAO/PhoneTest.php index 4f1779cd14..3a6dfcbf74 100644 --- a/tests/phpunit/CRM/Core/BAO/PhoneTest.php +++ b/tests/phpunit/CRM/Core/BAO/PhoneTest.php @@ -39,7 +39,7 @@ class CRM_Core_BAO_PhoneTest extends CiviUnitTestCase { * Add() method (create and update modes) */ public function testAdd() { - $contactId = Contact::createIndividual(); + $contactId = $this->individualCreate(); $params = array(); $params = array( @@ -79,17 +79,17 @@ class CRM_Core_BAO_PhoneTest extends CiviUnitTestCase { } /** - * AllPhones() method - get all Phones for our contact, with primary Phone first + * AllPhones() method - get all Phones for our contact, with primary Phone first. */ public function testAllPhones() { $contactParams = array( 'first_name' => 'Alan', 'last_name' => 'Smith', - 'phone-1' => '(415) 222-1011 x 221', - 'phone-2' => '(415) 222-5432', + 'api.phone.create' => array('phone' => '(415) 222-1011 x 221', 'location_type_id' => 'Home'), + 'api.phone.create.1' => array('phone' => '(415) 222-5432', 'location_type_id' => 'Work'), ); - $contactId = Contact::createIndividual($contactParams); + $contactId = $this->individualCreate($contactParams); $Phones = CRM_Core_BAO_Phone::allPhones($contactId); diff --git a/tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php b/tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php index e23e45b71c..9ac09f148f 100644 --- a/tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php +++ b/tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php @@ -33,8 +33,9 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); - $this->_contactId = Contact::createIndividual(); - $this->_eventId = Event::create($this->_contactId); + $this->_contactId = $this->individualCreate(); + $event = $this->eventCreate(); + $this->_eventId = $event['id']; } public function tearDown() { diff --git a/tests/phpunit/CRM/Event/BAO/ParticipantTest.php b/tests/phpunit/CRM/Event/BAO/ParticipantTest.php index 858be899c5..3b3244149b 100644 --- a/tests/phpunit/CRM/Event/BAO/ParticipantTest.php +++ b/tests/phpunit/CRM/Event/BAO/ParticipantTest.php @@ -33,8 +33,9 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); - $this->_contactId = Contact::createIndividual(); - $this->_eventId = Event::create($this->_contactId); + $this->_contactId = $this->individualCreate(); + $event = $this->eventCreate(); + $this->_eventId = $event['id']; } /** @@ -81,14 +82,14 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { ); $this->contactDelete($this->_contactId); - Event::delete($this->_eventId); + $this->eventDelete($this->_eventId); } /** * GetValues() method (fetch value of participant) */ public function testgetValuesWithValidParams() { - $participantId = Participant::create($this->_contactId, $this->_eventId); + $participantId = $this->participantCreate(array('contact_id' => $this->_contactId, 'event_id' => $this->_eventId)); $params = array('id' => $participantId); $values = $ids = array(); @@ -100,10 +101,10 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { 'is_test' => 0, 'is_pay_later' => 0, 'event_id' => $this->_eventId, - 'register_date' => date('Y-m-d') . " 00:00:00", + 'register_date' => '2007-02-19 00:00:00', 'role_id' => 1, - 'status_id' => 1, - 'source' => 'Event_' . $this->_eventId, + 'status_id' => 2, + 'source' => 'Wimbeldon', 'contact_id' => $this->_contactId, 'id' => $participantId, 'campaign_id' => NULL, @@ -115,7 +116,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { 'discount_amount' => NULL, 'cart_id' => NULL, 'must_wait' => NULL, - 'transferred_to_contact_id' => NULL, //CRM-16761 + 'transferred_to_contact_id' => NULL, ); foreach ($compareValues as $key => $value) { @@ -124,9 +125,9 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { } } - Participant::delete($participantId); + $this->participantDelete($participantId); $this->contactDelete($this->_contactId); - Event::delete($this->_eventId); + $this->eventDelete($this->_eventId); } /** @@ -134,12 +135,12 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { */ public function testgetValuesWithoutValidParams() { $params = $values = $ids = array(); - Participant::create($this->_contactId, $this->_eventId); + $this->participantCreate(array('contact_id' => $this->_contactId, 'event_id' => $this->_eventId)); $fetchParticipant = CRM_Event_BAO_Participant::getValues($params, $values, $ids); $this->assertNull($fetchParticipant); $this->contactDelete($this->_contactId); - Event::delete($this->_eventId); + $this->eventDelete($this->_eventId); } /** @@ -152,14 +153,14 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { ); CRM_Event_BAO_Event::add($eventParams); - $participantId = Participant::create($this->_contactId, $this->_eventId); + $participantId = $this->participantCreate(array('contact_id' => $this->_contactId, 'event_id' => $this->_eventId)); $eventFull = CRM_Event_BAO_Participant::eventFull($this->_eventId); - $this->assertEquals($eventFull, 'This event is full.', 'Checking if Event is full.'); + $this->assertEquals($eventFull, 'Sorry! We are already full', 'Checking if Event is full.'); - Participant::delete($participantId); + $this->participantDelete($participantId); $this->contactDelete($this->_contactId); - Event::delete($this->_eventId); + $this->eventDelete($this->_eventId); } /** @@ -170,25 +171,25 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { $this->assertNotEquals(count($importableFields), 0, 'Checking array not to be empty.'); $this->contactDelete($this->_contactId); - Event::delete($this->_eventId); + $this->eventDelete($this->_eventId); } /** * ParticipantDetails() method ( Checking the Participant Details ) */ public function testparticipantDetails() { - $participantId = Participant::create($this->_contactId, $this->_eventId); - $params = array('name' => 'Doe, John', 'title' => 'Test Event'); + $participant = $this->callAPISuccess('Participant', 'create', array('contact_id' => $this->_contactId, 'event_id' => $this->_eventId)); + $params = array('name' => 'Anderson, Anthony', 'title' => 'Annual CiviCRM meet'); - $participantDetails = CRM_Event_BAO_Participant::participantDetails($participantId); + $participantDetails = CRM_Event_BAO_Participant::participantDetails($participant['id']); $this->assertEquals(count($participantDetails), 3, 'Equating the array contains.'); $this->assertEquals($participantDetails['name'], $params['name'], 'Checking Name of Participant.'); $this->assertEquals($participantDetails['title'], $params['title'], 'Checking Event Title in which participant is enroled.'); - Participant::delete($participantId); + $this->participantDelete($participant['id']); $this->contactDelete($this->_contactId); - Event::delete($this->_eventId); + $this->eventDelete($this->_eventId); } /** @@ -222,7 +223,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { $this->assertDBNull('CRM_Event_BAO_Participant', $participant->id, 'contact_id', 'id', 'Check DB for deleted Participant.'); $this->contactDelete($this->_contactId); - Event::delete($this->_eventId); + $this->eventDelete($this->_eventId); } /** @@ -237,7 +238,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { } $params = array('event_id' => $this->_eventId, 'contact_id' => $this->_contactId); - $checkDuplicate = CRM_Event_BAO_Participant::checkDuplicate($params, $duplicate); + CRM_Event_BAO_Participant::checkDuplicate($params, $duplicate); $this->assertEquals(count($duplicate), 3, 'Equating the array contains with duplicate array.'); @@ -248,11 +249,11 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { //Deleting all participant for ($i = 0; $i < 3; $i++) { - $partidel[] = Participant::delete($partiId[$i]); + $partidel[] = $this->participantDelete($partiId[$i]); } $this->contactDelete($this->_contactId); - Event::delete($this->_eventId); + $this->eventDelete($this->_eventId); } /** @@ -321,7 +322,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { ); $this->contactDelete($this->_contactId); - Event::delete($this->_eventId); + $this->eventDelete($this->_eventId); } /** @@ -332,7 +333,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { $this->assertNotEquals(count($exportableFields), 0, 'Checking array not to be empty.'); $this->contactDelete($this->_contactId); - Event::delete($this->_eventId); + $this->eventDelete($this->_eventId); } /** @@ -421,9 +422,9 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { 'id', 'Check DB for non-existence of Price Set.' ); - Participant::delete($participant->id); + $this->participantDelete($participant->id); $this->contactDelete($this->_contactId); - Event::delete($eventId); + $this->eventDelete($eventId); } } diff --git a/tests/phpunit/CRM/Financial/BAO/FinancialTypeTest.php b/tests/phpunit/CRM/Financial/BAO/FinancialTypeTest.php index 6ab8786948..2ec30f8f5c 100644 --- a/tests/phpunit/CRM/Financial/BAO/FinancialTypeTest.php +++ b/tests/phpunit/CRM/Financial/BAO/FinancialTypeTest.php @@ -229,7 +229,7 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase { * Check method testcheckPermissionedLineItems() */ public function testcheckPermissionedLineItems() { - $contactId = Contact::createIndividual(); + $contactId = $this->individualCreate(); $paramsSet['title'] = 'Price Set' . substr(sha1(rand()), 0, 4); $paramsSet['name'] = CRM_Utils_String::titleToVar($paramsSet['title']); $paramsSet['is_active'] = TRUE; diff --git a/tests/phpunit/CRM/Member/BAO/MembershipLogTest.php b/tests/phpunit/CRM/Member/BAO/MembershipLogTest.php index 9e0b1c2469..7c1fda9927 100644 --- a/tests/phpunit/CRM/Member/BAO/MembershipLogTest.php +++ b/tests/phpunit/CRM/Member/BAO/MembershipLogTest.php @@ -79,7 +79,7 @@ class CRM_Member_BAO_MembershipLogTest extends CiviUnitTestCase { * Test add() */ public function testadd() { - $contactId = Contact::createIndividual(); + $contactId = $this->individualCreate(); $params = array( 'contact_id' => $contactId, @@ -107,7 +107,7 @@ class CRM_Member_BAO_MembershipLogTest extends CiviUnitTestCase { * Test del() */ public function testdel() { - $contactId = Contact::createIndividual(); + $contactId = $this->individualCreate(); $params = array( 'contact_id' => $contactId, @@ -136,7 +136,7 @@ class CRM_Member_BAO_MembershipLogTest extends CiviUnitTestCase { * Test resetmodified() */ public function testresetmodifiedId() { - $contactId = Contact::createIndividual(); + $contactId = $this->individualCreate(); $params = array( 'contact_id' => $contactId, diff --git a/tests/phpunit/CRM/Member/BAO/MembershipTest.php b/tests/phpunit/CRM/Member/BAO/MembershipTest.php index e5eca8705a..2e69855a14 100644 --- a/tests/phpunit/CRM/Member/BAO/MembershipTest.php +++ b/tests/phpunit/CRM/Member/BAO/MembershipTest.php @@ -70,7 +70,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { public function testCreate() { - $contactId = Contact::createIndividual(); + $contactId = $this->individualCreate(); $params = array( 'contact_id' => $contactId, @@ -125,7 +125,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { $last_month = $now - (30 * 24 * 60 * 60); $year_from_last_month = $last_month + (365 * 24 * 60 * 60); - $contactId = Contact::createIndividual(); + $contactId = $this->individualCreate(); $params = array( 'contact_id' => $contactId, @@ -176,7 +176,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { } public function testRetrieve() { - $contactId = Contact::createIndividual(); + $contactId = $this->individualCreate(); $params = array( 'contact_id' => $contactId, @@ -204,7 +204,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { } public function testActiveMembers() { - $contactId = Contact::createIndividual(); + $contactId = $this->individualCreate(); $params = array( 'contact_id' => $contactId, @@ -264,7 +264,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { } public function testDeleteMembership() { - $contactId = Contact::createIndividual(); + $contactId = $this->individualCreate(); $params = array( 'contact_id' => $contactId, @@ -291,7 +291,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { } public function testGetContactMembership() { - $contactId = Contact::createIndividual(); + $contactId = $this->individualCreate(); $params = array( 'contact_id' => $contactId, @@ -324,7 +324,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { * page id from the membership record */ public function testgetContributionPageId() { - $contactId = Contact::createIndividual(); + $contactId = $this->individualCreate(); $params = array( 'contact_id' => $contactId, @@ -354,7 +354,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { * type. */ public function testgetMembershipStarts() { - $contactId = Contact::createIndividual(); + $contactId = $this->individualCreate(); $params = array( 'contact_id' => $contactId, @@ -385,7 +385,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { * optionally for a specified date. */ public function testGetMembershipCount() { - $contactId = Contact::createIndividual(); + $contactId = $this->individualCreate(); $params = array( 'contact_id' => $contactId,