From fe14170bdfe40de8c0f40f64c31a00feb3f01bc1 Mon Sep 17 00:00:00 2001 From: Jaap Jansma Date: Tue, 3 Jun 2014 15:17:05 +0200 Subject: [PATCH] added a phpunit test file for country api --- tests/phpunit/api/v3/CountryTest.php | 120 +++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 tests/phpunit/api/v3/CountryTest.php diff --git a/tests/phpunit/api/v3/CountryTest.php b/tests/phpunit/api/v3/CountryTest.php new file mode 100644 index 0000000000..694e24cf8e --- /dev/null +++ b/tests/phpunit/api/v3/CountryTest.php @@ -0,0 +1,120 @@ +_apiversion = 3; + parent::setUp(); + $this->quickCleanup(array('civicrm_country')); + $this->_params = array( + 'id' => 1152, + 'name' => 'Netherlands', + 'iso_code' => 'NL', + ); + } + + 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->callAPISuccess('country', 'delete', array('id' => $result['id'])); + } + + public function testDeleteCountry() { + //create one + $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__); + $get = $this->callAPISuccess('country', 'get', array( + 'id' => $create['id'], + )); + $this->assertEquals(0, $get['count'], 'Country not successfully deleted In line ' . __LINE__); + } + + /** + * Test civicrm_phone_get with empty params. + */ + public function testGetEmptyParams() { + $result = $this->callAPISuccess('Country', 'Get', array()); + } + + /** + * Test civicrm_phone_get with wrong params. + */ + public function testGetWrongParams() { + $this->callAPIFailure('Country', 'Get', array('id' => 'abc')); + } + + /** + * Test civicrm_phone_get - success expected. + */ + public function testGet() { + $country = $this->callAPISuccess('Country', 'create', $this->_params); + $params = array( + '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__); + } + + ///////////////// civicrm_country_create methods + + /** + * If a new country is created and it is created again it should not create a second one. + * We check on the iso code (there should be only one iso code + * + */ + public function testCreatePhonePrimaryHandlingChangeExisting() { + $params = $this->_params; + unset($params['id']); + $phone1 = $this->callAPISuccess('country', 'create', $params); + $phone2 = $this->callAPISuccess('country', 'create', $params); + $check = $this->callAPISuccess('country', 'getcount', array( + 'iso_code' => $params['iso_code'], + )); + $this->assertEquals(1, $check); + } +} + -- 2.25.1