From 78abe068ef9e302e2edbe7777b74748c1ffba111 Mon Sep 17 00:00:00 2001 From: CiviCRM Date: Tue, 17 Jun 2014 19:49:56 +0530 Subject: [PATCH] CRM-12789 --- api/v3/Country.php | 6 ++---- tests/phpunit/api/v3/CountryTest.php | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/api/v3/Country.php b/api/v3/Country.php index dce4272e0a..1ecdd0316b 100644 --- a/api/v3/Country.php +++ b/api/v3/Country.php @@ -61,10 +61,7 @@ function civicrm_api3_country_create($params) { * @param array $params array or parameters determined by getfields */ function _civicrm_api3_country_create_spec(&$params) { - // TODO a 'clever' default should be introduced - $params['is_primary']['api.default'] = 0; - $params['country']['api.required'] = 1; - $params['contact_id']['api.required'] = 1; + $params['name']['api.required'] = 1; } /** @@ -79,6 +76,7 @@ function _civicrm_api3_country_create_spec(&$params) { * @access public */ function civicrm_api3_country_delete($params) { + CRM_Core_DAO::executeQuery("DELETE FROM civicrm_state_province WHERE country_id = %1", array(1 => array($params['id'], 'Integer'))); return _civicrm_api3_basic_delete(_civicrm_api3_get_DAO(__FUNCTION__), $params); } diff --git a/tests/phpunit/api/v3/CountryTest.php b/tests/phpunit/api/v3/CountryTest.php index 694e24cf8e..6836916e55 100644 --- a/tests/phpunit/api/v3/CountryTest.php +++ b/tests/phpunit/api/v3/CountryTest.php @@ -45,17 +45,17 @@ class api_v3_CountryTest extends CiviUnitTestCase { parent::setUp(); $this->quickCleanup(array('civicrm_country')); $this->_params = array( - 'id' => 1152, - 'name' => 'Netherlands', - 'iso_code' => 'NL', + 'name' => 'Made Up Land', + 'iso_code' => 'ML', + 'region_id' => 1, ); } public function testCreateCountry() { $result = $this->callAPIAndDocument('country', 'create', $this->_params, __FUNCTION__, __FILE__); - $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); - $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__); + $this->assertEquals(1, $result['count']); + $this->assertNotNull($result['values'][$result['id']]['id']); $this->callAPISuccess('country', 'delete', array('id' => $result['id'])); } @@ -65,11 +65,11 @@ class api_v3_CountryTest extends CiviUnitTestCase { $create = $this->callAPISuccess('country', 'create', $this->_params); $result = $this->callAPIAndDocument('country', 'delete', array('id' => $create['id'],), __FUNCTION__, __FILE__); - $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); + $this->assertEquals(1, $result['count']); $get = $this->callAPISuccess('country', 'get', array( 'id' => $create['id'], )); - $this->assertEquals(0, $get['count'], 'Country not successfully deleted In line ' . __LINE__); + $this->assertEquals(0, $get['count'], 'Country not successfully deleted'); } /** @@ -95,8 +95,8 @@ class api_v3_CountryTest extends CiviUnitTestCase { 'iso_code' => $this->_params['iso_code'], ); $result = $this->callAPIAndDocument('Country', 'Get', $params, __FUNCTION__, __FILE__); - $this->assertEquals($country['values'][$country['id']]['name'], $result['values'][$country['id']]['name'], 'In line ' . __LINE__); - $this->assertEquals($country['values'][$country['id']]['iso_code'], $result['values'][$country['id']]['iso_code'], 'In line ' . __LINE__); + $this->assertEquals($country['values'][$country['id']]['name'], $result['values'][$country['id']]['name']); + $this->assertEquals($country['values'][$country['id']]['iso_code'], $result['values'][$country['id']]['iso_code']); } ///////////////// civicrm_country_create methods @@ -106,11 +106,11 @@ class api_v3_CountryTest extends CiviUnitTestCase { * We check on the iso code (there should be only one iso code * */ - public function testCreatePhonePrimaryHandlingChangeExisting() { + public function testCreateDuplicateFail() { $params = $this->_params; unset($params['id']); - $phone1 = $this->callAPISuccess('country', 'create', $params); - $phone2 = $this->callAPISuccess('country', 'create', $params); + $this->callAPISuccess('country', 'create', $params); + $this->callAPIFailure('country', 'create', $params); $check = $this->callAPISuccess('country', 'getcount', array( 'iso_code' => $params['iso_code'], )); -- 2.25.1