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_SpellCheck.
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_SpellCheckTest extends Phergie_Plugin_TestCase
34 * Checks for the pspell extension.
38 public function setUp()
42 if (!extension_loaded('pspell')) {
43 $this->markTestSkipped('pspell extension not available');
48 * Tests for the plugin failing to load when the language setting is not
53 public function testLanguageSettingNotSet()
56 $this->plugin->onLoad();
57 $this->fail('Expected exception was not thrown');
58 } catch (Phergie_Plugin_Exception $e) {
61 $this->fail('Unexpected exception was thrown');
65 * Tests for the plugin requiring the Command plugin as a dependency.
69 public function testRequiresCommandPlugin()
71 $this->setConfig('spellcheck.lang', 'en');
72 $this->assertRequiresPlugin('Command');
73 $this->plugin->onLoad();
77 * Tests for the plugin failing to load because of a dictionary error.
81 public function testLoadDictionaryError()
83 $this->setConfig('spellcheck.lang', 'foo');
85 $this->plugin->onLoad();
86 $this->fail('Expected exception not thrown');
87 } catch (Phergie_Plugin_Exception $e) {
90 $this->fail('Unexpected exception was thrown');
94 * Initializes a spell check event.
96 * @param string $word Word to be checked
100 private function initializeSpellCheckEvent($word)
102 $this->setConfig('spellcheck.lang', 'en');
103 $this->plugin->onLoad();
105 'receiver' => $this->source,
106 'text' => 'spell ' . $word
108 $event = $this->getMockEvent('privmsg', $args);
109 $this->plugin->setEvent($event);
113 * Checks for a specified response to a spell check event.
115 * @param string $word Work being checked
116 * @param string $response Expected response
120 private function checkForSpellCheckResponse($word, $response)
122 $this->assertEmitsEvent('privmsg', array($this->source, $response));
123 $this->plugin->onCommandSpell($word);
127 * Tests for the plugin returning a response for a correctly spelled word.
131 public function testRespondsForCorrectlySpelledWord()
134 $this->initializeSpellCheckEvent($word);
135 $response = $this->nick . ': The word "' . $word . '" seems to be spelled correctly.';
136 $this->checkForSpellCheckResponse($word, $response);
140 * Tests for the plugin returning a response when it can't find any
141 * suggestions for a word.
145 public function testRespondsWithoutSuggestions()
147 $word = 'kjlfljlkjljkljlj';
148 $this->initializeSpellCheckEvent($word);
149 $response = $this->nick . ': I could not find any suggestions for "' . $word . '".';
150 $this->checkForSpellCheckResponse($word, $response);
154 * Tests for the plugin returning a response when it is able to find
155 * suggestions for a word.
159 public function testRespondsWithSuggestions()
162 $this->initializeSpellCheckEvent($word);
163 $response = $this->nick . ': Suggestions for "' . $word . '": the, Te, tech, Th, eh.';
164 $this->checkForSpellCheckResponse($word, $response);