Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-20989 Fix Active provider count to know about multisite #10792

Merged
merged 2 commits into from
Jul 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CRM/SMS/BAO/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public function __construct() {
* @return null|string
*/
public static function activeProviderCount() {
$activeProviders = CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_sms_provider WHERE is_active = 1');
$activeProviders = CRM_Core_DAO::singleValueQuery('SELECT count(id) FROM civicrm_sms_provider WHERE is_active = 1 AND (domain_id = %1 OR domain_id IS NULL)',
array(1 => array(CRM_Core_Config::domainID(), 'Positive')));
return $activeProviders;
}

Expand Down
26 changes: 26 additions & 0 deletions tests/phpunit/CRM/SMS/BAO/ProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,32 @@ public function testCreateAndUpdateProvider() {
CRM_SMS_BAO_Provider::del($provider['id']);
}

/**
* CRM-20989
* Add unit test to ensure that filtering by domain works in get Active Providers
*/
public function testActiveProviderCount() {
$values = array(
'domain_id' => NULL,
'title' => 'test SMS provider',
'username' => 'test',
'password' => 'dummpy password',
'name' => 1,
'is_active' => 1,
'api_type' => 1,
);
$provider = $this->callAPISuccess('SmsProvider', 'create', $values);
$provider2 = $this->callAPISuccess('SmsProvider', 'create', array_merge($values, array('domain_id' => 2)));
$result = CRM_SMS_BAO_Provider::activeProviderCount();
$this->assertEquals(1, $result);
$provider3 = $this->callAPISuccess('SmsProvider', 'create', array_merge($values, array('domain_id' => 1)));
$result = CRM_SMS_BAO_Provider::activeProviderCount();
$this->assertEquals(2, $result);
CRM_SMS_BAO_Provider::del($provider['id']);
CRM_SMS_BAO_Provider::del($provider2['id']);
CRM_SMS_BAO_Provider::del($provider3['id']);
}

/**
* CRM-19961 Check that when a domain is not passed when saving it defaults to current domain when create
*/
Expand Down