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_TerryChay.
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_TerryChayTest extends Phergie_Plugin_TestCase
34 * Chayism used as a consistent response when related events are
39 private $chayism = 'Terry Chay doesn\'t need a framework; he already knows everyone\'s code';
42 * Configures the mock plugin handler to return a mock Http plugin with
43 * a mock response object populated with predetermined content.
47 public function setUpHttpClient()
49 $response = $this->getMock('Phergie_Plugin_Http_Response');
51 ->expects($this->any())
52 ->method('getContent')
53 ->will($this->returnValue($this->chayism));
55 $plugin = $this->getMock('Phergie_Plugin_Http');
57 ->expects($this->any())
59 ->will($this->returnValue($response));
61 $this->getMockPluginHandler()
62 ->expects($this->any())
65 ->will($this->returnValue($plugin));
69 * Tests that the plugin requires the Http plugin as a dependency.
73 public function testRequiresHttpPlugin()
75 $this->assertRequiresPlugin('Http');
76 $this->plugin->onLoad();
80 * Data provider for testPrivmsgTriggerReturnsChayism().
82 * @return array Enumerated array of enumerated arrays each containing
83 * a set of parameters for a single call to
84 * testPrivmsgTriggerReturnsChayism()
86 public function dataProviderTestPrivmsgTriggerReturnsChayism()
94 array('foo tychay bar'),
99 * Tests that appropriate triggers result in a response with a Chayism.
102 * @dataProvider dataProviderTestPrivmsgTriggerReturnsChayism
104 public function testPrivmsgTriggerReturnsChayism($trigger)
106 $this->setConfig('command.prefix', '!');
107 $this->setUpHttpClient();
109 'receiver' => $this->source,
112 $event = $this->getMockEvent('privmsg', $args);
113 $this->plugin->setEvent($event);
114 $this->assertEmitsEvent('privmsg', array($this->source, 'Fact: ' . $this->chayism));
115 $this->plugin->onPrivmsg();
119 * Tests that lack of an appropriate trigger results in no response with
124 public function testNoPrivmsgTriggerDoesNotReturnChayism()
127 'receiver' => $this->source,
128 'text' => 'foo bar baz'
130 $event = $this->getMockEvent('privmsg', $args);
131 $this->plugin->setEvent($event);
132 $this->assertDoesNotEmitEvent('privmsg', array($this->source, 'Fact: ' . $this->chayism));
133 $this->plugin->onPrivmsg();