Code Duplication    Length = 28-29 lines in 2 locations

tests/TranslatableUnitTest.php 1 location

@@ 34-62 (lines=29) @@
31
	}
32
33
34
	public function testHighlightPassingFields() {
35
		$es = new ElasticSearcher();
36
		$es->setClasses('FlickrPhotoTO');
37
38
		$es->setHighlightedFields(array('Title', 'Title.standard', 'Description'));
39
40
		$fields = array('Title' => 1, 'Description' => 1);
41
		$query = 'New Zealand';
42
		$paginated = $es->search($query, $fields);
43
		$ctr = 0;
44
45
		foreach ($paginated->getList()->toArray() as $result) {
46
			$ctr++;
47
48
			foreach ($result->SearchHighlightsByField->Description->getIterator() as $highlight) {
49
				$snippet = $highlight->Snippet;
50
				$snippet = strtolower($snippet);
51
				$wordFound = false;
52
				$lcquery = explode(' ', strtolower($query));
53
				foreach ($lcquery as $part) {
54
					$bracketed = '<strong class="hl">'.$part.'</strong>';
55
					if (strpos($snippet, $bracketed) > 0) {
56
						$wordFound = true;
57
					}
58
				}
59
				$this->assertTrue($wordFound,'Highlight should have been found');
60
			}
61
		}
62
	}
63
64
65
	public function testAutoCompleteGood() {

tests/ElasticSearcherUnitTest.php 1 location

@@ 233-260 (lines=28) @@
230
	}
231
232
233
	public function testHighlightPassingFields() {
234
		$es = new ElasticSearcher();
235
		$es->setClasses('FlickrPhotoTO');
236
		$es->setHighlightedFields(array('Title', 'Title.standard', 'Description'));
237
238
		$fields = array('Title' => 1, 'Description' => 1);
239
		$query = 'New Zealand';
240
		$paginated = $es->search($query, $fields);
241
		$ctr = 0;
242
243
		foreach ($paginated->getList()->toArray() as $result) {
244
			$ctr++;
245
246
			foreach ($result->SearchHighlightsByField->Description->getIterator() as $highlight) {
247
				$snippet = $highlight->Snippet;
248
				$snippet = strtolower($snippet);
249
				$wordFound = false;
250
				$lcquery = explode(' ', strtolower($query));
251
				foreach ($lcquery as $part) {
252
					$bracketed = '<strong class="hl">'.$part.'</strong>';
253
					if (strpos($snippet, $bracketed) > 0) {
254
						$wordFound = true;
255
					}
256
				}
257
				$this->assertTrue($wordFound,'Highlight should have been found');
258
			}
259
		}
260
	}
261
262
263
	public function testAutoCompleteGood() {