Fix & test mail setting caching to fix test
authorEileen McNaughton <eileen@fuzion.co.nz>
Tue, 3 Jun 2014 20:33:03 +0000 (08:33 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Tue, 3 Jun 2014 20:33:03 +0000 (08:33 +1200)
tests/phpunit/api/v3/MailSettingsTest.php

index 04ccef0ff1540e315b963fc0295ec8272de1c6b6..117d08dcdca071ed9fd68a29effb19f581c09d72 100644 (file)
@@ -46,44 +46,71 @@ class api_v3_MailSettingsTest extends CiviUnitTestCase {
       'server' => "localhost",
       'username' => 'sue',
       'password' => 'pass',
+      'is_default' => 1,
     );
     parent::setUp();
   }
 
   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';
+    $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()));
   }
 }