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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
<?php
require_once(LIB_PATH . '/lib_date.php');
class ContextTest extends \PHPUnit_Framework_TestCase {
private $context;
public function setUp() {
$this->context = new FreshRSS_Context();
}
public function testParseSearch_whenEmpty_returnsEmptyArray() {
$this->assertCount(0, $this->context->parseSearch());
}
/**
* @dataProvider provideMultipleKeywordSearch
* @param string $search
* @param string $expected_values
*/
public function testParseSearch_whenMultipleKeywords_returnArrayWithMultipleValues($search, $expected_values) {
FreshRSS_Context::$search = $search;
$parsed_search = $this->context->parseSearch();
$this->assertEquals($expected_values, $parsed_search);
}
/**
* @return array
*/
public function provideMultipleKeywordSearch() {
return array(
array(
'intitle:word1 author:word2',
array(
'intitle' => 'word1',
'author' => 'word2',
),
),
array(
'author:word2 intitle:word1',
array(
'intitle' => 'word1',
'author' => 'word2',
),
),
array(
'author:word1 inurl:word2',
array(
'author' => 'word1',
'inurl' => 'word2',
),
),
array(
'inurl:word2 author:word1',
array(
'author' => 'word1',
'inurl' => 'word2',
),
),
array(
'date:2008-01-01/2008-02-01 pubdate:2007-01-01/2007-02-01',
array(
'min_date' => '1199163600',
'max_date' => '1201928399',
'min_pubdate' => '1167627600',
'max_pubdate' => '1170392399',
),
),
array(
'pubdate:2007-01-01/2007-02-01 date:2008-01-01/2008-02-01',
array(
'min_date' => '1199163600',
'max_date' => '1201928399',
'min_pubdate' => '1167627600',
'max_pubdate' => '1170392399',
),
),
array(
'inurl:word1 author:word2 intitle:word3 pubdate:2007-01-01/2007-02-01 date:2008-01-01/2008-02-01 hello world',
array(
'inurl' => 'word1',
'author' => 'word2',
'intitle' => 'word3',
'min_date' => '1199163600',
'max_date' => '1201928399',
'min_pubdate' => '1167627600',
'max_pubdate' => '1170392399',
'search' => 'hello world',
),
),
);
}
/**
* @dataProvider provideIntitleSearch
* @param string $search
* @param string $expected_value
*/
public function testParseSearch_whenIntitleKeyword_returnArrayWithIntitleValue($search, $expected_value) {
FreshRSS_Context::$search = $search;
$parsed_search = $this->context->parseSearch();
$this->assertEquals($expected_value, $parsed_search['intitle']);
}
/**
* @return array
*/
public function provideIntitleSearch() {
return array(
array('intitle:word1', 'word1'),
array('intitle:word1 word2', 'word1'),
array('intitle:"word1 word2"', 'word1 word2'),
array("intitle:'word1 word2'", 'word1 word2'),
array('word1 intitle:word2', 'word2'),
array('word1 intitle:word2 word3', 'word2'),
array('word1 intitle:"word2 word3"', 'word2 word3'),
array("word1 intitle:'word2 word3'", 'word2 word3'),
array('intitle:word1 intitle:word2', 'word1'),
array('intitle: word1 word2', ''),
array('intitle:123', '123'),
array('intitle:"word1 word2" word3"', 'word1 word2'),
array("intitle:'word1 word2' word3'", 'word1 word2'),
array('intitle:"word1 word2\' word3"', "word1 word2' word3"),
array("intitle:'word1 word2\" word3'", 'word1 word2" word3'),
);
}
/**
* @dataProvider provideAuthorSearch
* @param string $search
* @param string $expected_value
*/
public function testParseSearch_whenAuthorKeyword_returnArrayWithAuthorValue($search, $expected_value) {
FreshRSS_Context::$search = $search;
$parsed_search = $this->context->parseSearch();
$this->assertEquals($expected_value, $parsed_search['author']);
}
/**
* @return array
*/
public function provideAuthorSearch() {
return array(
array('author:word1', 'word1'),
array('author:word1 word2', 'word1'),
array('author:"word1 word2"', 'word1 word2'),
array("author:'word1 word2'", 'word1 word2'),
array('word1 author:word2', 'word2'),
array('word1 author:word2 word3', 'word2'),
array('word1 author:"word2 word3"', 'word2 word3'),
array("word1 author:'word2 word3'", 'word2 word3'),
array('author:word1 author:word2', 'word1'),
array('author: word1 word2', ''),
array('author:123', '123'),
array('author:"word1 word2" word3"', 'word1 word2'),
array("author:'word1 word2' word3'", 'word1 word2'),
array('author:"word1 word2\' word3"', "word1 word2' word3"),
array("author:'word1 word2\" word3'", 'word1 word2" word3'),
);
}
/**
* @dataProvider provideInurlSearch
* @param string $search
* @param string $expected_value
*/
public function testParseSearch_whenInurlKeyword_returnArrayWithInurlValue($search, $expected_value) {
FreshRSS_Context::$search = $search;
$parsed_search = $this->context->parseSearch();
$this->assertEquals($expected_value, $parsed_search['inurl']);
}
/**
* @return array
*/
public function provideInurlSearch() {
return array(
array('inurl:word1', 'word1'),
array('inurl: word1', ''),
array('inurl:123', '123'),
array('inurl:word1 word2', 'word1'),
array('inurl:"word1 word2"', '"word1'),
);
}
/**
* @dataProvider provideDateSearch
* @param string $search
* @param string $expected_min_value
* @param string $expected_max_value
*/
public function testParseSearch_whenDateKeyword_returnArrayWithDateValues($search, $expected_min_value, $expected_max_value) {
FreshRSS_Context::$search = $search;
$parsed_search = $this->context->parseSearch();
$this->assertEquals($expected_min_value, $parsed_search['min_date']);
$this->assertEquals($expected_max_value, $parsed_search['max_date']);
}
/**
* @return array
*/
public function provideDateSearch() {
return array(
array('date:2007-03-01T13:00:00Z/2008-05-11T15:30:00Z', '1172754000', '1210519800'),
array('date:2007-03-01T13:00:00Z/P1Y2M10DT2H30M', '1172754000', '1210516199'),
array('date:P1Y2M10DT2H30M/2008-05-11T15:30:00Z', '1172757601', '1210519800'),
array('date:2007-03-01/2008-05-11', '1172725200', '1210564799'),
array('date:2007-03-01/', '1172725200', ''),
array('date:/2008-05-11', '', '1210564799'),
);
}
/**
* @dataProvider providePubdateSearch
* @param string $search
* @param string $expected_min_value
* @param string $expected_max_value
*/
public function testParseSearch_whenPubdateKeyword_returnArrayWithPubdateValues($search, $expected_min_value, $expected_max_value) {
FreshRSS_Context::$search = $search;
$parsed_search = $this->context->parseSearch();
$this->assertEquals($expected_min_value, $parsed_search['min_pubdate']);
$this->assertEquals($expected_max_value, $parsed_search['max_pubdate']);
}
/**
* @return array
*/
public function providePubdateSearch() {
return array(
array('pubdate:2007-03-01T13:00:00Z/2008-05-11T15:30:00Z', '1172754000', '1210519800'),
array('pubdate:2007-03-01T13:00:00Z/P1Y2M10DT2H30M', '1172754000', '1210516199'),
array('pubdate:P1Y2M10DT2H30M/2008-05-11T15:30:00Z', '1172757601', '1210519800'),
array('pubdate:2007-03-01/2008-05-11', '1172725200', '1210564799'),
array('pubdate:2007-03-01/', '1172725200', ''),
array('pubdate:/2008-05-11', '', '1210564799'),
);
}
}
|