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
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
23 * Unit test suite for Pherge_Plugin_Ping.
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
31 class Phergie_Plugin_PingTest extends Phergie_Plugin_TestCase
34 * Tests that the last ping and event are initialized on connection to
39 public function testOnConnect()
41 $this->plugin->onConnect();
44 $actual = $this->plugin->getLastEvent();
45 $this->assertEquals($expected, $actual);
48 $actual = $this->plugin->getLastPing();
49 $this->assertEquals($expected, $actual);
53 * Tests that the last event is reset when an event occurs.
57 public function testPreEvent()
59 $this->plugin->preEvent();
62 $actual = $this->plugin->getLastEvent();
63 $this->assertEquals($expected, $actual);
67 * Tests that the last ping is reset when a ping is received.
71 public function testOnPingResponse()
73 $this->plugin->onPingResponse();
76 $actual = $this->plugin->getLastPing();
77 $this->assertEquals($expected, $actual);
81 * Tests that the test suite is able to manipulate the value of the last
86 public function testSetLastEvent()
88 $expected = time() + 1;
89 $this->plugin->setLastEvent($expected);
90 $actual = $this->plugin->getLastEvent();
91 $this->assertEquals($expected, $actual);
93 $this->plugin->setLastEvent();
95 $actual = $this->plugin->getLastEvent();
96 $this->assertEquals($expected, $actual);
99 $this->plugin->setLastEvent('foo');
100 $this->fail('Expected exception was not thrown');
101 } catch (Exception $e) { }
105 * Tests that the test suite is able to manipulate the value of the last
110 public function testSetLastPing()
112 $expected = time() + 1;
113 $this->plugin->setLastPing($expected);
114 $actual = $this->plugin->getLastPing();
115 $this->assertEquals($expected, $actual);
117 $this->plugin->setLastPing();
119 $actual = $this->plugin->getLastPing();
120 $this->assertEquals($expected, $actual);
123 $this->plugin->setLastPing('foo');
124 $this->fail('Expected exception was not thrown');
125 } catch (Exception $e) { }
129 * Tests that a ping event is sent after the appropriate time period has
130 * lapsed since receiving an event.
132 * @depends testSetLastEvent
135 public function testPing()
138 $this->setConfig('ping.event', $pingEvent);
139 $lastEvent = time() - ($pingEvent + 1);
140 $this->plugin->setLastEvent($lastEvent);
142 $this->assertEmitsEvent('ping', array($this->nick, $expected));
143 $this->plugin->onTick();
144 $actual = $this->plugin->getLastPing();
145 $this->assertEquals($expected, $actual);
149 * Tests that a quit event is sent after the appropriate time period has
150 * lapsed since sending a ping event.
155 public function testQuit()
158 $this->setConfig('ping.ping', $pingPing);
159 $lastPing = time() - ($pingPing + 1);
160 $this->plugin->setLastPing($lastPing);
161 $this->assertEmitsEvent('quit');
162 $this->plugin->onTick();