From: eileen Date: Wed, 6 Jul 2016 00:20:24 +0000 (+1200) Subject: [NFC] CRM-19033 improve standardisation of tests X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e4649817ad1ee12463428c47d0fb2dd619a1c5f9;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/Member/BAO/MembershipTest.php b/tests/phpunit/CRM/Member/BAO/MembershipTest.php index 2e69855a14..b1df70a3d5 100644 --- a/tests/phpunit/CRM/Member/BAO/MembershipTest.php +++ b/tests/phpunit/CRM/Member/BAO/MembershipTest.php @@ -413,37 +413,27 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { /** - * Take sort name of contact during - * Update multiple memberships + * Checkup sort name function. */ - public function testsortName() { - $contactId = Contact::createIndividual(); + public function testSortName() { + $contactId = $this->individualCreate(); $params = array( 'contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, - 'join_date' => date('Ymd', strtotime('2006-01-21')), - 'start_date' => date('Ymd', strtotime('2006-01-21')), - 'end_date' => date('Ymd', strtotime('2006-12-21')), + 'join_date' => '2006-01-21', + 'start_date' => '2006-01-21', + 'end_date' => '2006-12-21', 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID, ); - $ids = array(); - - CRM_Member_BAO_Membership::create($params, $ids); - - $membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', - 'contact_id', 'Database check for created membership.' - ); - CRM_Member_BAO_Membership::sortName($membershipId); + $membership = $this->callAPISuccess('Membership', 'create', $params); - $this->assertDBCompareValue('CRM_Contact_DAO_Contact', $contactId, 'sort_name', 'id', 'Doe, John', - 'Database check for sort name record.' - ); + $this->assertEquals('Anderson, Anthony', CRM_Member_BAO_Membership::sortName($membership['id'])); - $this->membershipDelete($membershipId); + $this->membershipDelete($membership['id']); $this->contactDelete($contactId); } @@ -451,7 +441,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { * Delete related memberships. */ public function testdeleteRelatedMemberships() { - $contactId = Contact::createIndividual(); + $contactId = $this->individualCreate(); $params = array( 'contact_id' => $contactId, @@ -481,7 +471,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { * Renew membership with change in membership type. */ public function testRenewMembership() { - $contactId = Contact::createIndividual(); + $contactId = $this->individualCreate(); $joinDate = $startDate = date("Ymd", strtotime(date("Ymd") . " -6 month")); $endDate = date("Ymd", strtotime($joinDate . " +1 year -1 day")); $params = array( @@ -548,7 +538,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { */ public function testStaleMembership() { $statusId = 3; - $contactId = Contact::createIndividual(); + $contactId = $this->individualCreate(); $joinDate = $startDate = date("Ymd", strtotime(date("Ymd") . " -1 year -15 days")); $endDate = date("Ymd", strtotime($joinDate . " +1 year -1 day")); $params = array( diff --git a/tests/phpunit/CRM/Pledge/BAO/PledgeTest.php b/tests/phpunit/CRM/Pledge/BAO/PledgeTest.php index d2c66c3653..255ba30ced 100644 --- a/tests/phpunit/CRM/Pledge/BAO/PledgeTest.php +++ b/tests/phpunit/CRM/Pledge/BAO/PledgeTest.php @@ -39,7 +39,7 @@ class CRM_Pledge_BAO_PledgeTest extends CiviUnitTestCase { */ protected function setUp() { parent::setUp(); - $this->_contactId = Contact::createIndividual(); + $this->_contactId = $this->individualCreate(); } /** diff --git a/tests/phpunit/api/v3/CRM11793Test.php b/tests/phpunit/api/v3/CRM11793Test.php index f7dc52b00e..61484322fe 100644 --- a/tests/phpunit/api/v3/CRM11793Test.php +++ b/tests/phpunit/api/v3/CRM11793Test.php @@ -19,15 +19,11 @@ class api_v3_CRM11793Test extends CiviUnitTestCase { * and redirect stdin to a temporary file */ public function setUp() { - // Connect to the database parent::setUp(); - require_once 'CiviTest/Contact.php'; - - // lets create one contact of each type - Contact::createIndividual(); - Contact::createHousehold(); - Contact::createOrganisation(); + $this->individualCreate(); + $this->householdCreate(); + $this->organizationCreate(); } public function tearDown() { diff --git a/tests/phpunit/api/v3/OrderTest.php b/tests/phpunit/api/v3/OrderTest.php index 21a174bf08..bad591ec2a 100644 --- a/tests/phpunit/api/v3/OrderTest.php +++ b/tests/phpunit/api/v3/OrderTest.php @@ -99,7 +99,7 @@ class api_v3_OrderTest extends CiviUnitTestCase { * Test Get Order api for participant contribution. */ public function testGetOrderParticipant() { - $contribution = $this->addOrder(FALSE, 100); + $this->addOrder(FALSE, 100); list($items, $contribution) = $this->createParticipantWithContribution(); $params = array( @@ -115,7 +115,7 @@ class api_v3_OrderTest extends CiviUnitTestCase { } /** - * Function to assert db values + * Function to assert db values. */ public function checkPaymentResult($results, $expectedResult, $lineItems = NULL) { foreach ($expectedResult[$results['id']] as $key => $value) { @@ -132,7 +132,7 @@ class api_v3_OrderTest extends CiviUnitTestCase { } /** - * add order + * Add order. * * @param bool $isPriceSet * @param float $amount @@ -140,7 +140,7 @@ class api_v3_OrderTest extends CiviUnitTestCase { * * @return array */ - public function addOrder($isPriceSet, $amount = 300, $extraParams = array()) { + public function addOrder($isPriceSet, $amount = 300.00, $extraParams = array()) { $p = array( 'contact_id' => $this->_individualId, 'receive_date' => '2010-01-20', @@ -204,11 +204,9 @@ class api_v3_OrderTest extends CiviUnitTestCase { * Test create order api for membership */ public function testAddOrderForMembership() { - require_once 'CiviTest/Membership.php'; - $membership = new Membership(); - $membershipType = $membership->createMembershipType(); - $membershipType1 = $membership->createMembershipType(); - $membershipType = $membershipTypes = array($membershipType->id, $membershipType1->id); + $membershipType = $this->membershipTypeCreate(); + $membershipType1 = $this->membershipTypeCreate(); + $membershipType = $membershipTypes = array($membershipType, $membershipType1); $p = array( 'contact_id' => $this->_individualId, 'receive_date' => '2010-01-20', @@ -298,9 +296,9 @@ class api_v3_OrderTest extends CiviUnitTestCase { /** * Test create order api for participant */ - public function testAddOrderForPariticipant() { - require_once 'CiviTest/Event.php'; - $this->_eventId = Event::create($this->_individualId); + public function testAddOrderForParticipant() { + $event = $this->eventCreate(); + $this->_eventId = $event['id']; $p = array( 'contact_id' => $this->_individualId, 'receive_date' => '2010-01-20', @@ -485,7 +483,8 @@ class api_v3_OrderTest extends CiviUnitTestCase { * Test cancel order api */ public function testCancelWithParticipant() { - $this->_eventId = Event::create($this->_individualId); + $event = $this->eventCreate(); + $this->_eventId = $event['id']; $eventParams = array( 'id' => $this->_eventId, 'financial_type_id' => 4,