]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/PingTest.php
Merge branch '0.9.x' into 1.0.x
[quix0rs-gnu-social.git] / plugins / Irc / extlib / phergie / Tests / Phergie / Plugin / PingTest.php
1 <?php
2 /**
3  * Phergie
4  *
5  * PHP version 5
6  *
7  * LICENSE
8  *
9  * This source file is subject to the new BSD license that is bundled
10  * with this package in the file LICENSE.
11  * It is also available through the world-wide-web at this URL:
12  * http://phergie.org/license
13  *
14  * @category  Phergie
15  * @package   Phergie_Tests
16  * @author    Phergie Development Team <team@phergie.org>
17  * @copyright 2008-2010 Phergie Development Team (http://phergie.org)
18  * @license   http://phergie.org/license New BSD License
19  * @link      http://pear.phergie.org/package/Phergie_Tests
20  */
21
22 /**
23  * Unit test suite for Pherge_Plugin_Ping.
24  *
25  * @category Phergie
26  * @package  Phergie_Tests
27  * @author   Phergie Development Team <team@phergie.org>
28  * @license  http://phergie.org/license New BSD License
29  * @link     http://pear.phergie.org/package/Phergie_Tests
30  */
31 class Phergie_Plugin_PingTest extends Phergie_Plugin_TestCase
32 {
33     /**
34      * Tests that the last ping and event are initialized on connection to
35      * the server.
36      *
37      * @return void
38      */
39     public function testOnConnect()
40     {
41         $this->plugin->onConnect();
42
43         $expected = time();
44         $actual = $this->plugin->getLastEvent();
45         $this->assertEquals($expected, $actual);
46
47         $expected = null;
48         $actual = $this->plugin->getLastPing();
49         $this->assertEquals($expected, $actual);
50     }
51
52     /**
53      * Tests that the last event is reset when an event occurs.
54      *
55      * @return void
56      */
57     public function testPreEvent()
58     {
59         $this->plugin->preEvent();
60
61         $expected = time();
62         $actual = $this->plugin->getLastEvent();
63         $this->assertEquals($expected, $actual);
64     }
65
66     /**
67      * Tests that the last ping is reset when a ping is received.
68      *
69      * @return void
70      */
71     public function testOnPingResponse()
72     {
73         $this->plugin->onPingResponse();
74
75         $expected = null;
76         $actual = $this->plugin->getLastPing();
77         $this->assertEquals($expected, $actual);
78     }
79
80     /**
81      * Tests that the test suite is able to manipulate the value of the last
82      * event.
83      *
84      * @return void
85      */
86     public function testSetLastEvent()
87     {
88         $expected = time() + 1;
89         $this->plugin->setLastEvent($expected);
90         $actual = $this->plugin->getLastEvent();
91         $this->assertEquals($expected, $actual);
92
93         $this->plugin->setLastEvent();
94         $expected = time();
95         $actual = $this->plugin->getLastEvent();
96         $this->assertEquals($expected, $actual);
97
98         try {
99             $this->plugin->setLastEvent('foo');
100             $this->fail('Expected exception was not thrown');
101         } catch (Exception $e) { }
102     }
103
104     /**
105      * Tests that the test suite is able to manipulate the value of the last
106      * ping.
107      *
108      * @return void
109      */
110     public function testSetLastPing()
111     {
112         $expected = time() + 1;
113         $this->plugin->setLastPing($expected);
114         $actual = $this->plugin->getLastPing();
115         $this->assertEquals($expected, $actual);
116
117         $this->plugin->setLastPing();
118         $expected = time();
119         $actual = $this->plugin->getLastPing();
120         $this->assertEquals($expected, $actual);
121
122         try {
123             $this->plugin->setLastPing('foo');
124             $this->fail('Expected exception was not thrown');
125         } catch (Exception $e) { }
126     }
127
128     /**
129      * Tests that a ping event is sent after the appropriate time period has
130      * lapsed since receiving an event.
131      *
132      * @depends testSetLastEvent
133      * @return void
134      */
135     public function testPing()
136     {
137         $pingEvent = 10;
138         $this->setConfig('ping.event', $pingEvent);
139         $lastEvent = time() - ($pingEvent + 1);
140         $this->plugin->setLastEvent($lastEvent);
141         $expected = time();
142         $this->assertEmitsEvent('ping', array($this->nick, $expected));
143         $this->plugin->onTick();
144         $actual = $this->plugin->getLastPing();
145         $this->assertEquals($expected, $actual);
146     }
147
148     /**
149      * Tests that a quit event is sent after the appropriate time period has
150      * lapsed since sending a ping event.
151      *
152      * @depends testPing
153      * @return void
154      */
155     public function testQuit()
156     {
157         $pingPing = 10;
158         $this->setConfig('ping.ping', $pingPing);
159         $lastPing = time() - ($pingPing + 1);
160         $this->plugin->setLastPing($lastPing);
161         $this->assertEmitsEvent('quit');
162         $this->plugin->onTick();
163     }
164 }