Skip to content

Commit

Permalink
CRM-19961 Add in tests to prove logic and fix logic
Browse files Browse the repository at this point in the history
remove changes to update function

Fix style
  • Loading branch information
seamuslee001 committed Apr 10, 2017
1 parent eca6c81 commit c1ab6fe
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CRM/Core/DAO/AllCoreTables.data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 0 additions & 5 deletions CRM/SMS/BAO/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,6 @@ public static function saveRecord($values) {
* @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)) {
Expand Down
99 changes: 99 additions & 0 deletions tests/phpunit/CRM/SMS/BAO/ProviderTest.php
Original file line number Diff line number Diff line change
@@ -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']);
}

}

0 comments on commit c1ab6fe

Please sign in to comment.