Merge branch 'JohnFF-patch-1'
[civicrm-core.git] / tests / phpunit / api / v3 / MailSettingsTest.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.5 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27 */
28
29 require_once 'CiviTest/CiviUnitTestCase.php';
30
31 /**
32 * Class api_v3_MailSettingsTest
33 */
34 class api_v3_MailSettingsTest extends CiviUnitTestCase {
35 protected $_apiversion = 3;
36 protected $params;
37 protected $id;
38 public $DBResetRequired = FALSE;
39
40 function setUp() {
41 $this->params = array(
42 'domain_id' => 1,
43 'name' => "my mail setting",
44 'domain' => 'setting.com',
45 'local_part' => 'civicrm+',
46 'server' => "localhost",
47 'username' => 'sue',
48 'password' => 'pass',
49 'is_default' => 1,
50 );
51 parent::setUp();
52 }
53
54 function tearDown() {}
55
56 /**
57 * Test creation
58 */
59 public function testCreateMailSettings() {
60 $this->callAPISuccessGetCount('mail_settings', array(), 1);
61 $result = $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__);
62 $this->assertEquals(1, $result['count']);
63 $this->assertNotNull($result['values'][$result['id']]['id']);
64 $this->callAPISuccess('MailSettings', 'delete', array('id' => $result['id']));
65 $this->callAPISuccessGetCount('mail_settings', array(), 1);
66 }
67
68 /**
69 * Test caches cleared adequately
70 */
71 public function testCreateUpdateMailSettings() {
72 $result = $this->callAPISuccess('MailSettings', 'create', $this->params);
73 $this->assertEquals('setting.com', CRM_Core_BAO_MailSettings::defaultDomain());
74 $this->callAPISuccess('mail_settings', 'create', array('id' => $result['id'], 'domain' => 'updated.com'));
75 $this->assertEquals('updated.com', CRM_Core_BAO_MailSettings::defaultDomain());
76 $this->callAPISuccess('MailSettings', 'delete', array('id' => $result['id']));
77 $this->callAPISuccessGetCount('mail_settings', array(), 1);
78 }
79
80 /**
81 * Test get method
82 */
83 public function testGetMailSettings() {
84 $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__);
85 $result = $this->callAPIAndDocument('MailSettings', 'get', $this->params, __FUNCTION__, __FILE__);
86 $this->assertEquals(1, $result['count']);
87 $this->assertNotNull($result['values'][$result['id']]['id']);
88 $this->callAPISuccess('MailSettings', 'delete', array('id' => $result['id']));
89 $this->callAPISuccessGetCount('mail_settings', array(), 1);
90 }
91
92 public function testDeleteMailSettings() {
93 $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__);
94 $entity = $this->callAPISuccess('MailSettings', 'get', $this->params);
95 $this->assertEquals('setting.com', $entity['values'][$entity['id']]['domain']);
96 $this->callAPIAndDocument('MailSettings', 'delete', array('id' => $entity['id']), __FUNCTION__, __FILE__);
97 $checkDeleted = $this->callAPISuccess('MailSettings', 'get', array());
98 $this->assertEquals('EXAMPLE.ORG', $checkDeleted['values'][$checkDeleted['id']]['domain']);
99 }
100
101 /**
102 * Test chained delete
103 */
104 public function testGetMailSettingsChainDelete() {
105 $description = "demonstrates get + delete in the same call";
106 $subFile = 'ChainedGetDelete';
107 $params = array(
108 'title' => "MailSettings title",
109 'api.MailSettings.delete' => 1,
110 );
111 $this->callAPISuccess('MailSettings', 'create', $this->params);
112 $this->callAPIAndDocument('MailSettings', 'get', $params, __FUNCTION__, __FILE__, $description, $subFile);
113 $this->assertEquals(0, $this->callAPISuccess('MailSettings', 'getcount', array()));
114 }
115 }
116