gnu-social/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/PingTest.php

165 lines
4.4 KiB
PHP
Raw Normal View History

2010-06-16 09:55:39 +09:00
<?php
/**
* Phergie
*
* PHP version 5
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.
* It is also available through the world-wide-web at this URL:
* http://phergie.org/license
*
* @category Phergie
2010-08-13 03:58:53 +09:00
* @package Phergie_Tests
2010-06-16 09:55:39 +09:00
* @author Phergie Development Team <team@phergie.org>
* @copyright 2008-2010 Phergie Development Team (http://phergie.org)
* @license http://phergie.org/license New BSD License
2010-08-13 03:58:53 +09:00
* @link http://pear.phergie.org/package/Phergie_Tests
2010-06-16 09:55:39 +09:00
*/
/**
* Unit test suite for Pherge_Plugin_Ping.
*
* @category Phergie
* @package Phergie_Tests
* @author Phergie Development Team <team@phergie.org>
* @license http://phergie.org/license New BSD License
2010-08-13 03:58:53 +09:00
* @link http://pear.phergie.org/package/Phergie_Tests
2010-06-16 09:55:39 +09:00
*/
class Phergie_Plugin_PingTest extends Phergie_Plugin_TestCase
{
/**
2010-08-13 03:58:53 +09:00
* Tests that the last ping and event are initialized on connection to
* the server.
*
* @return void
2010-06-16 09:55:39 +09:00
*/
public function testOnConnect()
{
$this->plugin->onConnect();
2010-08-13 03:58:53 +09:00
$expected = time();
$actual = $this->plugin->getLastEvent();
$this->assertEquals($expected, $actual);
$expected = null;
$actual = $this->plugin->getLastPing();
$this->assertEquals($expected, $actual);
2010-06-16 09:55:39 +09:00
}
/**
2010-08-13 03:58:53 +09:00
* Tests that the last event is reset when an event occurs.
*
* @return void
2010-06-16 09:55:39 +09:00
*/
public function testPreEvent()
{
$this->plugin->preEvent();
2010-08-13 03:58:53 +09:00
$expected = time();
$actual = $this->plugin->getLastEvent();
$this->assertEquals($expected, $actual);
2010-06-16 09:55:39 +09:00
}
/**
2010-08-13 03:58:53 +09:00
* Tests that the last ping is reset when a ping is received.
*
* @return void
2010-06-16 09:55:39 +09:00
*/
public function testOnPingResponse()
{
$this->plugin->onPingResponse();
2010-08-13 03:58:53 +09:00
$expected = null;
$actual = $this->plugin->getLastPing();
$this->assertEquals($expected, $actual);
2010-06-16 09:55:39 +09:00
}
/**
2010-08-13 03:58:53 +09:00
* Tests that the test suite is able to manipulate the value of the last
* event.
*
* @return void
2010-06-16 09:55:39 +09:00
*/
2010-08-13 03:58:53 +09:00
public function testSetLastEvent()
2010-06-16 09:55:39 +09:00
{
2010-08-13 03:58:53 +09:00
$expected = time() + 1;
$this->plugin->setLastEvent($expected);
$actual = $this->plugin->getLastEvent();
$this->assertEquals($expected, $actual);
$this->plugin->setLastEvent();
$expected = time();
$actual = $this->plugin->getLastEvent();
$this->assertEquals($expected, $actual);
try {
$this->plugin->setLastEvent('foo');
$this->fail('Expected exception was not thrown');
} catch (Exception $e) { }
2010-06-16 09:55:39 +09:00
}
2010-08-13 03:58:53 +09:00
2010-06-16 09:55:39 +09:00
/**
2010-08-13 03:58:53 +09:00
* Tests that the test suite is able to manipulate the value of the last
* ping.
*
* @return void
2010-06-16 09:55:39 +09:00
*/
2010-08-13 03:58:53 +09:00
public function testSetLastPing()
2010-06-16 09:55:39 +09:00
{
2010-08-13 03:58:53 +09:00
$expected = time() + 1;
$this->plugin->setLastPing($expected);
$actual = $this->plugin->getLastPing();
$this->assertEquals($expected, $actual);
$this->plugin->setLastPing();
$expected = time();
$actual = $this->plugin->getLastPing();
$this->assertEquals($expected, $actual);
try {
$this->plugin->setLastPing('foo');
$this->fail('Expected exception was not thrown');
} catch (Exception $e) { }
2010-06-16 09:55:39 +09:00
}
/**
2010-08-13 03:58:53 +09:00
* Tests that a ping event is sent after the appropriate time period has
* lapsed since receiving an event.
*
* @depends testSetLastEvent
* @return void
2010-06-16 09:55:39 +09:00
*/
2010-08-13 03:58:53 +09:00
public function testPing()
2010-06-16 09:55:39 +09:00
{
2010-08-13 03:58:53 +09:00
$pingEvent = 10;
$this->setConfig('ping.event', $pingEvent);
$lastEvent = time() - ($pingEvent + 1);
$this->plugin->setLastEvent($lastEvent);
$expected = time();
$this->assertEmitsEvent('ping', array($this->nick, $expected));
2010-06-16 09:55:39 +09:00
$this->plugin->onTick();
2010-08-13 03:58:53 +09:00
$actual = $this->plugin->getLastPing();
$this->assertEquals($expected, $actual);
2010-06-16 09:55:39 +09:00
}
/**
2010-08-13 03:58:53 +09:00
* Tests that a quit event is sent after the appropriate time period has
* lapsed since sending a ping event.
*
* @depends testPing
* @return void
2010-06-16 09:55:39 +09:00
*/
2010-08-13 03:58:53 +09:00
public function testQuit()
2010-06-16 09:55:39 +09:00
{
2010-08-13 03:58:53 +09:00
$pingPing = 10;
$this->setConfig('ping.ping', $pingPing);
$lastPing = time() - ($pingPing + 1);
$this->plugin->setLastPing($lastPing);
$this->assertEmitsEvent('quit');
2010-06-16 09:55:39 +09:00
$this->plugin->onTick();
}
2010-08-13 03:58:53 +09:00
}