@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | /** |
| 5 | 5 | * Alter the query or add to it, perhaps for example adding aggregation |
| 6 | 6 | * @param Elastic\Query &$query query object from Elastica |
| 7 | - * @return [type] [description] |
|
| 7 | + * @return void [description] |
|
| 8 | 8 | */ |
| 9 | 9 | public function augmentQuery(&$query); |
| 10 | 10 | |
@@ -12,6 +12,7 @@ discard block |
||
| 12 | 12 | * Update filters, perhaps remaps them, prior to performing a search. |
| 13 | 13 | * This allows for aggregation values to be updated prior to rendering. |
| 14 | 14 | * @param array &$filters array of key/value pairs for query filtering |
| 15 | + * @return void |
|
| 15 | 16 | */ |
| 16 | 17 | public function updateFilters(&$filters); |
| 17 | 18 | |
@@ -19,7 +20,7 @@ discard block |
||
| 19 | 20 | * Manipulate the array of aggregations post search butprior to rendering |
| 20 | 21 | * them in a template. |
| 21 | 22 | * @param [type] &$aggs [description] |
| 22 | - * @return [type] [description] |
|
| 23 | + * @return void [description] |
|
| 23 | 24 | */ |
| 24 | 25 | public function updateAggregation(&$aggs); |
| 25 | 26 | |
@@ -250,6 +250,9 @@ |
||
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | |
| 253 | + /** |
|
| 254 | + * @return integer |
|
| 255 | + */ |
|
| 253 | 256 | public function getTotalItems() { |
| 254 | 257 | $this->getResults(); |
| 255 | 258 | return $this->TotalItems; |
@@ -1036,6 +1036,7 @@ |
||
| 1036 | 1036 | /** |
| 1037 | 1037 | * Test searching |
| 1038 | 1038 | * http://stackoverflow.com/questions/28305250/elasticsearch-customize-score-for-synonyms-stemming |
| 1039 | + * @param string $queryText |
|
| 1039 | 1040 | */ |
| 1040 | 1041 | private function search($queryText,$fields = array('Title' => 1, 'Description' => 1), |
| 1041 | 1042 | $filters = array()) { |
@@ -34,9 +34,9 @@ discard block |
||
| 34 | 34 | $this->aggregationByName($aggregations); |
| 35 | 35 | |
| 36 | 36 | error_log('AGGS'); |
| 37 | - foreach ($aggregations as $agg) { |
|
| 37 | + foreach($aggregations as $agg) { |
|
| 38 | 38 | error_log($agg->Name); |
| 39 | - foreach ($agg->Buckets as $bucket) { |
|
| 39 | + foreach($agg->Buckets as $bucket) { |
|
| 40 | 40 | error_log("\t$bucket->Key -> $bucket->DocumentCount"); |
| 41 | 41 | } |
| 42 | 42 | } |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | $resultList = $this->search(''); |
| 433 | 433 | |
| 434 | 434 | //assert there are actually some results |
| 435 | - $this->assertGreaterThan(0,$resultList->getTotalItems()); |
|
| 435 | + $this->assertGreaterThan(0, $resultList->getTotalItems()); |
|
| 436 | 436 | $aggregations = $resultList->getAggregations()->toArray(); |
| 437 | 437 | $this->aggregationByName($aggregations); |
| 438 | 438 | |
@@ -452,49 +452,49 @@ discard block |
||
| 452 | 452 | //Asserting aggregate of ISO, 64 has count 5 |
| 453 | 453 | $this->assertEquals("64", $buckets[0]->Key); |
| 454 | 454 | $this->assertEquals(5, $buckets[0]->DocumentCount); |
| 455 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',64)->count(),5); |
|
| 455 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 64)->count(), 5); |
|
| 456 | 456 | $bucketSum += $buckets[0]->DocumentCount; |
| 457 | 457 | |
| 458 | 458 | //Asserting aggregate of ISO, 100 has count 11 |
| 459 | 459 | $this->assertEquals("100", $buckets[1]->Key); |
| 460 | 460 | $this->assertEquals(11, $buckets[1]->DocumentCount); |
| 461 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',100)->count(),11); |
|
| 461 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 100)->count(), 11); |
|
| 462 | 462 | $bucketSum += $buckets[1]->DocumentCount; |
| 463 | 463 | |
| 464 | 464 | //Asserting aggregate of ISO, 200 has count 12 |
| 465 | 465 | $this->assertEquals("200", $buckets[2]->Key); |
| 466 | 466 | $this->assertEquals(12, $buckets[2]->DocumentCount); |
| 467 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',200)->count(),12); |
|
| 467 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 200)->count(), 12); |
|
| 468 | 468 | $bucketSum += $buckets[2]->DocumentCount; |
| 469 | 469 | |
| 470 | 470 | //Asserting aggregate of ISO, 400 has count 13 |
| 471 | 471 | $this->assertEquals("400", $buckets[3]->Key); |
| 472 | 472 | $this->assertEquals(13, $buckets[3]->DocumentCount); |
| 473 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',400)->count(),13); |
|
| 473 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 400)->count(), 13); |
|
| 474 | 474 | $bucketSum += $buckets[3]->DocumentCount; |
| 475 | 475 | |
| 476 | 476 | //Asserting aggregate of ISO, 800 has count 16 |
| 477 | 477 | $this->assertEquals("800", $buckets[4]->Key); |
| 478 | 478 | $this->assertEquals(16, $buckets[4]->DocumentCount); |
| 479 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',800)->count(),16); |
|
| 479 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 800)->count(), 16); |
|
| 480 | 480 | $bucketSum += $buckets[4]->DocumentCount; |
| 481 | 481 | |
| 482 | 482 | //Asserting aggregate of ISO, 1600 has count 13 |
| 483 | 483 | $this->assertEquals("1600", $buckets[5]->Key); |
| 484 | 484 | $this->assertEquals(13, $buckets[5]->DocumentCount); |
| 485 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',1600)->count(),13); |
|
| 485 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 1600)->count(), 13); |
|
| 486 | 486 | $bucketSum += $buckets[5]->DocumentCount; |
| 487 | 487 | |
| 488 | 488 | //Asserting aggregate of ISO, 2000 has count 11 |
| 489 | 489 | $this->assertEquals("2000", $buckets[6]->Key); |
| 490 | 490 | $this->assertEquals(11, $buckets[6]->DocumentCount); |
| 491 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',2000)->count(),11); |
|
| 491 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 2000)->count(), 11); |
|
| 492 | 492 | $bucketSum += $buckets[6]->DocumentCount; |
| 493 | 493 | |
| 494 | 494 | //Asserting aggregate of ISO, 3200 has count 19 |
| 495 | 495 | $this->assertEquals("3200", $buckets[7]->Key); |
| 496 | 496 | $this->assertEquals(19, $buckets[7]->DocumentCount); |
| 497 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',3200)->count(),19); |
|
| 497 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 3200)->count(), 19); |
|
| 498 | 498 | $bucketSum += $buckets[7]->DocumentCount; |
| 499 | 499 | $this->assertEquals(100, $bucketSum); |
| 500 | 500 | |
@@ -507,43 +507,43 @@ discard block |
||
| 507 | 507 | //Asserting aggregate of Focal Length, 24 has count 12 |
| 508 | 508 | $this->assertEquals("24", $buckets[0]->Key); |
| 509 | 509 | $this->assertEquals(12, $buckets[0]->DocumentCount); |
| 510 | - $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',24)->count(),12); |
|
| 510 | + $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm', 24)->count(), 12); |
|
| 511 | 511 | $bucketSum += $buckets[0]->DocumentCount; |
| 512 | 512 | |
| 513 | 513 | //Asserting aggregate of Focal Length, 50 has count 11 |
| 514 | 514 | $this->assertEquals("50", $buckets[1]->Key); |
| 515 | 515 | $this->assertEquals(11, $buckets[1]->DocumentCount); |
| 516 | - $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',50)->count(),11); |
|
| 516 | + $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm', 50)->count(), 11); |
|
| 517 | 517 | $bucketSum += $buckets[1]->DocumentCount; |
| 518 | 518 | |
| 519 | 519 | //Asserting aggregate of Focal Length, 80 has count 11 |
| 520 | 520 | $this->assertEquals("80", $buckets[2]->Key); |
| 521 | 521 | $this->assertEquals(11, $buckets[2]->DocumentCount); |
| 522 | - $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',80)->count(),11); |
|
| 522 | + $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm', 80)->count(), 11); |
|
| 523 | 523 | $bucketSum += $buckets[2]->DocumentCount; |
| 524 | 524 | |
| 525 | 525 | //Asserting aggregate of Focal Length, 90 has count 20 |
| 526 | 526 | $this->assertEquals("90", $buckets[3]->Key); |
| 527 | 527 | $this->assertEquals(20, $buckets[3]->DocumentCount); |
| 528 | - $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',90)->count(),20); |
|
| 528 | + $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm', 90)->count(), 20); |
|
| 529 | 529 | $bucketSum += $buckets[3]->DocumentCount; |
| 530 | 530 | |
| 531 | 531 | //Asserting aggregate of Focal Length, 120 has count 12 |
| 532 | 532 | $this->assertEquals("120", $buckets[4]->Key); |
| 533 | 533 | $this->assertEquals(12, $buckets[4]->DocumentCount); |
| 534 | - $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',120)->count(),12); |
|
| 534 | + $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm', 120)->count(), 12); |
|
| 535 | 535 | $bucketSum += $buckets[4]->DocumentCount; |
| 536 | 536 | |
| 537 | 537 | //Asserting aggregate of Focal Length, 150 has count 17 |
| 538 | 538 | $this->assertEquals("150", $buckets[5]->Key); |
| 539 | 539 | $this->assertEquals(17, $buckets[5]->DocumentCount); |
| 540 | - $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',150)->count(),17); |
|
| 540 | + $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm', 150)->count(), 17); |
|
| 541 | 541 | $bucketSum += $buckets[5]->DocumentCount; |
| 542 | 542 | |
| 543 | 543 | //Asserting aggregate of Focal Length, 200 has count 17 |
| 544 | 544 | $this->assertEquals("200", $buckets[6]->Key); |
| 545 | 545 | $this->assertEquals(17, $buckets[6]->DocumentCount); |
| 546 | - $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',200)->count(),17); |
|
| 546 | + $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm', 200)->count(), 17); |
|
| 547 | 547 | $bucketSum += $buckets[6]->DocumentCount; |
| 548 | 548 | $this->assertEquals(100, $bucketSum); |
| 549 | 549 | |
@@ -830,7 +830,7 @@ discard block |
||
| 830 | 830 | $originalAggregations = $resultList->getAggregations()->toArray(); |
| 831 | 831 | |
| 832 | 832 | $filters = array('ISO' => 3200); |
| 833 | - $resultListFiltered = $this->search('New Zealand', $fields,$filters); |
|
| 833 | + $resultListFiltered = $this->search('New Zealand', $fields, $filters); |
|
| 834 | 834 | $filteredAggregations = $resultListFiltered->getAggregations()->toArray(); |
| 835 | 835 | |
| 836 | 836 | $this->checkDrillingDownHasHappened($filteredAggregations, $originalAggregations); |
@@ -842,8 +842,8 @@ discard block |
||
| 842 | 842 | $resultList = $this->search('New Zealand', $fields, array('ISO' => 400)); |
| 843 | 843 | $originalAggregations = $resultList->getAggregations()->toArray(); |
| 844 | 844 | |
| 845 | - $filters = array('ISO' => 400, 'Aspect' => 'Vertical' ); |
|
| 846 | - $resultListFiltered = $this->search('New Zealand', $fields,$filters); |
|
| 845 | + $filters = array('ISO' => 400, 'Aspect' => 'Vertical'); |
|
| 846 | + $resultListFiltered = $this->search('New Zealand', $fields, $filters); |
|
| 847 | 847 | $filteredAggregations = $resultListFiltered->getAggregations()->toArray(); |
| 848 | 848 | |
| 849 | 849 | $this->checkDrillingDownHasHappened($filteredAggregations, $originalAggregations); |
@@ -858,8 +858,8 @@ discard block |
||
| 858 | 858 | 'Aspect' => 'Vertical')); |
| 859 | 859 | $originalAggregations = $resultList->getAggregations()->toArray(); |
| 860 | 860 | |
| 861 | - $filters = array('ISO' => 400, 'Aspect' => 'Vertical', 'Aperture' => 5 ); |
|
| 862 | - $resultListFiltered = $this->search('New Zealand', $fields,$filters); |
|
| 861 | + $filters = array('ISO' => 400, 'Aspect' => 'Vertical', 'Aperture' => 5); |
|
| 862 | + $resultListFiltered = $this->search('New Zealand', $fields, $filters); |
|
| 863 | 863 | $filteredAggregations = $resultListFiltered->getAggregations()->toArray(); |
| 864 | 864 | |
| 865 | 865 | $this->checkDrillingDownHasHappened($filteredAggregations, $originalAggregations); |
@@ -899,7 +899,7 @@ discard block |
||
| 899 | 899 | private function checkDrillingDownHasHappened($filteredAggregations, $originalAggregations) { |
| 900 | 900 | $aggCtr = 0; |
| 901 | 901 | |
| 902 | - foreach ($filteredAggregations as $filteredAgg) { |
|
| 902 | + foreach($filteredAggregations as $filteredAgg) { |
|
| 903 | 903 | $origAgg = $originalAggregations[$aggCtr]; |
| 904 | 904 | $bucketCtr = 0; |
| 905 | 905 | $origBuckets = $origAgg->Buckets->toArray(); |
@@ -908,17 +908,17 @@ discard block |
||
| 908 | 908 | $origCounts = array(); |
| 909 | 909 | $filteredCounts = array(); |
| 910 | 910 | |
| 911 | - foreach ($origBuckets as $bucket) { |
|
| 911 | + foreach($origBuckets as $bucket) { |
|
| 912 | 912 | $origCounts[$bucket->Key] = $bucket->DocumentCount; |
| 913 | 913 | } |
| 914 | 914 | |
| 915 | - foreach ($filteredBuckets as $bucket) { |
|
| 915 | + foreach($filteredBuckets as $bucket) { |
|
| 916 | 916 | $filteredCounts[$bucket->Key] = $bucket->DocumentCount; |
| 917 | 917 | } |
| 918 | 918 | |
| 919 | 919 | $akf = array_keys($filteredCounts); |
| 920 | 920 | |
| 921 | - foreach ($akf as $aggregateKey) { |
|
| 921 | + foreach($akf as $aggregateKey) { |
|
| 922 | 922 | $this->assertGreaterThanOrEqual( |
| 923 | 923 | $filteredCounts[$aggregateKey], $origCounts[$aggregateKey] |
| 924 | 924 | ); |
@@ -954,8 +954,8 @@ discard block |
||
| 954 | 954 | $es->setQueryResultManipulator('FlickrPhotoTOElasticaSearchHelper'); |
| 955 | 955 | |
| 956 | 956 | //Add filters |
| 957 | - foreach ($filters as $key => $value) { |
|
| 958 | - $es->addFilter($key,$value); |
|
| 957 | + foreach($filters as $key => $value) { |
|
| 958 | + $es->addFilter($key, $value); |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | $es->showResultsForEmptySearch(); |
@@ -974,7 +974,7 @@ discard block |
||
| 974 | 974 | * Test searching |
| 975 | 975 | * http://stackoverflow.com/questions/28305250/elasticsearch-customize-score-for-synonyms-stemming |
| 976 | 976 | */ |
| 977 | - private function search($queryText,$fields = array('Title' => 1, 'Description' => 1), |
|
| 977 | + private function search($queryText, $fields = array('Title' => 1, 'Description' => 1), |
|
| 978 | 978 | $filters = array()) { |
| 979 | 979 | $es = new ElasticSearcher(); |
| 980 | 980 | $es->setStart(0); |
@@ -983,9 +983,9 @@ discard block |
||
| 983 | 983 | $es->setQueryResultManipulator('FlickrPhotoTOElasticaSearchHelper'); |
| 984 | 984 | |
| 985 | 985 | //Add filters |
| 986 | - foreach ($filters as $key => $value) { |
|
| 986 | + foreach($filters as $key => $value) { |
|
| 987 | 987 | error_log("ADDING FILTER RESULT $key, $value"); |
| 988 | - $es->addFilter($key,$value); |
|
| 988 | + $es->addFilter($key, $value); |
|
| 989 | 989 | } |
| 990 | 990 | |
| 991 | 991 | $es->showResultsForEmptySearch(); |
@@ -1003,7 +1003,7 @@ discard block |
||
| 1003 | 1003 | */ |
| 1004 | 1004 | private function aggregationByName(&$aggregations) { |
| 1005 | 1005 | $ctr = 0; |
| 1006 | - foreach ($aggregations as $agg) { |
|
| 1006 | + foreach($aggregations as $agg) { |
|
| 1007 | 1007 | $aggregations[$agg->Name] = $agg; |
| 1008 | 1008 | unset($aggregations[$ctr]); |
| 1009 | 1009 | $ctr++; |
@@ -153,6 +153,9 @@ |
||
| 153 | 153 | |
| 154 | 154 | /** |
| 155 | 155 | * Simulate a call to Elastica to get suggestions for a given phrase |
| 156 | + * @param string $phrase |
|
| 157 | + * @param string $suggestion |
|
| 158 | + * @param string $highlightedSuggestion |
|
| 156 | 159 | * @return [type] [description] |
| 157 | 160 | */ |
| 158 | 161 | private function getSuggestionArray($phrase, $suggestion, $highlightedSuggestion) { |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | * Note: characters are stripped from the content; make sure that your assertions take this into account. |
| 103 | 103 | * |
| 104 | 104 | * @param string $selector A basic CSS selector, e.g. 'li.jobs h3' |
| 105 | - * @param array|string $expectedMatches The content of at least one of the matched tags |
|
| 105 | + * @param integer $index |
|
| 106 | 106 | * @throws PHPUnit_Framework_AssertionFailedError |
| 107 | 107 | * @return boolean |
| 108 | 108 | */ |
@@ -133,6 +133,12 @@ discard block |
||
| 133 | 133 | /* |
| 134 | 134 | Check all the nodes matching the selector for attribute name = expected value |
| 135 | 135 | */ |
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @param string $selector |
|
| 139 | + * @param string $attributeName |
|
| 140 | + * @param string $expectedValue |
|
| 141 | + */ |
|
| 136 | 142 | public function assertAttributeHasExactValue($selector, $attributeName, $expectedValue) { |
| 137 | 143 | $items = $this->cssParser()->getBySelector($selector); |
| 138 | 144 | foreach ($items as $item) { |
@@ -141,6 +147,9 @@ discard block |
||
| 141 | 147 | } |
| 142 | 148 | |
| 143 | 149 | |
| 150 | + /** |
|
| 151 | + * @param string $selector |
|
| 152 | + */ |
|
| 144 | 153 | public function assertAttributesHaveExactValues($selector, $expectedValues) { |
| 145 | 154 | $attributeNames = array_keys($expectedValues); |
| 146 | 155 | $items = $this->cssParser()->getBySelector($selector); |
@@ -154,6 +163,10 @@ discard block |
||
| 154 | 163 | } |
| 155 | 164 | |
| 156 | 165 | |
| 166 | + /** |
|
| 167 | + * @param string $selector |
|
| 168 | + * @param integer $expectedAmount |
|
| 169 | + */ |
|
| 157 | 170 | public function assertNumberOfNodes($selector, $expectedAmount) { |
| 158 | 171 | $items = $this->cssParser()->getBySelector($selector); |
| 159 | 172 | foreach ($items as $item) { |
@@ -9,8 +9,8 @@ discard block |
||
| 9 | 9 | public static $ignoreFixtureFileFor = array(); |
| 10 | 10 | |
| 11 | 11 | protected $extraDataObjects = array( |
| 12 | - 'SearchableTestPage','FlickrPhotoTO','FlickrAuthorTO','FlickrSetTO','FlickrTagTO', |
|
| 13 | - 'SearchableTestFatherPage','SearchableTestGrandFatherPage' |
|
| 12 | + 'SearchableTestPage', 'FlickrPhotoTO', 'FlickrAuthorTO', 'FlickrSetTO', 'FlickrTagTO', |
|
| 13 | + 'SearchableTestFatherPage', 'SearchableTestGrandFatherPage' |
|
| 14 | 14 | ); |
| 15 | 15 | |
| 16 | 16 | |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | public function setUp() { |
| 29 | 29 | |
| 30 | - error_log("*************** TEST: ".$this->getName()); |
|
| 30 | + error_log("*************** TEST: " . $this->getName()); |
|
| 31 | 31 | |
| 32 | 32 | $cache = SS_Cache::factory('elasticsearch'); |
| 33 | 33 | $cache->clean(Zend_Cache::CLEANING_MODE_ALL); |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | // this needs to be called in order to create the list of searchable |
| 37 | 37 | // classes and fields that are available. Simulates part of a build |
| 38 | - $classes = array('SearchableTestPage','SiteTree','Page','FlickrPhotoTO','FlickrSetTO', |
|
| 38 | + $classes = array('SearchableTestPage', 'SiteTree', 'Page', 'FlickrPhotoTO', 'FlickrSetTO', |
|
| 39 | 39 | 'FlickrTagTO', 'FlickrAuthorTO'); |
| 40 | 40 | $this->requireDefaultRecordsFrom = $classes; |
| 41 | 41 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $this->service->setTestMode(true); |
| 55 | 55 | |
| 56 | 56 | // A previous test may have deleted the index and then failed, so check for this |
| 57 | - if (!$this->service->getIndex()->exists()) { |
|
| 57 | + if(!$this->service->getIndex()->exists()) { |
|
| 58 | 58 | $this->service->getIndex()->create(); |
| 59 | 59 | } |
| 60 | 60 | $this->service->reset(); |
@@ -65,9 +65,9 @@ discard block |
||
| 65 | 65 | // load fixtures |
| 66 | 66 | $orig_fixture_file = static::$fixture_file; |
| 67 | 67 | |
| 68 | - foreach (static::$ignoreFixtureFileFor as $testPattern) { |
|
| 69 | - $pattern = '/'.$testPattern.'/'; |
|
| 70 | - if (preg_match($pattern, $this->getName())) { |
|
| 68 | + foreach(static::$ignoreFixtureFileFor as $testPattern) { |
|
| 69 | + $pattern = '/' . $testPattern . '/'; |
|
| 70 | + if(preg_match($pattern, $this->getName())) { |
|
| 71 | 71 | static::$fixture_file = null; |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | // this has to be executed otherwise nesting exceptions occur |
| 80 | 80 | parent::setUp(); |
| 81 | 81 | |
| 82 | - if ($elasticaException) { |
|
| 82 | + if($elasticaException) { |
|
| 83 | 83 | $this->fail('T1 Exception with Elasticsearch'); |
| 84 | 84 | } |
| 85 | 85 | |
@@ -101,18 +101,18 @@ discard block |
||
| 101 | 101 | $elasticaException = true; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - if ($elasticaException) { |
|
| 104 | + if($elasticaException) { |
|
| 105 | 105 | $this->fail('T2 Exception with Elasticsearch'); |
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | |
| 110 | 110 | private function publishSiteTree() { |
| 111 | - foreach (SiteTree::get()->getIterator() as $page) { |
|
| 111 | + foreach(SiteTree::get()->getIterator() as $page) { |
|
| 112 | 112 | // temporarily disable Elasticsearch indexing, it will be done in a batch |
| 113 | 113 | $page->IndexingOff = true; |
| 114 | 114 | |
| 115 | - $page->publish('Stage','Live'); |
|
| 115 | + $page->publish('Stage', 'Live'); |
|
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | $items = $this->cssParser()->getBySelector($selector); |
| 134 | 134 | |
| 135 | 135 | $ctr = 0; |
| 136 | - foreach ($items as $item) { |
|
| 136 | + foreach($items as $item) { |
|
| 137 | 137 | $text = strip_tags($item); |
| 138 | 138 | $escaped = str_replace("'", "\'", $text); |
| 139 | 139 | $ctr++; |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | */ |
| 156 | 156 | public function assertAttributeHasExactValue($selector, $attributeName, $expectedValue) { |
| 157 | 157 | $items = $this->cssParser()->getBySelector($selector); |
| 158 | - foreach ($items as $item) { |
|
| 158 | + foreach($items as $item) { |
|
| 159 | 159 | $this->assertEquals($expectedValue, $item['value']); |
| 160 | 160 | } |
| 161 | 161 | } |
@@ -164,9 +164,9 @@ discard block |
||
| 164 | 164 | public function assertAttributesHaveExactValues($selector, $expectedValues) { |
| 165 | 165 | $attributeNames = array_keys($expectedValues); |
| 166 | 166 | $items = $this->cssParser()->getBySelector($selector); |
| 167 | - foreach ($items as $item) { |
|
| 167 | + foreach($items as $item) { |
|
| 168 | 168 | $actualValues = array(); |
| 169 | - foreach ($attributeNames as $attributeName) { |
|
| 169 | + foreach($attributeNames as $attributeName) { |
|
| 170 | 170 | $actualValues[$attributeName] = (string)$item[$attributeName]; |
| 171 | 171 | } |
| 172 | 172 | $this->assertEquals($expectedValues, $actualValues); |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | |
| 177 | 177 | public function assertNumberOfNodes($selector, $expectedAmount) { |
| 178 | 178 | $items = $this->cssParser()->getBySelector($selector); |
| 179 | - foreach ($items as $item) { |
|
| 179 | + foreach($items as $item) { |
|
| 180 | 180 | $text = strip_tags($item); |
| 181 | 181 | } |
| 182 | 182 | |
@@ -189,9 +189,9 @@ discard block |
||
| 189 | 189 | public function collateSearchResults() { |
| 190 | 190 | $items = $this->cssParser()->getBySelector('div.searchResults .searchResult'); |
| 191 | 191 | $result = array(); |
| 192 | - foreach ($items as $item) { |
|
| 192 | + foreach($items as $item) { |
|
| 193 | 193 | $attr = $item->attributes()->id; |
| 194 | - array_push($result, $attr.""); |
|
| 194 | + array_push($result, $attr . ""); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | return $result; |
@@ -106,6 +106,10 @@ |
||
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | |
| 109 | + /** |
|
| 110 | + * @param string $fieldName |
|
| 111 | + * @param string $message |
|
| 112 | + */ |
|
| 109 | 113 | private function checkForError($fieldName, $badValue, $message) { |
| 110 | 114 | $this->ElasticSearchPage->$fieldName = $badValue; |
| 111 | 115 | |
@@ -131,8 +131,8 @@ |
||
| 131 | 131 | $errors = Session::get("FormInfo.{$form->FormName()}.errors"); |
| 132 | 132 | $found = false; |
| 133 | 133 | |
| 134 | - foreach ($errors as $error) { |
|
| 135 | - if ($error['message'] == $message && $error['fieldName'] == $fieldName) { |
|
| 134 | + foreach($errors as $error) { |
|
| 135 | + if($error['message'] == $message && $error['fieldName'] == $fieldName) { |
|
| 136 | 136 | $found = true; |
| 137 | 137 | break; |
| 138 | 138 | } |
@@ -132,6 +132,10 @@ discard block |
||
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | |
| 135 | + /** |
|
| 136 | + * @param integer $depth |
|
| 137 | + * @param string $parentKey |
|
| 138 | + */ |
|
| 135 | 139 | private function recurseArrayAssertion($toAssert, $depth, $parentKey) { |
| 136 | 140 | $prefix = str_repeat("\t",$depth); |
| 137 | 141 | echo "\t{$prefix}'$parentKey' => array(\n"; |
@@ -160,6 +164,10 @@ discard block |
||
| 160 | 164 | /* |
| 161 | 165 | Helper methods for testing CMS fields |
| 162 | 166 | */ |
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @param string $tabName |
|
| 170 | + */ |
|
| 163 | 171 | public function checkTabExists($fields, $tabName) { |
| 164 | 172 | echo "Searching for tab $tabName\n"; |
| 165 | 173 | $tab = $fields->findOrMakeTab("Root.{$tabName}"); |
@@ -184,6 +192,9 @@ discard block |
||
| 184 | 192 | } |
| 185 | 193 | |
| 186 | 194 | |
| 195 | + /** |
|
| 196 | + * @param string $fieldName |
|
| 197 | + */ |
|
| 187 | 198 | public function checkFieldExists($tab,$fieldName) { |
| 188 | 199 | $fields = $tab->Fields(); |
| 189 | 200 | echo "TAB:{$tab->Name}\n"; |
@@ -208,11 +208,11 @@ |
||
| 208 | 208 | */ |
| 209 | 209 | public function invokeMethod(&$object, $methodName, array $parameters = array()) |
| 210 | 210 | { |
| 211 | - $reflection = new \ReflectionClass(get_class($object)); |
|
| 212 | - $method = $reflection->getMethod($methodName); |
|
| 213 | - $method->setAccessible(true); |
|
| 211 | + $reflection = new \ReflectionClass(get_class($object)); |
|
| 212 | + $method = $reflection->getMethod($methodName); |
|
| 213 | + $method->setAccessible(true); |
|
| 214 | 214 | |
| 215 | - return $method->invokeArgs($object, $parameters); |
|
| 215 | + return $method->invokeArgs($object, $parameters); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | |
@@ -8,8 +8,8 @@ discard block |
||
| 8 | 8 | public static $ignoreFixtureFileFor = array(); |
| 9 | 9 | |
| 10 | 10 | protected $extraDataObjects = array( |
| 11 | - 'SearchableTestPage','FlickrPhotoTO','FlickrAuthorTO','FlickrSetTO','FlickrTagTO', |
|
| 12 | - 'SearchableTestFatherPage','SearchableTestGrandFatherPage','AutoCompleteOption' |
|
| 11 | + 'SearchableTestPage', 'FlickrPhotoTO', 'FlickrAuthorTO', 'FlickrSetTO', 'FlickrTagTO', |
|
| 12 | + 'SearchableTestFatherPage', 'SearchableTestGrandFatherPage', 'AutoCompleteOption' |
|
| 13 | 13 | ); |
| 14 | 14 | |
| 15 | 15 | |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | // this needs to be called in order to create the list of searchable |
| 44 | 44 | // classes and fields that are available. Simulates part of a build |
| 45 | - $classes = array('SearchableTestPage','SiteTree','Page','FlickrPhotoTO','FlickrSetTO', |
|
| 45 | + $classes = array('SearchableTestPage', 'SiteTree', 'Page', 'FlickrPhotoTO', 'FlickrSetTO', |
|
| 46 | 46 | 'FlickrTagTO', 'FlickrAuthorTO'); |
| 47 | 47 | $this->requireDefaultRecordsFrom = $classes; |
| 48 | 48 | |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | try { |
| 60 | 60 | // A previous test may have deleted the index and then failed, so check for this |
| 61 | - if (!$this->service->getIndex()->exists()) { |
|
| 61 | + if(!$this->service->getIndex()->exists()) { |
|
| 62 | 62 | error_log('++++ EL BASE SET UP T4a'); |
| 63 | 63 | |
| 64 | 64 | $this->service->getIndex()->create(); |
@@ -73,16 +73,16 @@ discard block |
||
| 73 | 73 | $orig_fixture_file = static::$fixture_file; |
| 74 | 74 | error_log('++++ EL BASE SET UP T5'); |
| 75 | 75 | |
| 76 | - foreach (static::$ignoreFixtureFileFor as $testPattern) { |
|
| 77 | - $pattern = '/'.$testPattern.'/'; |
|
| 78 | - if (preg_match($pattern, $this->getName())) { |
|
| 76 | + foreach(static::$ignoreFixtureFileFor as $testPattern) { |
|
| 77 | + $pattern = '/' . $testPattern . '/'; |
|
| 78 | + if(preg_match($pattern, $this->getName())) { |
|
| 79 | 79 | static::$fixture_file = null; |
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | error_log('++++ EL BASE SET UP T6'); |
| 84 | 84 | } catch (Exception $e) { |
| 85 | - error_log("**** EXCEPTION T1 ".$e->getMessage()); |
|
| 85 | + error_log("**** EXCEPTION T1 " . $e->getMessage()); |
|
| 86 | 86 | $elasticException = true; |
| 87 | 87 | } |
| 88 | 88 | error_log('++++ EL BASE SET UP T7'); |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | // this needs to run otherwise nested injector errors show up |
| 92 | 92 | parent::setUp(); |
| 93 | 93 | |
| 94 | - if ($elasticException) { |
|
| 94 | + if($elasticException) { |
|
| 95 | 95 | $this->fail('T1 An error has occurred trying to contact Elasticsearch server'); |
| 96 | 96 | } |
| 97 | 97 | |
@@ -107,11 +107,11 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | $task->run(null); |
| 109 | 109 | } catch (Exception $e) { |
| 110 | - error_log("**** EXCEPTION T2 ".$e->getMessage()); |
|
| 110 | + error_log("**** EXCEPTION T2 " . $e->getMessage()); |
|
| 111 | 111 | $elasticException = true; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - if ($elasticException) { |
|
| 114 | + if($elasticException) { |
|
| 115 | 115 | $this->fail('T2 An error has occurred trying to contact Elasticsearch server'); |
| 116 | 116 | } |
| 117 | 117 | |
@@ -126,55 +126,55 @@ discard block |
||
| 126 | 126 | |
| 127 | 127 | |
| 128 | 128 | private function publishSiteTree() { |
| 129 | - foreach (SiteTree::get()->getIterator() as $page) { |
|
| 129 | + foreach(SiteTree::get()->getIterator() as $page) { |
|
| 130 | 130 | // temporarily disable Elasticsearch indexing, it will be done in a batch |
| 131 | 131 | $page->IndexingOff = true; |
| 132 | - $page->publish('Stage','Live'); |
|
| 132 | + $page->publish('Stage', 'Live'); |
|
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | |
| 137 | 137 | public function generateAssertionsFromArray($toAssert) { |
| 138 | - echo '$expected = array('."\n"; |
|
| 139 | - foreach ($toAssert as $key => $value) { |
|
| 138 | + echo '$expected = array(' . "\n"; |
|
| 139 | + foreach($toAssert as $key => $value) { |
|
| 140 | 140 | $escValue = str_replace("'", '\\\'', $value); |
| 141 | 141 | echo "'$key' => '$escValue',\n"; |
| 142 | 142 | } |
| 143 | 143 | echo ");\n"; |
| 144 | - echo '$this->assertEquals($expected, $somevar);'."\n"; |
|
| 144 | + echo '$this->assertEquals($expected, $somevar);' . "\n"; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | |
| 148 | 148 | public function generateAssertionsFromArray1D($toAssert) { |
| 149 | - echo '$expected = array('."\n"; |
|
| 150 | - foreach ($toAssert as $key => $value) { |
|
| 149 | + echo '$expected = array(' . "\n"; |
|
| 150 | + foreach($toAssert as $key => $value) { |
|
| 151 | 151 | $escValue = str_replace("'", '\\\'', $value); |
| 152 | 152 | echo "'$escValue',"; |
| 153 | 153 | } |
| 154 | 154 | echo ");\n"; |
| 155 | - echo '$this->assertEquals($expected, $somevar);'."\n"; |
|
| 155 | + echo '$this->assertEquals($expected, $somevar);' . "\n"; |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | |
| 159 | 159 | public function generateAssertionsFromArrayRecurse($toAssert) { |
| 160 | 160 | echo '$expected = '; |
| 161 | - $this->recurseArrayAssertion($toAssert,1, 'FIXME'); |
|
| 162 | - echo '$this->assertEquals($expected, $somevar);'."\n"; |
|
| 161 | + $this->recurseArrayAssertion($toAssert, 1, 'FIXME'); |
|
| 162 | + echo '$this->assertEquals($expected, $somevar);' . "\n"; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | |
| 166 | 166 | private function recurseArrayAssertion($toAssert, $depth, $parentKey) { |
| 167 | - $prefix = str_repeat("\t",$depth); |
|
| 167 | + $prefix = str_repeat("\t", $depth); |
|
| 168 | 168 | echo "\t{$prefix}'$parentKey' => array(\n"; |
| 169 | 169 | $ctr = 0; |
| 170 | 170 | $len = sizeof(array_keys($toAssert)); |
| 171 | - foreach ($toAssert as $key => $value) { |
|
| 172 | - if (is_array($value)) { |
|
| 173 | - $this->recurseArrayAssertion($value, $depth+1, $key); |
|
| 171 | + foreach($toAssert as $key => $value) { |
|
| 172 | + if(is_array($value)) { |
|
| 173 | + $this->recurseArrayAssertion($value, $depth + 1, $key); |
|
| 174 | 174 | } else { |
| 175 | 175 | $escValue = str_replace("'", '\\\'', $value); |
| 176 | 176 | $comma = ','; |
| 177 | - if ($ctr == $len-1) { |
|
| 177 | + if($ctr == $len - 1) { |
|
| 178 | 178 | $comma = ''; |
| 179 | 179 | } |
| 180 | 180 | echo "\t\t$prefix'$key' => '$escValue'$comma\n"; |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | $size = sizeof($splits); |
| 199 | 199 | $nameToCheck = end($splits); |
| 200 | 200 | $this->assertEquals($actualTabName, $nameToCheck); |
| 201 | - if ($size == 1) { |
|
| 201 | + if($size == 1) { |
|
| 202 | 202 | $this->assertEquals("Root_${tabName}", $tab->id()); |
| 203 | 203 | } else { |
| 204 | 204 | $expected = "Root_{$splits[0]}_set_{$splits[1]}"; |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | |
| 212 | - public function checkFieldExists($tab,$fieldName) { |
|
| 212 | + public function checkFieldExists($tab, $fieldName) { |
|
| 213 | 213 | $fields = $tab->Fields(); |
| 214 | 214 | $field = $tab->fieldByName($fieldName); |
| 215 | 215 | $this->assertTrue($field != null); |
@@ -243,16 +243,16 @@ discard block |
||
| 243 | 243 | |
| 244 | 244 | $numberDocsInIndex = -1; // flag value for not yet indexed |
| 245 | 245 | error_log('CHECKING NUMBER OF INDEXED DOCUMENTS, SHOULD BE ' . $expectedAmount); |
| 246 | - error_log(print_r($status,1)); |
|
| 246 | + error_log(print_r($status, 1)); |
|
| 247 | 247 | |
| 248 | - if (isset($status['indices']['elastica_ss_module_test_en_us']['docs'])) { |
|
| 248 | + if(isset($status['indices']['elastica_ss_module_test_en_us']['docs'])) { |
|
| 249 | 249 | $numberDocsInIndex = $status['indices']['elastica_ss_module_test_en_us']['docs']['num_docs']; |
| 250 | - error_log('DOCUMENTS FOUND:'.$numberDocsInIndex); |
|
| 250 | + error_log('DOCUMENTS FOUND:' . $numberDocsInIndex); |
|
| 251 | 251 | } else { |
| 252 | 252 | $numberDocsInIndex = 0; |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - $this->assertEquals($expectedAmount,$numberDocsInIndex); |
|
| 255 | + $this->assertEquals($expectedAmount, $numberDocsInIndex); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /* |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | $status = $index->getStatus()->getData(); |
| 264 | 264 | |
| 265 | 265 | $numberDocsInIndex = -1; // flag value for not yet indexed |
| 266 | - if (isset($status['indices']['elastica_ss_module_test_en_us']['docs'])) { |
|
| 266 | + if(isset($status['indices']['elastica_ss_module_test_en_us']['docs'])) { |
|
| 267 | 267 | $numberDocsInIndex = $status['indices']['elastica_ss_module_test_en_us']['docs']['num_docs']; |
| 268 | 268 | } |
| 269 | 269 | |
@@ -479,6 +479,9 @@ |
||
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | |
| 482 | + /** |
|
| 483 | + * @param string $query |
|
| 484 | + */ |
|
| 482 | 485 | private function getResultsFor($query, $pageLength = 10, $fields = array('Title' => 1, 'Description' => 1)) { |
| 483 | 486 | $es = new ElasticSearcher(); |
| 484 | 487 | $es->setStart(0); |
@@ -140,7 +140,7 @@ |
||
| 140 | 140 | |
| 141 | 141 | public function testEach() { |
| 142 | 142 | $callback = function($fp) { |
| 143 | - $this->assertTrue(true, 'Callback reached'); |
|
| 143 | + $this->assertTrue(true, 'Callback reached'); |
|
| 144 | 144 | }; |
| 145 | 145 | $resultList = $this->getResultsFor('New Zealand',10); |
| 146 | 146 | $resultList->each($callback); |
@@ -319,10 +319,10 @@ |
||
| 319 | 319 | |
| 320 | 320 | foreach($toarr as $item) { |
| 321 | 321 | $hl = $item->SearchHighlights; |
| 322 | - foreach ($hl as $shl) { |
|
| 322 | + foreach($hl as $shl) { |
|
| 323 | 323 | $html = $shl->Snippet; |
| 324 | 324 | $splits = explode('<strong class="hl">', $html); |
| 325 | - if (sizeof($splits) > 1) { |
|
| 325 | + if(sizeof($splits) > 1) { |
|
| 326 | 326 | $splits = explode('</strong>', $splits[1]); |
| 327 | 327 | $term = $splits[0]; |
| 328 | 328 | $term = strtolower($term); |
@@ -233,6 +233,9 @@ |
||
| 233 | 233 | |
| 234 | 234 | |
| 235 | 235 | |
| 236 | + /** |
|
| 237 | + * @param PaginatedList $paginated |
|
| 238 | + */ |
|
| 236 | 239 | private function makeCode($paginated) { |
| 237 | 240 | $results = $paginated->getList()->toArray(); |
| 238 | 241 | $ctr = 0; |
@@ -102,7 +102,7 @@ |
||
| 102 | 102 | $es->setLocale($locale); |
| 103 | 103 | $es->setClasses('FlickrPhotoTO'); |
| 104 | 104 | |
| 105 | - $fields = array('Description.standard' => 1,'Title.standard' => 1); |
|
| 105 | + $fields = array('Description.standard' => 1, 'Title.standard' => 1); |
|
| 106 | 106 | $results = $es->moreLikeThis($fp, $fields, true); |
| 107 | 107 | |
| 108 | 108 | $terms = $results->getList()->MoreLikeThisTerms; |