<?php
-
/*
+--------------------------------------------------------------------+
-| CiviCRM version 4.5 |
+| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
*/
require_once 'CiviTest/CiviUnitTestCase.php';
+
+/**
+ * Class api_v3_MailSettingsTest
+ */
class api_v3_MailSettingsTest extends CiviUnitTestCase {
protected $_apiversion = 3;
protected $params;
protected $id;
public $DBResetRequired = FALSE;
- function setUp() {
+ public function setUp() {
$this->params = array(
'domain_id' => 1,
'name' => "my mail setting",
'server' => "localhost",
'username' => 'sue',
'password' => 'pass',
+ 'is_default' => 1,
);
parent::setUp();
+ $this->useTransaction(TRUE);
}
- function tearDown() {}
-
+ /**
+ * Test creation
+ */
public function testCreateMailSettings() {
+ $this->callAPISuccessGetCount('mail_settings', array(), 1);
$result = $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__);
- $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
- $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
+ $this->assertEquals(1, $result['count']);
+ $this->assertNotNull($result['values'][$result['id']]['id']);
+ $this->callAPISuccess('MailSettings', 'delete', array('id' => $result['id']));
+ $this->callAPISuccessGetCount('mail_settings', array(), 1);
}
- public function testGetMailSettings() {
+ /**
+ * Test caches cleared adequately
+ */
+ public function testCreateUpdateMailSettings() {
+ $result = $this->callAPISuccess('MailSettings', 'create', $this->params);
+ $this->assertEquals('setting.com', CRM_Core_BAO_MailSettings::defaultDomain());
+ $this->callAPISuccess('mail_settings', 'create', array('id' => $result['id'], 'domain' => 'updated.com'));
+ $this->assertEquals('updated.com', CRM_Core_BAO_MailSettings::defaultDomain());
+ $this->callAPISuccess('MailSettings', 'delete', array('id' => $result['id']));
+ $this->callAPISuccessGetCount('mail_settings', array(), 1);
+ }
+ /**
+ * Test get method
+ */
+ public function testGetMailSettings() {
+ $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__);
$result = $this->callAPIAndDocument('MailSettings', 'get', $this->params, __FUNCTION__, __FILE__);
- $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
- $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
+ $this->assertEquals(1, $result['count']);
+ $this->assertNotNull($result['values'][$result['id']]['id']);
+ $this->callAPISuccess('MailSettings', 'delete', array('id' => $result['id']));
+ $this->callAPISuccessGetCount('mail_settings', array(), 1);
}
public function testDeleteMailSettings() {
+ $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__);
$entity = $this->callAPISuccess('MailSettings', 'get', $this->params);
- $this->assertEquals('setting.com', $entity['values'][$entity['id']]['domain'], 'In line ' . __LINE__);
-
- $result = $this->callAPIAndDocument('MailSettings', 'delete', array('id' => $entity['id']), __FUNCTION__, __FILE__);
+ $this->assertEquals('setting.com', $entity['values'][$entity['id']]['domain']);
+ $this->callAPIAndDocument('MailSettings', 'delete', array('id' => $entity['id']), __FUNCTION__, __FILE__);
$checkDeleted = $this->callAPISuccess('MailSettings', 'get', array());
- $this->assertEquals('EXAMPLE.ORG', $checkDeleted['values'][$checkDeleted['id']]['domain'], 'In line ' . __LINE__);
+ $this->assertEquals('EXAMPLE.ORG', $checkDeleted['values'][$checkDeleted['id']]['domain']);
}
+ /**
+ * Test chained delete
+ */
public function testGetMailSettingsChainDelete() {
$description = "demonstrates get + delete in the same call";
- $subfile = 'ChainedGetDelete';
- $params = array(
+ $subFile = 'ChainedGetDelete';
+ $params = array(
'title' => "MailSettings title",
'api.MailSettings.delete' => 1,
);
- $result = $this->callAPISuccess('MailSettings', 'create', $this->params);
- $result = $this->callAPIAndDocument('MailSettings', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile);
- $this->assertEquals(0, $this->callAPISuccess('MailSettings', 'getcount', array()), 'In line ' . __LINE__);
+ $this->callAPISuccess('MailSettings', 'create', $this->params);
+ $this->callAPIAndDocument('MailSettings', 'get', $params, __FUNCTION__, __FILE__, $description, $subFile);
+ $this->assertEquals(0, $this->callAPISuccess('MailSettings', 'getcount', array()));
}
}
-