forked from FreePBX/superfecta
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request FreePBX#3 in FREEPBX/superfecta from feature/FREEP…
…BX-12238 to release/13.0 * commit '13d318623a69cca2887f70f656f0c2944461ad08': FREEPBX-12238 Add Contact Manager source with test
- Loading branch information
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* Uses FreePBX Contact manager to lookup numbers; | ||
*/ | ||
class FreePBX_Contactmanager extends superfecta_base { | ||
|
||
public $description; | ||
public $version_requirement = "2.11"; | ||
public $source_param = array( | ||
'Return_Format' => array( | ||
'description' => 'The format to return any found caller ID in.', | ||
'type' => 'select', | ||
'option' => array ( | ||
'1' => 'Display Name', | ||
'2' => 'Company', | ||
'3' => 'Last First', | ||
'4' => 'First Last', | ||
), | ||
'default' => '4', | ||
), | ||
); | ||
|
||
public function __construct() { | ||
$this->description = _("Searches FreePBX Contact manager for name."); | ||
} | ||
|
||
function get_caller_id($thenumber, $run_param=array()) { | ||
$caller_id = null; | ||
$data = FreePBX::Contactmanager()->lookupByUserID(-1, $thenumber,"/\D/"); | ||
if(empty($data)){ | ||
return null; | ||
} | ||
$first = !empty($data['fname'])?$data['fname']:''; | ||
$last = !empty($data['lname'])?$data['lname']:''; | ||
$company = !empty($data['company'])?$data['company']:'Unknown'; | ||
$displayname = !empty($data['displayname'])?$data['displayname']:'Unknown'; | ||
|
||
if(empty($first) && empty($last)){ | ||
$first = 'Unknown'; | ||
} | ||
$format = isset($run_param['Return_Format'])?$run_param['Return_Format']:'4'; | ||
switch($format){ | ||
case '1': | ||
$caller_id = $displayname; | ||
break; | ||
case '2': | ||
$caller_id = $company; | ||
break; | ||
case '3': | ||
$caller_id = $last .' ' .$first; | ||
break; | ||
case '4': | ||
default: | ||
$caller_id = $first .' ' .$last; | ||
break; | ||
} | ||
|
||
return $caller_id; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/** | ||
* https://blogs.kent.ac.uk/webdev/2011/07/14/phpunit-and-unserialized-pdo-instances/ | ||
* @backupGlobals disabled | ||
*/ | ||
|
||
class FreePBX_ContactmanagerTest extends PHPUnit_Framework_TestCase{ | ||
protected static $o; | ||
public static function setUpBeforeClass() { | ||
include 'setuptests.php'; | ||
$webroot = FreePBX::Config()->get('AMPWEBROOT'); | ||
include $webroot.'/admin/modules/superfecta/includes/superfecta_base.php'; | ||
include $webroot.'/admin/modules/superfecta/sources/source-FreePBX_Contactmanager.module'; | ||
self::$o = new FreePBX_Contactmanager(); | ||
} | ||
//Stuff before the test | ||
public function setup() {} | ||
//Leave this alone, it test that PHPUnit is working | ||
public function testPHPUnit() { | ||
$this->assertEquals("test", "test", "PHPUnit is broken."); | ||
$this->assertNotEquals("test", "nottest", "PHPUnit is broken."); | ||
} | ||
|
||
//This tests that the the object for your class is an object | ||
public function testCreate() {; | ||
$this->assertTrue(is_object(self::$o), "Did not get an object"); | ||
} | ||
|
||
public function testCnam(){ | ||
$cnam = self::$o->get_caller_id('4805551212',array('Return Format' => 3)); | ||
$this->assertEquals("Jimmy John", $cnam, "The lookup returned an unexpected result for 6305434316"); | ||
} | ||
} |