Merge remote-tracking branch 'upstream/4.3' into 4.3-master-2013-05-24-02-32-04
[civicrm-core.git] / tests / phpunit / api / v3 / MailSettingsTest.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
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 class api_v3_MailSettingsTest extends CiviUnitTestCase {
31 protected $_apiversion;
32 protected $params;
33 protected $id;
34 public $DBResetRequired = FALSE; function setUp() {
35 $this->_apiversion = 3;
36 $this->params = array(
37 'domain_id' => 1,
38 'name' => "my mail setting",
39 'domain' => 'setting.com',
40 'local_part' => 'civicrm+',
41 'server' => "localhost",
42 'username' => 'sue',
43 'password' => 'pass',
44 'version' => $this->_apiversion,
45 );
46 parent::setUp();
47 }
48
49 function tearDown() {}
50
51 public function testCreateMailSettings() {
52 $result = civicrm_api('MailSettings', 'create', $this->params);
53 $this->documentMe($this->params, $result, __FUNCTION__, __FILE__);
54 $this->assertAPISuccess($result, 'In line ' . __LINE__);
55 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
56 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
57 }
58
59 public function testGetMailSettings() {
60
61 $result = civicrm_api('MailSettings', 'get', $this->params);
62 $this->documentMe($this->params, $result, __FUNCTION__, __FILE__);
63 $this->assertAPISuccess($result, 'In line ' . __LINE__);
64 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
65 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
66 $this->id = $result['id'];
67 }
68
69 public function testDeleteMailSettings() {
70 $entity = civicrm_api('MailSettings', 'get', $this->params);
71 $this->assertEquals('setting.com', $entity['values'][$entity['id']]['domain'], 'In line ' . __LINE__);
72
73 $result = civicrm_api('MailSettings', 'delete', array('version' => 3, 'id' => $entity['id']));
74 $this->documentMe($this->params, $result, __FUNCTION__, __FILE__);
75 $this->assertAPISuccess($result, 'In line ' . __LINE__);
76 $checkDeleted = civicrm_api('MailSettings', 'get', array(
77 'version' => 3,
78 ));
79 $this->assertEquals('EXAMPLE.ORG', $checkDeleted['values'][$checkDeleted['id']]['domain'], 'In line ' . __LINE__);
80 }
81
82 public function testGetMailSettingsChainDelete() {
83 $description = "demonstrates get + delete in the same call";
84 $subfile = 'ChainedGetDelete';
85 $params = array(
86 'version' => 3,
87 'title' => "MailSettings title",
88 'api.MailSettings.delete' => 1,
89 );
90 $result = civicrm_api('MailSettings', 'create', $this->params);
91 $result = civicrm_api('MailSettings', 'get', $params);
92 $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
93 $this->assertAPISuccess($result, 'In line ' . __LINE__);
94 $this->assertEquals(0, civicrm_api('MailSettings', 'getcount', array('version' => 3)), 'In line ' . __LINE__);
95 }
96 }
97