test failure fix2
[civicrm-core.git] / tests / phpunit / api / v3 / MailSettingsTest.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.6 |
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 public 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 $this->useTransaction(TRUE);
53 }
54
55 /**
56 * Test creation
57 */
58 public function testCreateMailSettings() {
59 $this->callAPISuccessGetCount('mail_settings', array(), 1);
60 $result = $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__);
61 $this->assertEquals(1, $result['count']);
62 $this->assertNotNull($result['values'][$result['id']]['id']);
63 $this->callAPISuccess('MailSettings', 'delete', array('id' => $result['id']));
64 $this->callAPISuccessGetCount('mail_settings', array(), 1);
65 }
66
67 /**
68 * Test caches cleared adequately
69 */
70 public function testCreateUpdateMailSettings() {
71 $result = $this->callAPISuccess('MailSettings', 'create', $this->params);
72 $this->assertEquals('setting.com', CRM_Core_BAO_MailSettings::defaultDomain());
73 $this->callAPISuccess('mail_settings', 'create', array('id' => $result['id'], 'domain' => 'updated.com'));
74 $this->assertEquals('updated.com', CRM_Core_BAO_MailSettings::defaultDomain());
75 $this->callAPISuccess('MailSettings', 'delete', array('id' => $result['id']));
76 $this->callAPISuccessGetCount('mail_settings', array(), 1);
77 }
78
79 /**
80 * Test get method
81 */
82 public function testGetMailSettings() {
83 $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__);
84 $result = $this->callAPIAndDocument('MailSettings', 'get', $this->params, __FUNCTION__, __FILE__);
85 $this->assertEquals(1, $result['count']);
86 $this->assertNotNull($result['values'][$result['id']]['id']);
87 $this->callAPISuccess('MailSettings', 'delete', array('id' => $result['id']));
88 $this->callAPISuccessGetCount('mail_settings', array(), 1);
89 }
90
91 public function testDeleteMailSettings() {
92 $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__);
93 $entity = $this->callAPISuccess('MailSettings', 'get', $this->params);
94 $this->assertEquals('setting.com', $entity['values'][$entity['id']]['domain']);
95 $this->callAPIAndDocument('MailSettings', 'delete', array('id' => $entity['id']), __FUNCTION__, __FILE__);
96 $checkDeleted = $this->callAPISuccess('MailSettings', 'get', array());
97 $this->assertEquals('EXAMPLE.ORG', $checkDeleted['values'][$checkDeleted['id']]['domain']);
98 }
99
100 /**
101 * Test chained delete
102 */
103 public function testGetMailSettingsChainDelete() {
104 $description = "demonstrates get + delete in the same call";
105 $subFile = 'ChainedGetDelete';
106 $params = array(
107 'title' => "MailSettings title",
108 'api.MailSettings.delete' => 1,
109 );
110 $this->callAPISuccess('MailSettings', 'create', $this->params);
111 $this->callAPIAndDocument('MailSettings', 'get', $params, __FUNCTION__, __FILE__, $description, $subFile);
112 $this->assertEquals(0, $this->callAPISuccess('MailSettings', 'getcount', array()));
113 }
114 }