CRM-19961 Add in tests to prove logic and fix logic
authorSeamus Lee <seamuslee001@gmail.com>
Mon, 10 Apr 2017 22:08:17 +0000 (08:08 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Mon, 10 Apr 2017 23:56:18 +0000 (09:56 +1000)
remove changes to update function

Fix style

CRM/Core/DAO/AllCoreTables.data.php
CRM/SMS/BAO/Provider.php
tests/phpunit/CRM/SMS/BAO/ProviderTest.php [new file with mode: 0644]

index f19c8323197bd1334941ebebb1093eefd406ef81..0488ea6ce548c58bd3c89433da29dacee3c431dd 100644 (file)
@@ -24,7 +24,7 @@
 | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
 +--------------------------------------------------------------------+
 */
-// (GenCodeChecksum:fe1a575dafdc824e3ce8a7e0d7fc49bf)
+// (GenCodeChecksum:53f1cd5e913b2f82abfc7097127caafc)
 return array(
   'CRM_Core_DAO_AddressFormat' => array(
     'name' => 'AddressFormat',
index 5906419c81428754dc7918cd41408b74d20e50c0..4d3470450176413283fb08f6b837e06ac1dc03aa 100644 (file)
@@ -106,11 +106,6 @@ class CRM_SMS_BAO_Provider extends CRM_SMS_DAO_Provider {
    * @param int $providerId
    */
   public static function updateRecord($values, $providerId) {
-    $current_domain_id = CRM_Core_DAO::getFieldValue('CRM_SMS_DAO_Provider', $providerId, 'domain_id');
-    if (isset($current_domain_id) || is_null($current_domain_id)) {
-      $current_domain_id = CRM_Core_Config::domainID();
-    }
-    $values['domain_id'] = CRM_Utils_Array::value('domain_id', $values, $current_domain_id);
     $dao = new CRM_SMS_DAO_Provider();
     $dao->id = $providerId;
     if ($dao->find(TRUE)) {
diff --git a/tests/phpunit/CRM/SMS/BAO/ProviderTest.php b/tests/phpunit/CRM/SMS/BAO/ProviderTest.php
new file mode 100644 (file)
index 0000000..c4fb264
--- /dev/null
@@ -0,0 +1,99 @@
+<?php
+
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.7                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2017                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+ */
+/**
+ *  Test CRM_SMS_BAO_Provider functions
+ *
+ * @package CiviCRM_APIv3
+ * @subpackage API_Contribution
+ * @group headless
+ */
+class CRM_SMS_BAO_ProviderTest extends CiviUnitTestCase {
+
+  /**
+   * Set Up Funtion
+   */
+  public function setUp() {
+    parent::setUp();
+    $option = $this->callAPISuccess('option_value', 'create', array('option_group_id' => 'sms_provider_name', 'name' => 'test_provider_name', 'label' => 'test_provider_name', 'value' => 1));
+    $this->option_value = $option['id'];
+  }
+
+  /**
+   * Clean up after each test.
+   */
+  public function tearDown() {
+    parent::tearDown();
+    $this->callAPISuccess('option_value', 'delete', array('id' => $this->option_value));
+  }
+
+  /**
+   * CRM-19961 Check that when saving and updating a SMS provider with domain as NULL that it stays null
+   */
+  public function testCreateAndUpdateProvider() {
+    $values = array(
+      'domain_id' => NULL,
+      'title' => 'test SMS provider',
+      'username' => 'test',
+      'password' => 'dummpy password',
+      'name' => 1,
+      'is_active' => 1,
+      'api_type' => 1,
+    );
+    CRM_SMS_BAO_Provider::saveRecord($values);
+    $provider = $this->callAPISuccess('SmsProvider', 'getsingle', array('title' => 'test SMS provider'));
+    $domain_id = CRM_Core_DAO::getFieldValue('CRM_SMS_DAO_Provider', $provider['id'], 'domain_id');
+    $this->assertNull($domain_id);
+    $values2 = array('title' => 'Test SMS Provider2');
+    CRM_SMS_BAO_Provider::updateRecord($values2, $provider['id']);
+    $provider = $this->callAPISuccess('SmsProvider', 'getsingle', array('id' => $provider['id']));
+    $this->assertEquals('Test SMS Provider2', $provider['title']);
+    $domain_id = CRM_Core_DAO::getFieldValue('CRM_SMS_DAO_Provider', $provider['id'], 'domain_id');
+    $this->assertNull($domain_id);
+    CRM_SMS_BAO_Provider::del($provider['id']);
+  }
+
+  /**
+   * CRM-19961 Check that when a domain is not passed when saving it defaults to current domain when create
+   */
+  public function testCreateWithoutDomain() {
+    $values = array(
+      'title' => 'test SMS provider',
+      'username' => 'test',
+      'password' => 'dummpy password',
+      'name' => 1,
+      'is_active' => 1,
+      'api_type' => 1,
+    );
+    CRM_SMS_BAO_Provider::saveRecord($values);
+    $provider = $this->callAPISuccess('SmsProvider', 'getsingle', array('title' => 'test SMS provider'));
+    $domain_id = CRM_Core_DAO::getFieldValue('CRM_SMS_DAO_Provider', $provider['id'], 'domain_id');
+    $this->assertEquals(CRM_Core_Config::domainID(), $domain_id);
+    CRM_SMS_BAO_Provider::del($provider['id']);
+  }
+
+}