From c0536a926573b22207ac180b7a4ed41c6c96a052 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 10 Jun 2013 20:25:38 +1200 Subject: [PATCH] test tidy up, use apiSuccess & fail assertions, add assertion to highlight cause of failure --- tests/phpunit/api/v3/CustomGroupTest.php | 30 +++++++++++++----------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/tests/phpunit/api/v3/CustomGroupTest.php b/tests/phpunit/api/v3/CustomGroupTest.php index e5f1f3533e..6871cd6720 100644 --- a/tests/phpunit/api/v3/CustomGroupTest.php +++ b/tests/phpunit/api/v3/CustomGroupTest.php @@ -84,7 +84,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); $customGroup = civicrm_api('custom_group', 'create', $params); - $this->assertEquals($customGroup['is_error'], 1, 'In line ' . __LINE__); + $this->assertAPIFailure($customGroup, 'In line ' . __LINE__); $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: title, extends', 'In line ' . __LINE__ ); @@ -109,7 +109,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { $customGroup = civicrm_api('custom_group', 'create', $params); $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: extends', 'In line ' . __LINE__); - $this->assertEquals($customGroup['is_error'], 1, 'In line ' . __LINE__); + $this->assertAPIFailure($customGroup, 'In line ' . __LINE__); } /** @@ -131,8 +131,8 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { ); $customGroup = civicrm_api('custom_group', 'create', $params); + $this->assertAPIFailure($customGroup, 'In line ' . __LINE__); $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: extends', 'In line ' . __LINE__); - $this->assertEquals($customGroup['is_error'], 1, 'In line ' . __LINE__); } /** @@ -189,6 +189,8 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { ); $result = civicrm_api('custom_group', 'getfields', $params); + $this->assertAPISuccess($result); + $this->assertArrayKeyExists('options', $result['values'], ' check that options are rendered for fieldtype enum'); $this->assertEquals('Tab', $result['values']['style']['options'][0]); $this->assertEquals('Inline', $result['values']['style']['options'][1]); @@ -213,7 +215,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { ); $result = civicrm_api('custom_group', 'create', $params); - $this->assertEquals($result['is_error'], 1, 'In line ' . __LINE__); + $this->assertAPIFailure($result, 'In line ' . __LINE__); $this->assertEquals($result['error_message'], 'implode(): Invalid arguments passed', 'In line ' . __LINE__); } @@ -234,7 +236,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { ); $customGroup = civicrm_api('custom_group', 'create', $params); - $this->assertEquals($customGroup['is_error'], 0, 'In line ' . __LINE__); + $this->assertAPISuccess($customGroup, 'In line ' . __LINE__); $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__); $this->assertEquals($customGroup['values'][$customGroup['id']]['style'], 'Inline', 'In line ' . __LINE__); } @@ -245,7 +247,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { function testCustomGroupCreateNotArray() { $params = NULL; $customGroup = civicrm_api('custom_group', 'create', $params); - $this->assertEquals($customGroup['is_error'], 1, 'In line ' . __LINE__); + $this->assertAPIFailure($customGroup, 'In line ' . __LINE__); $this->assertEquals($customGroup['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__); } @@ -264,7 +266,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { $customGroup = civicrm_api('custom_group', 'create', $params); $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: title', 'In line ' . __LINE__); - $this->assertEquals($customGroup['is_error'], 1, 'In line ' . __LINE__); + $this->assertAPIFailure($customGroup, 'In line ' . __LINE__); } /** @@ -284,7 +286,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { ); $customGroup = civicrm_api('custom_group', 'create', $params); - $this->assertEquals($customGroup['is_error'], 0, 'In line ' . __LINE__); + $this->assertAPISuccess($customGroup, 'In line ' . __LINE__); $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__); $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Household', 'In line ' . __LINE__); $this->assertEquals($customGroup['values'][$customGroup['id']]['style'], 'Tab', 'In line ' . __LINE__); @@ -308,7 +310,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { ); $customGroup = civicrm_api('custom_group', 'create', $params); - $this->assertEquals($customGroup['is_error'], 0, 'In line ' . __LINE__); + $this->assertAPISuccess($customGroup, 'In line ' . __LINE__); $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__); $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Contribution', 'In line ' . __LINE__); } @@ -332,7 +334,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { ); $customGroup = civicrm_api('custom_group', 'create', $params); - $this->assertEquals($customGroup['is_error'], 0, 'In line ' . __LINE__); + $this->assertAPISuccess($customGroup, 'In line ' . __LINE__); $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__); $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Group', 'In line ' . __LINE__); } @@ -354,7 +356,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { ); $customGroup = civicrm_api('custom_group', 'create', $params); - $this->assertEquals($customGroup['is_error'], 0, 'In line ' . __LINE__); + $this->assertAPISuccess($customGroup, 'In line ' . __LINE__); $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__); $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Activity', 'In line ' . __LINE__); } @@ -369,7 +371,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); $customGroup = civicrm_api('custom_group', 'delete', $params); - $this->assertEquals($customGroup['is_error'], 1, 'In line ' . __LINE__); + $this->assertAPIFailure($customGroup, 'In line ' . __LINE__); $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: id', 'In line ' . __LINE__); } @@ -394,7 +396,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { ); $result = civicrm_api('custom_group', 'delete', $params); $this->documentMe($params, $result, __FUNCTION__, __FILE__); - $this->assertEquals($result['is_error'], 0, 'In line ' . __LINE__); + $this->assertAPISuccess($result, 'In line ' . __LINE__); } /* * main success get function @@ -408,7 +410,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { $params = array('version' => 3); $result = civicrm_api($this->_entity, 'get', $params); $this->documentMe($params, $result, __FUNCTION__, __FILE__); - $this->assertEquals($result['is_error'], 0, 'in line' . __LINE__); + $this->assertAPISuccess($result, 'In line ' . __LINE__); $values = $result['values'][$result['id']]; foreach ($this->_params as $key => $value) { if ($key == 'version' || $key == 'weight') { -- 2.25.1