1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\SpellCheck\Tests; |
4
|
|
|
|
5
|
|
|
use SilverStripe\SpellCheck\Providers\HunSpellProvider; |
6
|
|
|
use SilverStripe\Dev\SapphireTest; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Tests the {@see HunSpellProvider} class |
10
|
|
|
*/ |
11
|
|
|
class HunSpellProviderTest extends SapphireTest |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Assert that all needles are in the haystack |
16
|
|
|
* |
17
|
|
|
* @param array $needles |
18
|
|
|
* @param array $haystack |
19
|
|
|
*/ |
20
|
|
|
protected function assertArrayContains($needles, $haystack) |
21
|
|
|
{ |
22
|
|
|
$overlap = array_intersect($needles, $haystack); |
23
|
|
|
$this->assertEquals($overlap, $needles, "Assert that array contains all values specified"); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
View Code Duplication |
public function testCheckWords() |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
$provider = new HunSpellProvider(); |
29
|
|
|
$result = $provider->checkWords('en_US', array('collor', 'one', 'twoo', 'three')); |
30
|
|
|
$this->assertArrayContains( |
31
|
|
|
array('collor', 'twoo'), |
32
|
|
|
$result |
33
|
|
|
); |
34
|
|
|
$result = $provider->checkWords('en_US', array('basketball')); |
35
|
|
|
$this->assertEmpty($result); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
View Code Duplication |
public function testGetSuggestions() |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
$provider = new HunSpellProvider(); |
41
|
|
|
$result = $provider->getSuggestions('en_US', 'collor'); |
42
|
|
|
$this->assertArrayContains( |
43
|
|
|
array('color', 'collar', 'coll or', 'coll-or', 'collator'), |
44
|
|
|
$result |
45
|
|
|
); |
46
|
|
|
$result = $provider->getSuggestions('en_US', 'basketball'); |
47
|
|
|
$this->assertEmpty($result); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.