CRM-12789
authorCiviCRM <info@civicrm.org>
Tue, 17 Jun 2014 14:19:56 +0000 (19:49 +0530)
committerjitendrapurohit <jituraj7760@gmail.com>
Tue, 24 Jun 2014 13:06:09 +0000 (18:36 +0530)
api/v3/Country.php
tests/phpunit/api/v3/CountryTest.php

index dce4272e0ad58259e9cde6ccc48c887f8ba6c209..1ecdd0316b81a90a91e6f0364afa064376ae9f78 100644 (file)
@@ -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);
 }
 
index 694e24cf8ec0393ce56a9acc7d56d2bb42083173..6836916e55453cef86d7784ebc2c5325b7c1ff53 100644 (file)
@@ -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'],
     ));