CRM-15855 - Allow mailings to be saved (but not sent) without name+subject.
[civicrm-core.git] / tests / phpunit / api / v3 / CountryTest.php
CommitLineData
fe14170b
JJ
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
fe14170b
JJ
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28
29require_once 'CiviTest/CiviUnitTestCase.php';
30
31
32/**
33 * Test APIv3 civicrm_country* functions
34 *
6c6e6187
TO
35 * @package CiviCRM_APIv3
36 * @subpackage API_Contact
fe14170b
JJ
37 */
38class api_v3_CountryTest extends CiviUnitTestCase {
39 protected $_apiversion;
40 protected $_params;
41
42
00be9182 43 public function setUp() {
fe14170b
JJ
44 $this->_apiversion = 3;
45 parent::setUp();
a6e1ef97 46 $this->useTransaction(TRUE);
fe14170b 47 $this->_params = array(
78abe068 48 'name' => 'Made Up Land',
a6e1ef97 49 'iso_code' => 'ZZ',
78abe068 50 'region_id' => 1,
fe14170b
JJ
51 );
52 }
53
54 public function testCreateCountry() {
55
56 $result = $this->callAPIAndDocument('country', 'create', $this->_params, __FUNCTION__, __FILE__);
78abe068
C
57 $this->assertEquals(1, $result['count']);
58 $this->assertNotNull($result['values'][$result['id']]['id']);
fe14170b
JJ
59
60 $this->callAPISuccess('country', 'delete', array('id' => $result['id']));
61 }
62
63 public function testDeleteCountry() {
64 //create one
65 $create = $this->callAPISuccess('country', 'create', $this->_params);
66
6c6e6187 67 $result = $this->callAPIAndDocument('country', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__);
78abe068 68 $this->assertEquals(1, $result['count']);
fe14170b
JJ
69 $get = $this->callAPISuccess('country', 'get', array(
70 'id' => $create['id'],
71 ));
78abe068 72 $this->assertEquals(0, $get['count'], 'Country not successfully deleted');
fe14170b
JJ
73 }
74
75 /**
76 * Test civicrm_phone_get with empty params.
77 */
78 public function testGetEmptyParams() {
79 $result = $this->callAPISuccess('Country', 'Get', array());
80 }
81
82 /**
83 * Test civicrm_phone_get with wrong params.
84 */
85 public function testGetWrongParams() {
86 $this->callAPIFailure('Country', 'Get', array('id' => 'abc'));
87 }
88
89 /**
90 * Test civicrm_phone_get - success expected.
91 */
92 public function testGet() {
93 $country = $this->callAPISuccess('Country', 'create', $this->_params);
94 $params = array(
6c6e6187 95 'iso_code' => $this->_params['iso_code'],
fe14170b
JJ
96 );
97 $result = $this->callAPIAndDocument('Country', 'Get', $params, __FUNCTION__, __FILE__);
78abe068
C
98 $this->assertEquals($country['values'][$country['id']]['name'], $result['values'][$country['id']]['name']);
99 $this->assertEquals($country['values'][$country['id']]['iso_code'], $result['values'][$country['id']]['iso_code']);
fe14170b
JJ
100 }
101
102 ///////////////// civicrm_country_create methods
103
104 /**
105 * If a new country is created and it is created again it should not create a second one.
106 * We check on the iso code (there should be only one iso code
fe14170b 107 */
78abe068 108 public function testCreateDuplicateFail() {
fe14170b
JJ
109 $params = $this->_params;
110 unset($params['id']);
78abe068
C
111 $this->callAPISuccess('country', 'create', $params);
112 $this->callAPIFailure('country', 'create', $params);
fe14170b
JJ
113 $check = $this->callAPISuccess('country', 'getcount', array(
114 'iso_code' => $params['iso_code'],
115 ));
116 $this->assertEquals(1, $check);
117 }
96025800 118
fe14170b 119}