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
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
22 require_once dirname(__FILE__) . '/TestCase.php';
25 * Unit test suite for Pherge_Plugin_SpellCheck.
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
33 class Phergie_Plugin_SpellCheckTest extends Phergie_Plugin_TestCase
37 * Current SpellCheck plugin instance
39 * @var Phergie_Plugin_SpellCheck
44 * Sets up the fixture, for example, opens a network connection.
45 * This method is called before a test is executed.
49 protected function setUp()
51 $this->config = array('spellcheck.lang' => 'en');
53 $this->spell = new Phergie_Plugin_SpellCheck();
54 $this->setPlugin(new Phergie_Plugin_Command());
56 $config = $this->plugin->getConfig();
58 $handler = new Phergie_Plugin_Handler($config, $this->handler);
59 $this->plugin->setPluginHandler($handler);
61 $handler->addPlugin($this->plugin);
62 $handler->addPlugin($this->spell);
64 $this->spell->setEventHandler($this->handler);
65 $this->spell->setConnection($this->connection);
69 * @event Phergie_Event_Request::privmsg
73 public function testSpell()
75 $this->spell->onLoad();
78 $this->plugin->onPrivMsg();
79 $this->assertDoesNotHaveEvent(Phergie_Event_Command::TYPE_PRIVMSG);
83 * @event Phergie_Event_Request::privmsg
85 * @eventArg spell test
87 public function testSpellTest()
89 $this->spell->onLoad();
92 $this->plugin->onPrivMsg();
94 $events = $this->getResponseEvents(Phergie_Event_Command::TYPE_PRIVMSG);
96 $this->assertEquals(1, count($events));
97 foreach ($events as $event) {
98 $args = $event->getArguments();
100 $this->assertEquals('#phergie', $args[0]);
102 $this->assertContains('CheckSpellUser:', $args[1]);
103 $this->assertContains('test', $args[1]);
104 $this->assertContains('correct', $args[1]);
109 * @event Phergie_Event_Request::privmsg
111 * @eventArg spell testz
113 public function testSpellTestz()
115 $this->spell->onLoad();
118 $this->plugin->onPrivMsg();
120 $events = $this->getResponseEvents(Phergie_Event_Command::TYPE_PRIVMSG);
122 $this->assertEquals(1, count($events));
123 foreach ($events as $event) {
124 $args = $event->getArguments();
126 $this->assertEquals('#phergie', $args[0]);
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]);
136 * @event Phergie_Event_Request::privmsg
138 * @eventArg spell testz
140 public function testSpellMoreSuggestions()
142 $config = $this->spell->getConfig();
145 $config['spellcheck.limit'] = 6;
147 $this->spell->onLoad();
148 $this->plugin->onPrivMsg();
150 $events = $this->getResponseEvents(Phergie_Event_Command::TYPE_PRIVMSG);
152 $this->assertEquals(1, count($events));
153 foreach ($events as $event) {
154 $args = $event->getArguments();
156 $this->assertEquals('#phergie', $args[0]);
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]);
166 * @event Phergie_Event_Request::privmsg
168 * @eventArg spell qwertyuiopasdfghjklzxcvbnm
170 public function testSpellNoSuggestions()
172 $this->spell->onLoad();
175 $this->plugin->onPrivMsg();
177 $events = $this->getResponseEvents(Phergie_Event_Command::TYPE_PRIVMSG);
179 $this->assertEquals(1, count($events));
180 foreach ($events as $event) {
181 $args = $event->getArguments();
183 $this->assertEquals('#phergie', $args[0]);
185 $this->assertContains('CheckSpellUser:', $args[1]);
186 $this->assertContains('find any suggestions', $args[1]);
191 * Copy event from command to spell plugin
195 protected function copyEvent()
197 $hostmask = Phergie_Hostmask::fromString('CheckSpellUser!test@testing.org');
199 $event = $this->plugin->getEvent();
200 $event->setHostmask($hostmask);
202 $this->spell->setEvent($event);