From 6d6dc88586b65b4a919085ef31fe0bc53454256a Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 4 Feb 2015 11:17:48 +1300 Subject: [PATCH] minor tidy-ups --- tests/phpunit/api/v3/APITest.php | 16 ++-- tests/phpunit/api/v3/CaseTypeTest.php | 37 ++++----- tests/phpunit/api/v3/JobTest.php | 16 ++-- tests/phpunit/api/v3/MailingContactTest.php | 76 ++++++++++--------- .../api/v3/Generic/ExampleAction2.php | 4 +- .../v3/dataset/resolver/api/v3/TestEntity.php | 2 + 6 files changed, 83 insertions(+), 68 deletions(-) diff --git a/tests/phpunit/api/v3/APITest.php b/tests/phpunit/api/v3/APITest.php index 5c21a9d55a..2b92c6fc47 100644 --- a/tests/phpunit/api/v3/APITest.php +++ b/tests/phpunit/api/v3/APITest.php @@ -29,7 +29,7 @@ require_once 'CiviTest/CiviUnitTestCase.php'; /** - * Test class for API functions + * Test class for API functions. * * @package CiviCRM_APIv3 */ @@ -81,16 +81,19 @@ class api_v3_APITest extends CiviUnitTestCase { } public function testAPIWrapperCamelCaseFunction() { - $result = $this->callAPISuccess('OptionGroup', 'Get', array()); + $this->callAPISuccess('OptionGroup', 'Get', array()); } public function testAPIWrapperLcaseFunction() { - $result = $this->callAPISuccess('OptionGroup', 'get', array()); + $this->callAPISuccess('OptionGroup', 'get', array()); } + /** + * Test resolver. + */ public function testAPIResolver() { - $oldpath = get_include_path(); - set_include_path($oldpath . PATH_SEPARATOR . dirname(__FILE__) . '/dataset/resolver'); + $oldPath = get_include_path(); + set_include_path($oldPath . PATH_SEPARATOR . dirname(__FILE__) . '/dataset/resolver'); $result = $this->callAPISuccess('contact', 'example_action1', array()); $this->assertEquals($result['values'][0], 'civicrm_api3_generic_example_action1 is ok'); @@ -99,7 +102,7 @@ class api_v3_APITest extends CiviUnitTestCase { $result = $this->callAPISuccess('test_entity', 'example_action3', array()); $this->assertEquals($result['values'][0], 'civicrm_api3_test_entity_example_action3 is ok'); - set_include_path($oldpath); + set_include_path($oldPath); } public function testFromCamel() { @@ -127,7 +130,6 @@ class api_v3_APITest extends CiviUnitTestCase { 'optionValue' => 'OptionValue', 'option_value' => 'OptionValue', 'UFJoin' => 'UFJoin', - // dommage 'ufJoin' => 'UFJoin', 'uf_join' => 'UFJoin', ); foreach ($cases as $input => $expected) { diff --git a/tests/phpunit/api/v3/CaseTypeTest.php b/tests/phpunit/api/v3/CaseTypeTest.php index 0a2522eb7a..cc3284cf2a 100644 --- a/tests/phpunit/api/v3/CaseTypeTest.php +++ b/tests/phpunit/api/v3/CaseTypeTest.php @@ -64,6 +64,7 @@ class api_v3_CaseTypeTest extends CiviCaseTestCase { /** * Tears down the fixture, for example, closes a network connection. + * * This method is called after a test is executed. */ public function tearDown() { @@ -72,14 +73,14 @@ class api_v3_CaseTypeTest extends CiviCaseTestCase { } /** - * Check with empty array + * Check with empty array. */ public function testCaseTypeCreateEmpty() { $this->callAPIFailure('CaseType', 'create', array()); } /** - * Check if required fields are not passed + * Check if required fields are not passed. */ public function testCaseTypeCreateWithoutRequired() { $params = array( @@ -95,11 +96,12 @@ class api_v3_CaseTypeTest extends CiviCaseTestCase { } /** - * Test create methods with valid data - * success expected + * Test create methods with valid data. + * + * Success expected. */ public function testCaseTypeCreate() { - // Create Case Type + // Create Case Type. $params = array( 'title' => 'Application', 'name' => 'Application', @@ -110,14 +112,14 @@ class api_v3_CaseTypeTest extends CiviCaseTestCase { $result = $this->callAPISuccess('CaseType', 'create', $params); $id = $result['id']; - // Check result + // Check result. $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id)); $this->assertEquals($result['values'][$id]['id'], $id, 'in line ' . __LINE__); $this->assertEquals($result['values'][$id]['title'], $params['title'], 'in line ' . __LINE__); } /** - * Create a case with an invalid name + * Create a case with an invalid name. */ public function testCaseTypeCreate_invalidName() { // Create Case Type @@ -133,7 +135,7 @@ class api_v3_CaseTypeTest extends CiviCaseTestCase { /** - * Test update (create with id) function with valid parameters + * Test update (create with id) function with valid parameters. */ public function testCaseTypeUpdate() { // Create Case Type @@ -148,21 +150,21 @@ class api_v3_CaseTypeTest extends CiviCaseTestCase { $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id)); $caseType = $result['values'][$id]; - // Update Case Type + // Update Case Type. $params = array('id' => $id); $params['title'] = $caseType['title'] = 'Something Else'; $this->callAPISuccess('CaseType', 'create', $params); - // Verify that updated case Type is exactly equal to the original with new title + // Verify that updated case Type is exactly equal to the original with new title. $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id)); - $this->assertEquals($result['values'][$id], $caseType, 'in line ' . __LINE__); + $this->assertEquals($result['values'][$id], $caseType); } /** - * Test delete function with valid parameters + * Test delete function with valid parameters. */ public function testCaseTypeDelete_New() { - // Create Case Type + // Create Case Type. $params = array( 'title' => 'Application', 'name' => 'Application', @@ -180,8 +182,9 @@ class api_v3_CaseTypeTest extends CiviCaseTestCase { } /** - * Test create methods with xml file - * success expected + * Test create methods with xml file. + * + * Success expected. */ public function testCaseTypeCreateWithDefinition() { // Create Case Type @@ -219,10 +222,10 @@ class api_v3_CaseTypeTest extends CiviCaseTestCase { $getCaseType = $this->callAPISuccess('CaseType', 'get', array('id' => $createCaseType['id'])); $this->assertEquals(1, $getCaseType['count']); - // Deletion succeeds when it's not in-use + // Deletion succeeds when it's not in-use. $this->callAPISuccess('Case', 'delete', array('id' => $createCase['id'])); - // Check result - case type should no longer exist + // Check result - case type should no longer exist. $this->callAPISuccess('CaseType', 'delete', array('id' => $createCaseType['id'])); $getCaseType = $this->callAPISuccess('CaseType', 'get', array('id' => $createCaseType['id'])); $this->assertEquals(0, $getCaseType['count']); diff --git a/tests/phpunit/api/v3/JobTest.php b/tests/phpunit/api/v3/JobTest.php index cc1396ef25..b153d8108a 100644 --- a/tests/phpunit/api/v3/JobTest.php +++ b/tests/phpunit/api/v3/JobTest.php @@ -63,13 +63,13 @@ class api_v3_JobTest extends CiviUnitTestCase { } /** - * Check with no name + * Check with no name. */ public function testCreateWithoutName() { $params = array( 'is_active' => 1, ); - $result = $this->callAPIFailure('job', 'create', $params, + $this->callAPIFailure('job', 'create', $params, 'Mandatory key(s) missing from params array: run_frequency, name, api_entity, api_action' ); } @@ -92,7 +92,7 @@ class api_v3_JobTest extends CiviUnitTestCase { } /** - * Create job + * Create job. */ public function testCreate() { $result = $this->callAPIAndDocument('job', 'create', $this->_params, __FUNCTION__, __FILE__); @@ -105,7 +105,7 @@ class api_v3_JobTest extends CiviUnitTestCase { } /** - * Check with empty array + * Check with empty array. */ public function testDeleteEmpty() { $params = array(); @@ -113,14 +113,14 @@ class api_v3_JobTest extends CiviUnitTestCase { } /** - * Check with No array + * Check with No array. */ public function testDeleteParamsNotArray() { $result = $this->callAPIFailure('job', 'delete', 'string'); } /** - * Check if required fields are not passed + * Check if required fields are not passed. */ public function testDeleteWithoutRequired() { $params = array( @@ -134,7 +134,7 @@ class api_v3_JobTest extends CiviUnitTestCase { } /** - * Check with incorrect required fields + * Check with incorrect required fields. */ public function testDeleteWithIncorrectData() { $params = array( @@ -144,7 +144,7 @@ class api_v3_JobTest extends CiviUnitTestCase { } /** - * Check job delete + * Check job delete. */ public function testDelete() { $createResult = $this->callAPISuccess('job', 'create', $this->_params); diff --git a/tests/phpunit/api/v3/MailingContactTest.php b/tests/phpunit/api/v3/MailingContactTest.php index 1a28382091..8bf293b8df 100644 --- a/tests/phpunit/api/v3/MailingContactTest.php +++ b/tests/phpunit/api/v3/MailingContactTest.php @@ -33,7 +33,6 @@ * * @copyright CiviCRM LLC (c) 2004-2014 * @version $Id: Job.php 30879 2010-11-22 15:45:55Z shot $ - * */ require_once 'CiviTest/CiviUnitTestCase.php'; @@ -60,14 +59,17 @@ class api_v3_MailingContactTest extends CiviUnitTestCase { } /** - * Test that the api responds correctly to null params - * Note to copy & pasters - tests like this that test the wrapper belong in the SyntaxConformance class + * Test that the api responds correctly to null params. + * + * Do not copy and paste. + * + * Tests like this that test the wrapper belong in the SyntaxConformance class * (which already has a 'not array test) * I have left this here in case 'null' isn't covered in that class * but don't copy it only any other classes */ public function testMailingNullParams() { - $result = $this->callAPIFailure('MailingContact', 'get', NULL); + $this->callAPIFailure('MailingContact', 'get', NULL); } public function testMailingContactGetFields() { @@ -79,54 +81,58 @@ class api_v3_MailingContactTest extends CiviUnitTestCase { } /** - * Test that the api will return the proper error when you do not - * supply the contact_id - * Note to copy & pasters - test is of marginal if any value & testing of wrapper level functionaliy + * Test for proper error when you do not supply the contact_id. + * + * Do not copy and paste. + * + * Test is of marginal if any value & testing of wrapper level functionality * belongs in the SyntaxConformance class */ public function testMailingNoContactID() { $params = array( 'something' => 'This is not a real field', ); - $result = $this->callAPIFailure('MailingContact', 'get', $params); + $this->callAPIFailure('MailingContact', 'get', $params); } /** - * Test that invalid contact_id return with proper error messages - * Note to copy & pasters - test is of marginal if any value & testing of wrapper level functionaliy + * Test that invalid contact_id return with proper error messages. + * + * Do not copy & paste. + * + * Test is of marginal if any value & testing of wrapper level functionality * belongs in the SyntaxConformance class */ public function testMailingContactInvalidContactID() { $params = array('contact_id' => 'This is not a number'); - $result = $this->callAPIFailure('MailingContact', 'get', $params); + $this->callAPIFailure('MailingContact', 'get', $params); } /** - * Test that invalid types are returned with appropriate errors + * Test that invalid types are returned with appropriate errors. */ public function testMailingContactInvalidType() { $params = array( 'contact_id' => 23, 'type' => 'invalid', ); - $result = $this->callAPIFailure('MailingContact', 'get', $params); + $this->callAPIFailure('MailingContact', 'get', $params); } /** - * Test that the API returns properly when there are no mailings - * for a the given contact + * Test for success result when there are no mailings for a the given contact. */ public function testMailingContactNoMailings() { $params = array( 'contact_id' => $this->_contact['id'], ); $result = $this->callAPISuccess('MailingContact', 'get', $params); - $this->assertEquals($result['count'], 0, "In line " . __LINE__); - $this->assertTrue(empty($result['values']), "In line " . __LINE__); + $this->assertEquals($result['count'], 0); + $this->assertTrue(empty($result['values'])); } /** - * Test that the API returns a mailing properly when there is only one + * Test that the API returns a mailing properly when there is only one. */ public function testMailingContactDelivered() { $op = new PHPUnit_Extensions_Database_Operation_Insert(); @@ -136,7 +142,7 @@ class api_v3_MailingContactTest extends CiviUnitTestCase { dirname(__FILE__) . '/dataset/mailing_contact.xml' ) ); - //~ Create the Mailing and connections to the user + // Create the Mailing and connections to the user. $op->execute($this->_dbconn, $this->createXMLDataSet( dirname(__FILE__) . '/dataset/mailing_delivered.xml' @@ -150,28 +156,28 @@ class api_v3_MailingContactTest extends CiviUnitTestCase { $result = $this->callAPISuccess('MailingContact', 'get', $params); $count = $this->callAPISuccess('MailingContact', 'getcount', $params); - $this->assertEquals($result['count'], 1, "In line " . __LINE__); - $this->assertEquals($count, 1, "In line " . __LINE__); - $this->assertFalse(empty($result['values']), "In line " . __LINE__); - $this->assertEquals($result['values'][1]['mailing_id'], 1, "In line " . __LINE__); - $this->assertEquals($result['values'][1]['subject'], "Some Subject", "In line " . __LINE__); - $this->assertEquals($result['values'][1]['creator_id'], 3, "In line " . __LINE__); - $this->assertEquals($result['values'][1]['creator_name'], "xyz1, abc1", "In line " . __LINE__); + $this->assertEquals($result['count'], 1); + $this->assertEquals($count, 1); + $this->assertFalse(empty($result['values'])); + $this->assertEquals($result['values'][1]['mailing_id'], 1); + $this->assertEquals($result['values'][1]['subject'], "Some Subject"); + $this->assertEquals($result['values'][1]['creator_id'], 3); + $this->assertEquals($result['values'][1]['creator_name'], "xyz1, abc1"); } /** - * Test that the API returns only the "Bounced" mailings when instructed to do so + * Test that the API returns only the "Bounced" mailings when instructed to do so. */ public function testMailingContactBounced() { $op = new PHPUnit_Extensions_Database_Operation_Insert(); - //Create the User + // Create the User. $op->execute($this->_dbconn, $this->createXMLDataSet( dirname(__FILE__) . '/dataset/mailing_contact.xml' ) ); - //~ Create the Mailing and connections to the user + // Create the Mailing and connections to the user. $op->execute($this->_dbconn, $this->createXMLDataSet( dirname(__FILE__) . '/dataset/mailing_bounced.xml' @@ -184,12 +190,12 @@ class api_v3_MailingContactTest extends CiviUnitTestCase { ); $result = $this->callAPISuccess('MailingContact', 'get', $params); - $this->assertEquals($result['count'], 1, "In line " . __LINE__); - $this->assertFalse(empty($result['values']), "In line " . __LINE__); - $this->assertEquals($result['values'][2]['mailing_id'], 2, "In line " . __LINE__); - $this->assertEquals($result['values'][2]['subject'], "Some Subject", "In line " . __LINE__); - $this->assertEquals($result['values'][2]['creator_id'], 3, "In line " . __LINE__); - $this->assertEquals($result['values'][2]['creator_name'], "xyz1, abc1", "In line " . __LINE__); + $this->assertEquals($result['count'], 1); + $this->assertFalse(empty($result['values'])); + $this->assertEquals($result['values'][2]['mailing_id'], 2); + $this->assertEquals($result['values'][2]['subject'], "Some Subject"); + $this->assertEquals($result['values'][2]['creator_id'], 3); + $this->assertEquals($result['values'][2]['creator_name'], "xyz1, abc1"); } } diff --git a/tests/phpunit/api/v3/dataset/resolver/api/v3/Generic/ExampleAction2.php b/tests/phpunit/api/v3/dataset/resolver/api/v3/Generic/ExampleAction2.php index 3ff0d857be..84885d255b 100644 --- a/tests/phpunit/api/v3/dataset/resolver/api/v3/Generic/ExampleAction2.php +++ b/tests/phpunit/api/v3/dataset/resolver/api/v3/Generic/ExampleAction2.php @@ -1,7 +1,9 @@