]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/SpellCheckTest.php
8ed9f0d36d09ecfc2fae6bcccaf623244594e225
[quix0rs-gnu-social.git] / plugins / Irc / extlib / phergie / Tests / Phergie / Plugin / SpellCheckTest.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
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
20  */
21
22 require_once dirname(__FILE__) . '/TestCase.php';
23
24 /**
25  * Unit test suite for Pherge_Plugin_SpellCheck.
26  *
27  * @category Phergie
28  * @package  Phergie_Tests
29  * @author   Phergie Development Team <team@phergie.org>
30  * @license  http://phergie.org/license New BSD License
31  * @link     http://pear.phergie.org/package/Phergie
32  */
33 class Phergie_Plugin_SpellCheckTest extends Phergie_Plugin_TestCase
34 {
35
36     /**
37      * Current SpellCheck plugin instance
38      *
39      * @var Phergie_Plugin_SpellCheck
40      */
41     protected $spell;
42
43     /**
44      * Sets up the fixture, for example, opens a network connection.
45      * This method is called before a test is executed.
46      * 
47      * @return void
48      */
49     protected function setUp()
50     {
51         $this->config = array('spellcheck.lang' => 'en');
52
53         $this->spell = new Phergie_Plugin_SpellCheck();
54         $this->setPlugin(new Phergie_Plugin_Command());
55         
56         $config = $this->plugin->getConfig();
57         
58         $handler = new Phergie_Plugin_Handler($config, $this->handler);
59         $this->plugin->setPluginHandler($handler);
60         
61         $handler->addPlugin($this->plugin);
62         $handler->addPlugin($this->spell);
63
64         $this->spell->setEventHandler($this->handler);
65         $this->spell->setConnection($this->connection);
66     }
67
68     /**
69      * @event Phergie_Event_Request::privmsg
70      * @eventArg #zftalk
71      * @eventArg spell
72      */
73     public function testSpell()
74     {
75         $this->spell->onLoad();
76         
77         $this->copyEvent();
78         $this->plugin->onPrivMsg();
79         $this->assertDoesNotHaveEvent(Phergie_Event_Command::TYPE_PRIVMSG);
80     }
81
82     /**
83      * @event Phergie_Event_Request::privmsg
84      * @eventArg #phergie
85      * @eventArg spell test
86      */
87     public function testSpellTest()
88     {
89         $this->spell->onLoad();
90         
91         $this->copyEvent();
92         $this->plugin->onPrivMsg();
93
94         $events = $this->getResponseEvents(Phergie_Event_Command::TYPE_PRIVMSG);
95         
96         $this->assertEquals(1, count($events));
97         foreach ($events as $event) {
98             $args = $event->getArguments();
99             
100             $this->assertEquals('#phergie', $args[0]);
101             
102             $this->assertContains('CheckSpellUser:', $args[1]);
103             $this->assertContains('test', $args[1]);
104             $this->assertContains('correct', $args[1]);
105         }            
106     }
107
108     /**
109      * @event Phergie_Event_Request::privmsg
110      * @eventArg #phergie
111      * @eventArg spell testz
112      */
113     public function testSpellTestz()
114     {
115         $this->spell->onLoad();
116         
117         $this->copyEvent();
118         $this->plugin->onPrivMsg();
119         
120         $events = $this->getResponseEvents(Phergie_Event_Command::TYPE_PRIVMSG);
121         
122         $this->assertEquals(1, count($events));
123         foreach ($events as $event) {
124             $args = $event->getArguments();
125             
126             $this->assertEquals('#phergie', $args[0]);
127             
128             $this->assertContains('CheckSpellUser:', $args[1]);
129             $this->assertRegExp('/([a-z]+, ){4}/', $args[1]);
130             $this->assertContains('testz', $args[1]);
131             $this->assertContains('test,', $args[1]);
132         }
133     }
134
135     /**
136      * @event Phergie_Event_Request::privmsg
137      * @eventArg #phergie
138      * @eventArg spell testz
139      */
140     public function testSpellMoreSuggestions()
141     {
142         $config = $this->spell->getConfig();
143         
144         $this->copyEvent();
145         $config['spellcheck.limit'] = 6;
146         
147         $this->spell->onLoad();
148         $this->plugin->onPrivMsg();
149         
150         $events = $this->getResponseEvents(Phergie_Event_Command::TYPE_PRIVMSG);
151         
152         $this->assertEquals(1, count($events));
153         foreach ($events as $event) {
154             $args = $event->getArguments();
155             
156             $this->assertEquals('#phergie', $args[0]);
157             
158             $this->assertContains('CheckSpellUser:', $args[1]);
159             $this->assertRegExp('/([a-z]+, ){5}/', $args[1]);
160             $this->assertContains('testz', $args[1]);
161             $this->assertContains('test,', $args[1]);
162         }
163     }
164
165     /**
166      * @event Phergie_Event_Request::privmsg
167      * @eventArg #phergie
168      * @eventArg spell qwertyuiopasdfghjklzxcvbnm
169      */
170     public function testSpellNoSuggestions()
171     {
172         $this->spell->onLoad();
173         
174         $this->copyEvent();
175         $this->plugin->onPrivMsg();
176         
177         $events = $this->getResponseEvents(Phergie_Event_Command::TYPE_PRIVMSG);
178         
179         $this->assertEquals(1, count($events));
180         foreach ($events as $event) {
181             $args = $event->getArguments();
182             
183             $this->assertEquals('#phergie', $args[0]);
184             
185             $this->assertContains('CheckSpellUser:', $args[1]);
186             $this->assertContains('find any suggestions', $args[1]);
187         }
188     }
189     
190     /**
191      * Copy event from command to spell plugin
192      * 
193      * @return void
194      */
195     protected function copyEvent()
196     {
197         $hostmask = Phergie_Hostmask::fromString('CheckSpellUser!test@testing.org');
198
199         $event = $this->plugin->getEvent();
200         $event->setHostmask($hostmask);
201
202         $this->spell->setEvent($event);
203     }
204
205 }