]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/SpellCheckTest.php
Merge branch '0.9.x' into 1.0.x
[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_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_SpellCheck.
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_SpellCheckTest extends Phergie_Plugin_TestCase
32 {
33     /**
34      * Checks for the pspell extension.
35      *
36      * @return void
37      */
38     public function setUp()
39     {
40         parent::setUp();
41
42         if (!extension_loaded('pspell')) {
43             $this->markTestSkipped('pspell extension not available');
44         }
45     }
46
47     /**
48      * Tests for the plugin failing to load when the language setting is not
49      * specified.
50      *
51      * @return void
52      */
53     public function testLanguageSettingNotSet()
54     {
55         try {
56             $this->plugin->onLoad();
57             $this->fail('Expected exception was not thrown');
58         } catch (Phergie_Plugin_Exception $e) {
59             return;
60         }
61         $this->fail('Unexpected exception was thrown');
62     }
63
64     /**
65      * Tests for the plugin requiring the Command plugin as a dependency.
66      *
67      * @return void
68      */
69     public function testRequiresCommandPlugin()
70     {
71         $this->setConfig('spellcheck.lang', 'en');
72         $this->assertRequiresPlugin('Command');
73         $this->plugin->onLoad();
74     }
75
76     /**
77      * Tests for the plugin failing to load because of a dictionary error.
78      *
79      * @return void
80      */
81     public function testLoadDictionaryError()
82     {
83         $this->setConfig('spellcheck.lang', 'foo');
84         try {
85             $this->plugin->onLoad();
86             $this->fail('Expected exception not thrown');
87         } catch (Phergie_Plugin_Exception $e) {
88             return;
89         }
90         $this->fail('Unexpected exception was thrown');
91     }
92
93     /**
94      * Initializes a spell check event.
95      *
96      * @param string $word Word to be checked
97      *
98      * @return void
99      */
100     private function initializeSpellCheckEvent($word)
101     {
102         $this->setConfig('spellcheck.lang', 'en');
103         $this->plugin->onLoad();
104         $args = array(
105             'receiver' => $this->source,
106             'text' => 'spell ' . $word
107         );
108         $event = $this->getMockEvent('privmsg', $args);
109         $this->plugin->setEvent($event);
110     }
111
112     /**
113      * Checks for a specified response to a spell check event.
114      *
115      * @param string $word     Work being checked
116      * @param string $response Expected response
117      *
118      * @return void
119      */
120     private function checkForSpellCheckResponse($word, $response)
121     {
122         $this->assertEmitsEvent('privmsg', array($this->source, $response));
123         $this->plugin->onCommandSpell($word);
124     }
125
126     /**
127      * Tests for the plugin returning a response for a correctly spelled word.
128      *
129      * @return void
130      */
131     public function testRespondsForCorrectlySpelledWord()
132     {
133         $word = 'test';
134         $this->initializeSpellCheckEvent($word);
135         $response = $this->nick . ': The word "' . $word . '" seems to be spelled correctly.';
136         $this->checkForSpellCheckResponse($word, $response);
137     }
138
139     /**
140      * Tests for the plugin returning a response when it can't find any
141      * suggestions for a word.
142      *
143      * @return void
144      */
145     public function testRespondsWithoutSuggestions()
146     {
147         $word = 'kjlfljlkjljkljlj';
148         $this->initializeSpellCheckEvent($word);
149         $response = $this->nick . ': I could not find any suggestions for "' . $word . '".';
150         $this->checkForSpellCheckResponse($word, $response);
151     }
152
153     /**
154      * Tests for the plugin returning a response when it is able to find
155      * suggestions for a word.
156      *
157      * @return void
158      */
159     public function testRespondsWithSuggestions()
160     {
161         $word = 'teh';
162         $this->initializeSpellCheckEvent($word);
163         $response = $this->nick . ': Suggestions for "' . $word . '": the, Te, tech, Th, eh.';
164         $this->checkForSpellCheckResponse($word, $response);
165     }
166 }