1 | <?php |
---|
2 | /** |
---|
3 | * Copyright 2011 Bas de Nooijer. All rights reserved. |
---|
4 | * |
---|
5 | * Redistribution and use in source and binary forms, with or without |
---|
6 | * modification, are permitted provided that the following conditions are met: |
---|
7 | * |
---|
8 | * 1. Redistributions of source code must retain the above copyright notice, |
---|
9 | * this list of conditions and the following disclaimer. |
---|
10 | * |
---|
11 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
---|
12 | * this listof conditions and the following disclaimer in the documentation |
---|
13 | * and/or other materials provided with the distribution. |
---|
14 | * |
---|
15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" |
---|
16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
---|
19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
25 | * POSSIBILITY OF SUCH DAMAGE. |
---|
26 | * |
---|
27 | * The views and conclusions contained in the software and documentation are |
---|
28 | * those of the authors and should not be interpreted as representing official |
---|
29 | * policies, either expressed or implied, of the copyright holder. |
---|
30 | */ |
---|
31 | |
---|
32 | class Solarium_Client_ResponseParser_Select_Component_SpellcheckTest extends PHPUnit_Framework_TestCase |
---|
33 | { |
---|
34 | |
---|
35 | protected $_parser; |
---|
36 | |
---|
37 | public function setUp() |
---|
38 | { |
---|
39 | $this->_parser = new Solarium_Client_ResponseParser_Select_Component_Spellcheck(); |
---|
40 | } |
---|
41 | |
---|
42 | public function testParseExtended() |
---|
43 | { |
---|
44 | $data = array( |
---|
45 | 'spellcheck' => array( |
---|
46 | 'suggestions' => array( |
---|
47 | 0 => 'delll', |
---|
48 | 1 => array ( |
---|
49 | 'numFound' => 1, |
---|
50 | 'startOffset' => 0, |
---|
51 | 'endOffset' => 5, |
---|
52 | 'origFreq' => 0, |
---|
53 | 'suggestion' => array ( |
---|
54 | 0 => array ( |
---|
55 | 'word' => 'dell', 'freq' => 1 |
---|
56 | ), |
---|
57 | ), |
---|
58 | ), |
---|
59 | 2 => 'ultrashar', |
---|
60 | 3 => array ( |
---|
61 | 'numFound' => 1, |
---|
62 | 'startOffset' => 6, |
---|
63 | 'endOffset' => 15, |
---|
64 | 'origFreq' => 0, |
---|
65 | 'suggestion' => array ( |
---|
66 | 0 => array ( |
---|
67 | 'word' => 'ultrasharp', |
---|
68 | 'freq' => 1 |
---|
69 | ), |
---|
70 | ), |
---|
71 | ), |
---|
72 | 4 => 'correctlySpelled', |
---|
73 | 5 => false, |
---|
74 | 6 => 'collation', |
---|
75 | 7 => array ( |
---|
76 | 0 => 'collationQuery', |
---|
77 | 1 => 'dell ultrasharp', |
---|
78 | 2 => 'hits', |
---|
79 | 3 => 0, |
---|
80 | 4 => 'misspellingsAndCorrections', |
---|
81 | 5 => array ( |
---|
82 | 0 => 'delll', |
---|
83 | 1 => 'dell', |
---|
84 | 2 => 'ultrashar', |
---|
85 | 3 => 'ultrasharp' |
---|
86 | ), |
---|
87 | ), |
---|
88 | ) |
---|
89 | ) |
---|
90 | ); |
---|
91 | |
---|
92 | $result = $this->_parser->parse(null, null, $data); |
---|
93 | |
---|
94 | $suggestions = $result->getSuggestions(); |
---|
95 | $this->assertEquals(false, $result->getCorrectlySpelled()); |
---|
96 | $this->assertEquals('dell', $suggestions[0]->getWord()); |
---|
97 | $this->assertEquals('dell ultrasharp', $result->getCollation()->getQuery()); |
---|
98 | } |
---|
99 | |
---|
100 | public function testParse() |
---|
101 | { |
---|
102 | $data = array( |
---|
103 | 'spellcheck' => array( |
---|
104 | 'suggestions' => array( |
---|
105 | 0 => 'delll', |
---|
106 | 1 => array ( |
---|
107 | 'numFound' => 1, |
---|
108 | 'startOffset' => 0, |
---|
109 | 'endOffset' => 5, |
---|
110 | 'origFreq' => 0, |
---|
111 | 'suggestion' => array ( |
---|
112 | 0 => 'dell', |
---|
113 | ), |
---|
114 | ), |
---|
115 | 2 => 'ultrashar', |
---|
116 | 3 => array ( |
---|
117 | 'numFound' => 1, |
---|
118 | 'startOffset' => 6, |
---|
119 | 'endOffset' => 15, |
---|
120 | 'origFreq' => 0, |
---|
121 | 'suggestion' => array ( |
---|
122 | 0 => array ( |
---|
123 | 'word' => 'ultrasharp', |
---|
124 | 'freq' => 1 |
---|
125 | ), |
---|
126 | ), |
---|
127 | ), |
---|
128 | 4 => 'correctlySpelled', |
---|
129 | 5 => false, |
---|
130 | 6 => 'collation', |
---|
131 | 7 => 'dell ultrasharp', |
---|
132 | ) |
---|
133 | ) |
---|
134 | ); |
---|
135 | |
---|
136 | $result = $this->_parser->parse(null, null, $data); |
---|
137 | |
---|
138 | $suggestions = $result->getSuggestions(); |
---|
139 | $this->assertEquals(false, $result->getCorrectlySpelled()); |
---|
140 | $this->assertEquals('dell', $suggestions[0]->getWord()); |
---|
141 | $this->assertEquals('dell ultrasharp', $result->getCollation()->getQuery()); |
---|
142 | } |
---|
143 | |
---|
144 | public function testParseNoData() |
---|
145 | { |
---|
146 | $result = $this->_parser->parse(null, null, array()); |
---|
147 | |
---|
148 | $this->assertEquals(null, $result); |
---|
149 | } |
---|
150 | |
---|
151 | } |
---|