]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/TerryChayTest.php
e58ac6f2902daa81b450af279667070e6371f98b
[quix0rs-gnu-social.git] / plugins / Irc / extlib / phergie / Tests / Phergie / Plugin / TerryChayTest.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_TerryChay.
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_TerryChayTest extends Phergie_Plugin_TestCase
32 {
33     /**
34      * Chayism used as a consistent response when related events are
35      * triggered
36      *
37      * @var string
38      */
39     private $chayism = 'Terry Chay doesn\'t need a framework; he already knows everyone\'s code';
40
41     /**
42      * Configures the mock plugin handler to return a mock Http plugin with
43      * a mock response object populated with predetermined content.
44      *
45      * @return void
46      */
47     public function setUpHttpClient()
48     {
49         $response = $this->getMock('Phergie_Plugin_Http_Response');
50         $response
51             ->expects($this->any())
52             ->method('getContent')
53             ->will($this->returnValue($this->chayism));
54
55         $plugin = $this->getMock('Phergie_Plugin_Http');
56         $plugin
57             ->expects($this->any())
58             ->method('get')
59             ->will($this->returnValue($response));
60
61         $this->getMockPluginHandler()
62             ->expects($this->any())
63             ->method('getPlugin')
64             ->with('Http')
65             ->will($this->returnValue($plugin));
66     }
67
68     /**
69      * Tests that the plugin requires the Http plugin as a dependency.
70      *
71      * @return void
72      */
73     public function testRequiresHttpPlugin()
74     {
75         $this->assertRequiresPlugin('Http');
76         $this->plugin->onLoad();
77     }
78
79     /**
80      * Data provider for testPrivmsgTriggerReturnsChayism().
81      *
82      * @return array Enumerated array of enumerated arrays each containing
83      *               a set of parameters for a single call to
84      *               testPrivmsgTriggerReturnsChayism()
85      */
86     public function dataProviderTestPrivmsgTriggerReturnsChayism()
87     {
88         return array(
89             array('terry chay'),
90             array('terry  chay'),
91             array('tychay'),
92             array('!tychay'),
93             array('! tychay'),
94             array('foo tychay bar'),
95         );
96     }
97
98     /**
99      * Tests that appropriate triggers result in a response with a Chayism.
100      *
101      * @return void
102      * @dataProvider dataProviderTestPrivmsgTriggerReturnsChayism
103      */
104     public function testPrivmsgTriggerReturnsChayism($trigger)
105     {
106         $this->setConfig('command.prefix', '!');
107         $this->setUpHttpClient();
108         $args = array(
109             'receiver' => $this->source,
110             'text' => $trigger
111         );
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();
116     }
117
118     /**
119      * Tests that lack of an appropriate trigger results in no response with
120      * a Chayism.
121      *
122      * @return void
123      */
124     public function testNoPrivmsgTriggerDoesNotReturnChayism()
125     {
126         $args = array(
127             'receiver' => $this->source,
128             'text' => 'foo bar baz'
129         );
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();
134     }
135 }