File: SpellcheckerPspell.php

package info (click to toggle)
roundcube 1.6.13%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 44,888 kB
  • sloc: javascript: 195,591; php: 76,917; sql: 3,150; sh: 2,882; pascal: 1,079; makefile: 234; xml: 93; perl: 73; ansic: 48; python: 21
file content (128 lines) | stat: -rw-r--r-- 3,716 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php

namespace Roundcube\Tests\Framework;

use PHPUnit\Framework\TestCase;

/**
 * Test class to test rcube_spellcheck_pspell class
 */
class Framework_SpellcheckerPspell extends TestCase
{
    /**
     * Class constructor
     */
    function test_class()
    {
        $object = new \rcube_spellchecker_pspell(null, 'en');

        $this->assertInstanceOf(\rcube_spellchecker_pspell::class, $object, "Class constructor");
        $this->assertInstanceOf(\rcube_spellchecker_engine::class, $object, "Class constructor");
    }

    /**
     * Test languages() method
     */
    function test_languages()
    {
        if (!extension_loaded('pspell')) {
            $this->markTestSkipped();
        }

        \rcube::get_instance()->config->set('spellcheck_engine', 'pspell');

        $object = new \rcube_spellchecker();

        $langs = $object->languages();

        $this->assertSame('English (US)', $langs['en']);
    }

    /**
     * Test check() method
     */
    function test_check()
    {
        if (!extension_loaded('pspell')) {
            $this->markTestSkipped();
        }

        \rcube::get_instance()->config->set('spellcheck_engine', 'pspell');

        $object = new \rcube_spellchecker();

        $this->assertTrue($object->check('one'));

        // Test other methods that depend on the spellcheck result
        $this->assertSame(0, $object->found());
        $this->assertSame([], $object->get_words());

        $this->assertSame(
            '<?xml version="1.0" encoding="UTF-8"?><spellresult charschecked="3"></spellresult>',
            $object->get_xml()
        );

        $this->assertFalse($object->check('ony'));

        // Test other methods that depend on the spellcheck result
        $this->assertSame(1, $object->found());
        $this->assertSame(['ony'], $object->get_words());

        $this->assertMatchesRegularExpression(
            '|^<\?xml version="1.0" encoding="UTF-8"\?><spellresult charschecked="3"><c o="0" l="3">([a-zA-Z\t]+)</c></spellresult>$|',
            $object->get_xml()
        );

        // Test that links are ignored (#8527)
        $html = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body>'
            . '<p><a href="http://www.redacted.com">www.redacted.com</a></div></body></html>';

        $this->assertTrue($object->check($html, true));

        $html = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body>'
            . '<p><a href="http://www.redacted.com">http://www.redacted.com</a></div></body></html>';

        $this->assertTrue($object->check($html, true));

        $this->assertTrue($object->check('one http://www.redacted.com'));
        $this->assertTrue($object->check('one www.redacted.com'));
    }

    /**
     * Test get_suggestions() method
     */
    function test_get_suggestions()
    {
        if (!extension_loaded('pspell')) {
            $this->markTestSkipped();
        }

        \rcube::get_instance()->config->set('spellcheck_engine', 'pspell');

        $object = new \rcube_spellchecker();

        $expected = ['ON','on','Ont','only','onya','NY','onyx','Ono','any','one'];
        $result   = $object->get_suggestions('ony');

        sort($expected);
        sort($result);

        $this->assertSame($expected, $result);
    }

    /**
     * Test get_words() method
     */
    function test_get_words()
    {
        if (!extension_loaded('pspell')) {
            $this->markTestSkipped();
        }

        \rcube::get_instance()->config->set('spellcheck_engine', 'pspell');

        $object = new \rcube_spellchecker();

        $this->assertSame(['ony'], $object->get_words('ony'));
    }
}