Merge pull request #14662 from eileenmcnaughton/activity_pdf_71
[civicrm-core.git] / tests / phpunit / CRM / SMS / BAO / ProviderTest.php
CommitLineData
c1ab6fe3
SL
1<?php
2
3/*
4 +--------------------------------------------------------------------+
7d61e75f 5 | Copyright CiviCRM LLC. All rights reserved. |
c1ab6fe3 6 | |
7d61e75f
TO
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
c1ab6fe3
SL
10 +--------------------------------------------------------------------+
11 */
12/**
13 * Test CRM_SMS_BAO_Provider functions
14 *
15 * @package CiviCRM_APIv3
16 * @subpackage API_Contribution
17 * @group headless
18 */
19class CRM_SMS_BAO_ProviderTest extends CiviUnitTestCase {
20
21 /**
22 * Set Up Funtion
23 */
24 public function setUp() {
25 parent::setUp();
9099cab3 26 $option = $this->callAPISuccess('option_value', 'create', ['option_group_id' => 'sms_provider_name', 'name' => 'test_provider_name', 'label' => 'test_provider_name', 'value' => 1]);
c1ab6fe3
SL
27 $this->option_value = $option['id'];
28 }
29
30 /**
31 * Clean up after each test.
32 */
33 public function tearDown() {
34 parent::tearDown();
9099cab3 35 $this->callAPISuccess('option_value', 'delete', ['id' => $this->option_value]);
c1ab6fe3
SL
36 }
37
38 /**
39 * CRM-19961 Check that when saving and updating a SMS provider with domain as NULL that it stays null
40 */
41 public function testCreateAndUpdateProvider() {
9099cab3 42 $values = [
c1ab6fe3
SL
43 'domain_id' => NULL,
44 'title' => 'test SMS provider',
45 'username' => 'test',
46 'password' => 'dummpy password',
47 'name' => 1,
48 'is_active' => 1,
49 'api_type' => 1,
9099cab3 50 ];
59248c40 51 $this->callAPISuccess('SmsProvider', 'create', $values);
9099cab3 52 $provider = $this->callAPISuccess('SmsProvider', 'getsingle', ['title' => 'test SMS provider']);
c1ab6fe3
SL
53 $domain_id = CRM_Core_DAO::getFieldValue('CRM_SMS_DAO_Provider', $provider['id'], 'domain_id');
54 $this->assertNull($domain_id);
9099cab3 55 $values2 = ['title' => 'Test SMS Provider2', 'id' => $provider['id']];
449fbe14 56 $this->callAPISuccess('SmsProvider', 'create', $values2);
9099cab3 57 $provider = $this->callAPISuccess('SmsProvider', 'getsingle', ['id' => $provider['id']]);
c1ab6fe3
SL
58 $this->assertEquals('Test SMS Provider2', $provider['title']);
59 $domain_id = CRM_Core_DAO::getFieldValue('CRM_SMS_DAO_Provider', $provider['id'], 'domain_id');
60 $this->assertNull($domain_id);
61 CRM_SMS_BAO_Provider::del($provider['id']);
62 }
63
eb6078c8
SL
64 /**
65 * CRM-20989
66 * Add unit test to ensure that filtering by domain works in get Active Providers
67 */
68 public function testActiveProviderCount() {
9099cab3 69 $values = [
eb6078c8
SL
70 'domain_id' => NULL,
71 'title' => 'test SMS provider',
72 'username' => 'test',
73 'password' => 'dummpy password',
74 'name' => 1,
75 'is_active' => 1,
76 'api_type' => 1,
9099cab3 77 ];
eb6078c8 78 $provider = $this->callAPISuccess('SmsProvider', 'create', $values);
9099cab3 79 $provider2 = $this->callAPISuccess('SmsProvider', 'create', array_merge($values, ['domain_id' => 2]));
eb6078c8
SL
80 $result = CRM_SMS_BAO_Provider::activeProviderCount();
81 $this->assertEquals(1, $result);
9099cab3 82 $provider3 = $this->callAPISuccess('SmsProvider', 'create', array_merge($values, ['domain_id' => 1]));
eb6078c8
SL
83 $result = CRM_SMS_BAO_Provider::activeProviderCount();
84 $this->assertEquals(2, $result);
85 CRM_SMS_BAO_Provider::del($provider['id']);
86 CRM_SMS_BAO_Provider::del($provider2['id']);
87 CRM_SMS_BAO_Provider::del($provider3['id']);
88 }
89
c1ab6fe3
SL
90 /**
91 * CRM-19961 Check that when a domain is not passed when saving it defaults to current domain when create
92 */
93 public function testCreateWithoutDomain() {
9099cab3 94 $values = [
c1ab6fe3
SL
95 'title' => 'test SMS provider',
96 'username' => 'test',
97 'password' => 'dummpy password',
98 'name' => 1,
99 'is_active' => 1,
100 'api_type' => 1,
9099cab3 101 ];
449fbe14 102 $this->callAPISuccess('SmsProvider', 'create', $values);
9099cab3 103 $provider = $this->callAPISuccess('SmsProvider', 'getsingle', ['title' => 'test SMS provider']);
c1ab6fe3
SL
104 $domain_id = CRM_Core_DAO::getFieldValue('CRM_SMS_DAO_Provider', $provider['id'], 'domain_id');
105 $this->assertEquals(CRM_Core_Config::domainID(), $domain_id);
106 CRM_SMS_BAO_Provider::del($provider['id']);
107 }
108
109}