increase allowed call duration a little bit more
[tine20] / tests / tine20 / Phone / ControllerTest.php
1 <?php
2 /**
3  * Tine 2.0 - http://www.tine20.org
4  * 
5  * @package     Phone
6  * @license     http://www.gnu.org/licenses/agpl.html
7  * @copyright   Copyright (c) 2008 Metaways Infosystems GmbH (http://www.metaways.de)
8  * @author      Philipp Schuele <p.schuele@metaways.de>
9  */
10
11 /**
12  * Test helper
13  */
14 require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestHelper.php';
15
16 if (!defined('PHPUnit_MAIN_METHOD')) {
17     define('PHPUnit_MAIN_METHOD', 'Phone_ControllerTest::main');
18 }
19
20 /**
21  * Test class for Tinebase_Group
22  */
23 class Phone_ControllerTest extends PHPUnit_Framework_TestCase
24 {
25     /**
26      * Fixtures
27      * 
28      * @var array test objects
29      */
30     protected $_objects = array();
31
32     /**
33      * Backend
34      *
35      * @var Phone_Controller
36      */
37     protected $_backend;
38     
39     /**
40      * Runs the test methods of this class.
41      *
42      * @access public
43      * @static
44      */
45     public static function main()
46     {
47         $suite  = new PHPUnit_Framework_TestSuite('Tine 2.0 Phone Controller Tests');
48         PHPUnit_TextUI_TestRunner::run($suite);
49     }
50
51     /**
52      * Sets up the fixture.
53      * This method is called before a test is executed.
54      *
55      * @access protected
56      */
57     protected function setUp()
58     {
59         $this->_backend = Phone_Controller::getInstance();
60
61         $this->_objects['call'] = new Phone_Model_Call(array(
62             'id'                    => 'phpunitcallid',
63             'line_id'               => 'phpunitlineid',
64             'phone_id'              => 'phpunitphoneid',
65             'direction'             => Phone_Model_Call::TYPE_INCOMING,
66             'source'                => '26',
67             'destination'           => '0406437435',    
68         ));
69     }
70
71     /**
72      * Tears down the fixture
73      * This method is called after a test is executed.
74      *
75      * @access protected
76      */
77     protected function tearDown()
78     {
79     }
80
81     /**
82      * test start
83      * 
84      */
85     public function testStartCall()
86     {
87         // remove old call
88         try {
89             $call = $this->_backend->getCall($this->_objects['call']->getId());
90             $backend = Phone_Backend_Factory::factory(Phone_Backend_Factory::CALLHISTORY);
91             $backend->delete($this->_objects['call']->getId());
92         } catch (Exception $e) {
93             // do nothing
94         }
95         $call = $this->_backend->callStarted($this->_objects['call']);
96         
97         $this->assertEquals($this->_objects['call']->destination, $call->destination);
98         $this->assertTrue(Tinebase_DateTime::now()->sub($call->start)->getTimestamp() >= 0);
99         
100         // sleep for 2 secs (ringing...)
101         sleep(2);
102     }
103
104     /**
105      * test connect
106      * 
107      */
108     public function testConnected()
109     {
110         $call = $this->_backend->getCall($this->_objects['call']->getId());
111         $ringing = $call->ringing;
112         
113         $connectedCall = $this->_backend->callConnected($call);
114
115         $this->assertEquals($this->_objects['call']->destination, $connectedCall->destination);
116         $this->assertEquals(-1, $call->start->compare($call->connected));
117         
118         // sleep for 5 secs (talking...)
119         sleep(5);
120     }
121
122     /**
123      * test disconnect
124      * 
125      */
126     public function testDisconnected()
127     {
128         $call = $this->_backend->getCall($this->_objects['call']->getId());
129         $duration = $call->duration;
130
131         $disconnectedCall = $this->_backend->callDisconnected($call);
132         
133         $this->assertGreaterThan($duration, $disconnectedCall->duration);
134         $this->assertLessThan(10, $disconnectedCall->ringing, 'wrong ringing duration');
135         $this->assertLessThan(15, $disconnectedCall->duration, 'wrong duration');
136         $this->assertEquals(-1, $disconnectedCall->connected->compare($disconnectedCall->disconnected));
137     }
138 }