Code Duplication    Length = 31-36 lines in 2 locations

tests/QueryGeneratorTest.php 2 locations

@@ 112-142 (lines=31) @@
109
	}
110
111
112
	public function testMultiMatchWithText() {
113
		$qg = new QueryGenerator();
114
		$qg->setQueryText('New Zealand');
115
		$fields = array('Title' => 1, 'Description' => 1);
116
		$qg->setFields($fields);
117
		$qg->setSelectedFilters(null);
118
		$qg->setClasses('FlickrPhotoTO');
119
120
		//As the query is not empty it should not matter whether or not the show results for empty
121
		//query flag is set or not - test with true and false
122
123
		$qg->setShowResultsForEmptyQuery(false);
124
		$qs = array('multi_match' => array(
125
			'fields' => array('Title','Title.*','Description','Description.*'),
126
			'type' => 'most_fields',
127
			'query' => 'New Zealand',
128
			'lenient' => true
129
			)
130
		);
131
		$expected = array(
132
			'query' => $qs,
133
			'size' => 10,
134
			'from' => 0,
135
			'suggest' => $this->getDefaultSuggest('New Zealand')
136
		);
137
138
		$this->assertEquals($expected, $qg->generateElasticaQuery()->toArray());
139
140
		$qg->setShowResultsForEmptyQuery(true);
141
		$this->assertEquals($expected, $qg->generateElasticaQuery()->toArray());
142
	}
143
144
145
@@ 146-181 (lines=36) @@
143
144
145
146
	public function testMultiMatchWithNoText() {
147
		$qg = new QueryGenerator();
148
		$qg->setQueryText('');
149
		$fields = array('Title' => 1, 'Description' => 1);
150
		$qg->setFields($fields);
151
		$qg->setSelectedFilters(null);
152
		$qg->setClasses('FlickrPhotoTO');
153
154
		//As the query is not empty it should not matter whether or not the show results for empty
155
		//query flag is set or not - test with true and false
156
157
		//Case of empty query, do not show results
158
		$qg->setShowResultsForEmptyQuery(false);
159
		$qs = array(
160
			'multi_match' => array(
161
				'fields' => array('Title','Title.*','Description','Description.*'),
162
				'type' => 'most_fields',
163
				'query' => '',
164
				'lenient' => true
165
			)
166
		);
167
		$expected = array(
168
			'query' => $qs,
169
			'size' => 10,
170
			'from' => 0,
171
			'suggest' => $this->getDefaultSuggest('')
172
		);
173
174
		$this->assertEquals($expected, $qg->generateElasticaQuery()->toArray());
175
176
177
		// Now the case of empty query and show results
178
		$qg->setShowResultsForEmptyQuery(true);
179
		unset($expected['query']);
180
		$this->assertEquals($expected, $qg->generateElasticaQuery()->toArray());
181
	}
182
183
184
	// ---- tests with aggregations ----