Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tm1000 committed Oct 12, 2016
1 parent 7aab9c2 commit 6b4fc22
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 19 deletions.
65 changes: 50 additions & 15 deletions utests/source-FreePBX_ContactmanagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,63 @@

class FreePBX_ContactmanagerTest extends PHPUnit_Framework_TestCase{
protected static $o;
protected static $gid;
protected static $randnum;
protected static $randdisplayname;
protected static $randfname;
protected static $randlname;
protected static $randcompany;

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';
include_once 'setuptests.php';
include_once dirname(__DIR__).'/includes/superfecta_base.php';
include dirname(__DIR__).'/sources/source-FreePBX_Contactmanager.module';
self::$o = new FreePBX_Contactmanager();
self::$randnum = rand(1111111111,9999999999);
self::$randdisplayname = 'displayname'.substr( md5(rand()), 0, 7);
self::$randfname = 'fname'.substr( md5(rand()), 0, 7);
self::$randlname = 'lname'.substr( md5(rand()), 0, 7);
self::$randcompany = 'company'.substr( md5(rand()), 0, 7);
}
//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.");
public function setup() {
$group = FreePBX::Contactmanager()->addGroup("testgroup","external");
FreePBX::Contactmanager()->addEntryByGroupID($group['id'], array(
'user' => -1,
'displayname' => self::$randdisplayname,
'fname' => self::$randfname,
'lname' => self::$randlname,
'company' => self::$randcompany,
'numbers' => array(
array(
'number' => self::$randnum
)
)
));
self::$gid = $group['id'];
}

public function testFormat1(){
$cnam = self::$o->get_caller_id(self::$randnum,array('Return_Format' => 1));
$this->assertEquals(self::$randdisplayname, $cnam, "The lookup returned an unexpected result for ".self::$randnum);
}

public function testFormat2(){
$cnam = self::$o->get_caller_id(self::$randnum,array('Return_Format' => 2));
$this->assertEquals(self::$randcompany, $cnam, "The lookup returned an unexpected result for ".self::$randnum);
}

public function testFormat3(){
$cnam = self::$o->get_caller_id(self::$randnum,array('Return_Format' => 3));
$this->assertEquals(self::$randlname." ".self::$randfname, $cnam, "The lookup returned an unexpected result for ".self::$randnum);
}

//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 testFormat4(){
$cnam = self::$o->get_caller_id(self::$randnum,array('Return_Format' => 4));
$this->assertEquals(self::$randfname." ".self::$randlname, $cnam, "The lookup returned an unexpected result for ".self::$randnum);
}

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");
public function tearDown() {
FreePBX::Contactmanager()->deleteGroupByID(self::$gid);
}
}
7 changes: 3 additions & 4 deletions utests/source-Who_CalledTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
class Who_CalledTest 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-Who_Called.module';
include_once 'setuptests.php';
include_once dirname(__DIR__).'/includes/superfecta_base.php';
include dirname(__DIR__).'/sources/source-Who_Called.module';
self::$o = new Who_Called();
}
//Stuff before the test
Expand Down

0 comments on commit 6b4fc22

Please sign in to comment.