@@ -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()) { |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | $aggregations = $resultList->getAggregations(); |
| 34 | 34 | |
| 35 | 35 | error_log('AGGS'); |
| 36 | - foreach ($aggregations as $agg) { |
|
| 36 | + foreach($aggregations as $agg) { |
|
| 37 | 37 | error_log($agg->Name); |
| 38 | 38 | } |
| 39 | 39 | |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | $resultList = $this->search(''); |
| 427 | 427 | |
| 428 | 428 | //assert there are actually some results |
| 429 | - $this->assertGreaterThan(0,$resultList->getTotalItems()); |
|
| 429 | + $this->assertGreaterThan(0, $resultList->getTotalItems()); |
|
| 430 | 430 | $aggregations = $resultList->getAggregations()->toArray(); |
| 431 | 431 | |
| 432 | 432 | /* |
@@ -445,49 +445,49 @@ discard block |
||
| 445 | 445 | //Asserting aggregate of ISO, 64 has count 5 |
| 446 | 446 | $this->assertEquals("64", $buckets[0]->Key); |
| 447 | 447 | $this->assertEquals(5, $buckets[0]->DocumentCount); |
| 448 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',64)->count(),5); |
|
| 448 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 64)->count(), 5); |
|
| 449 | 449 | $bucketSum += $buckets[0]->DocumentCount; |
| 450 | 450 | |
| 451 | 451 | //Asserting aggregate of ISO, 100 has count 11 |
| 452 | 452 | $this->assertEquals("100", $buckets[1]->Key); |
| 453 | 453 | $this->assertEquals(11, $buckets[1]->DocumentCount); |
| 454 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',100)->count(),11); |
|
| 454 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 100)->count(), 11); |
|
| 455 | 455 | $bucketSum += $buckets[1]->DocumentCount; |
| 456 | 456 | |
| 457 | 457 | //Asserting aggregate of ISO, 200 has count 12 |
| 458 | 458 | $this->assertEquals("200", $buckets[2]->Key); |
| 459 | 459 | $this->assertEquals(12, $buckets[2]->DocumentCount); |
| 460 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',200)->count(),12); |
|
| 460 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 200)->count(), 12); |
|
| 461 | 461 | $bucketSum += $buckets[2]->DocumentCount; |
| 462 | 462 | |
| 463 | 463 | //Asserting aggregate of ISO, 400 has count 13 |
| 464 | 464 | $this->assertEquals("400", $buckets[3]->Key); |
| 465 | 465 | $this->assertEquals(13, $buckets[3]->DocumentCount); |
| 466 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',400)->count(),13); |
|
| 466 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 400)->count(), 13); |
|
| 467 | 467 | $bucketSum += $buckets[3]->DocumentCount; |
| 468 | 468 | |
| 469 | 469 | //Asserting aggregate of ISO, 800 has count 16 |
| 470 | 470 | $this->assertEquals("800", $buckets[4]->Key); |
| 471 | 471 | $this->assertEquals(16, $buckets[4]->DocumentCount); |
| 472 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',800)->count(),16); |
|
| 472 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 800)->count(), 16); |
|
| 473 | 473 | $bucketSum += $buckets[4]->DocumentCount; |
| 474 | 474 | |
| 475 | 475 | //Asserting aggregate of ISO, 1600 has count 13 |
| 476 | 476 | $this->assertEquals("1600", $buckets[5]->Key); |
| 477 | 477 | $this->assertEquals(13, $buckets[5]->DocumentCount); |
| 478 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',1600)->count(),13); |
|
| 478 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 1600)->count(), 13); |
|
| 479 | 479 | $bucketSum += $buckets[5]->DocumentCount; |
| 480 | 480 | |
| 481 | 481 | //Asserting aggregate of ISO, 2000 has count 11 |
| 482 | 482 | $this->assertEquals("2000", $buckets[6]->Key); |
| 483 | 483 | $this->assertEquals(11, $buckets[6]->DocumentCount); |
| 484 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',2000)->count(),11); |
|
| 484 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 2000)->count(), 11); |
|
| 485 | 485 | $bucketSum += $buckets[6]->DocumentCount; |
| 486 | 486 | |
| 487 | 487 | //Asserting aggregate of ISO, 3200 has count 19 |
| 488 | 488 | $this->assertEquals("3200", $buckets[7]->Key); |
| 489 | 489 | $this->assertEquals(19, $buckets[7]->DocumentCount); |
| 490 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',3200)->count(),19); |
|
| 490 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 3200)->count(), 19); |
|
| 491 | 491 | $bucketSum += $buckets[7]->DocumentCount; |
| 492 | 492 | $this->assertEquals(100, $bucketSum); |
| 493 | 493 | |
@@ -500,43 +500,43 @@ discard block |
||
| 500 | 500 | //Asserting aggregate of Focal Length, 24 has count 12 |
| 501 | 501 | $this->assertEquals("24", $buckets[0]->Key); |
| 502 | 502 | $this->assertEquals(12, $buckets[0]->DocumentCount); |
| 503 | - $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',24)->count(),12); |
|
| 503 | + $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm', 24)->count(), 12); |
|
| 504 | 504 | $bucketSum += $buckets[0]->DocumentCount; |
| 505 | 505 | |
| 506 | 506 | //Asserting aggregate of Focal Length, 50 has count 11 |
| 507 | 507 | $this->assertEquals("50", $buckets[1]->Key); |
| 508 | 508 | $this->assertEquals(11, $buckets[1]->DocumentCount); |
| 509 | - $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',50)->count(),11); |
|
| 509 | + $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm', 50)->count(), 11); |
|
| 510 | 510 | $bucketSum += $buckets[1]->DocumentCount; |
| 511 | 511 | |
| 512 | 512 | //Asserting aggregate of Focal Length, 80 has count 11 |
| 513 | 513 | $this->assertEquals("80", $buckets[2]->Key); |
| 514 | 514 | $this->assertEquals(11, $buckets[2]->DocumentCount); |
| 515 | - $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',80)->count(),11); |
|
| 515 | + $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm', 80)->count(), 11); |
|
| 516 | 516 | $bucketSum += $buckets[2]->DocumentCount; |
| 517 | 517 | |
| 518 | 518 | //Asserting aggregate of Focal Length, 90 has count 20 |
| 519 | 519 | $this->assertEquals("90", $buckets[3]->Key); |
| 520 | 520 | $this->assertEquals(20, $buckets[3]->DocumentCount); |
| 521 | - $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',90)->count(),20); |
|
| 521 | + $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm', 90)->count(), 20); |
|
| 522 | 522 | $bucketSum += $buckets[3]->DocumentCount; |
| 523 | 523 | |
| 524 | 524 | //Asserting aggregate of Focal Length, 120 has count 12 |
| 525 | 525 | $this->assertEquals("120", $buckets[4]->Key); |
| 526 | 526 | $this->assertEquals(12, $buckets[4]->DocumentCount); |
| 527 | - $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',120)->count(),12); |
|
| 527 | + $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm', 120)->count(), 12); |
|
| 528 | 528 | $bucketSum += $buckets[4]->DocumentCount; |
| 529 | 529 | |
| 530 | 530 | //Asserting aggregate of Focal Length, 150 has count 17 |
| 531 | 531 | $this->assertEquals("150", $buckets[5]->Key); |
| 532 | 532 | $this->assertEquals(17, $buckets[5]->DocumentCount); |
| 533 | - $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',150)->count(),17); |
|
| 533 | + $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm', 150)->count(), 17); |
|
| 534 | 534 | $bucketSum += $buckets[5]->DocumentCount; |
| 535 | 535 | |
| 536 | 536 | //Asserting aggregate of Focal Length, 200 has count 17 |
| 537 | 537 | $this->assertEquals("200", $buckets[6]->Key); |
| 538 | 538 | $this->assertEquals(17, $buckets[6]->DocumentCount); |
| 539 | - $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',200)->count(),17); |
|
| 539 | + $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm', 200)->count(), 17); |
|
| 540 | 540 | $bucketSum += $buckets[6]->DocumentCount; |
| 541 | 541 | $this->assertEquals(100, $bucketSum); |
| 542 | 542 | |
@@ -824,7 +824,7 @@ discard block |
||
| 824 | 824 | $originalAggregations = $resultList->getAggregations()->toArray(); |
| 825 | 825 | |
| 826 | 826 | $filters = array('ISO' => 3200); |
| 827 | - $resultListFiltered = $this->search('New Zealand', $fields,$filters); |
|
| 827 | + $resultListFiltered = $this->search('New Zealand', $fields, $filters); |
|
| 828 | 828 | $filteredAggregations = $resultListFiltered->getAggregations()->toArray(); |
| 829 | 829 | |
| 830 | 830 | $this->checkDrillingDownHasHappened($filteredAggregations, $originalAggregations); |
@@ -836,8 +836,8 @@ discard block |
||
| 836 | 836 | $resultList = $this->search('New Zealand', $fields, array('ISO' => 400)); |
| 837 | 837 | $originalAggregations = $resultList->getAggregations()->toArray(); |
| 838 | 838 | |
| 839 | - $filters = array('ISO' => 400, 'Aspect' => 'Vertical' ); |
|
| 840 | - $resultListFiltered = $this->search('New Zealand', $fields,$filters); |
|
| 839 | + $filters = array('ISO' => 400, 'Aspect' => 'Vertical'); |
|
| 840 | + $resultListFiltered = $this->search('New Zealand', $fields, $filters); |
|
| 841 | 841 | $filteredAggregations = $resultListFiltered->getAggregations()->toArray(); |
| 842 | 842 | |
| 843 | 843 | $this->checkDrillingDownHasHappened($filteredAggregations, $originalAggregations); |
@@ -852,8 +852,8 @@ discard block |
||
| 852 | 852 | 'Aspect' => 'Vertical')); |
| 853 | 853 | $originalAggregations = $resultList->getAggregations()->toArray(); |
| 854 | 854 | |
| 855 | - $filters = array('ISO' => 400, 'Aspect' => 'Vertical', 'Aperture' => 5 ); |
|
| 856 | - $resultListFiltered = $this->search('New Zealand', $fields,$filters); |
|
| 855 | + $filters = array('ISO' => 400, 'Aspect' => 'Vertical', 'Aperture' => 5); |
|
| 856 | + $resultListFiltered = $this->search('New Zealand', $fields, $filters); |
|
| 857 | 857 | $filteredAggregations = $resultListFiltered->getAggregations()->toArray(); |
| 858 | 858 | |
| 859 | 859 | $this->checkDrillingDownHasHappened($filteredAggregations, $originalAggregations); |
@@ -893,7 +893,7 @@ discard block |
||
| 893 | 893 | private function checkDrillingDownHasHappened($filteredAggregations, $originalAggregations) { |
| 894 | 894 | $aggCtr = 0; |
| 895 | 895 | |
| 896 | - foreach ($filteredAggregations as $filteredAgg) { |
|
| 896 | + foreach($filteredAggregations as $filteredAgg) { |
|
| 897 | 897 | $origAgg = $originalAggregations[$aggCtr]; |
| 898 | 898 | $bucketCtr = 0; |
| 899 | 899 | $origBuckets = $origAgg->Buckets->toArray(); |
@@ -902,17 +902,17 @@ discard block |
||
| 902 | 902 | $origCounts = array(); |
| 903 | 903 | $filteredCounts = array(); |
| 904 | 904 | |
| 905 | - foreach ($origBuckets as $bucket) { |
|
| 905 | + foreach($origBuckets as $bucket) { |
|
| 906 | 906 | $origCounts[$bucket->Key] = $bucket->DocumentCount; |
| 907 | 907 | } |
| 908 | 908 | |
| 909 | - foreach ($filteredBuckets as $bucket) { |
|
| 909 | + foreach($filteredBuckets as $bucket) { |
|
| 910 | 910 | $filteredCounts[$bucket->Key] = $bucket->DocumentCount; |
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | $akf = array_keys($filteredCounts); |
| 914 | 914 | |
| 915 | - foreach ($akf as $aggregateKey) { |
|
| 915 | + foreach($akf as $aggregateKey) { |
|
| 916 | 916 | $this->assertGreaterThanOrEqual( |
| 917 | 917 | $filteredCounts[$aggregateKey], $origCounts[$aggregateKey] |
| 918 | 918 | ); |
@@ -948,8 +948,8 @@ discard block |
||
| 948 | 948 | $es->setQueryResultManipulator('FlickrPhotoTOElasticaSearchHelper'); |
| 949 | 949 | |
| 950 | 950 | //Add filters |
| 951 | - foreach ($filters as $key => $value) { |
|
| 952 | - $es->addFilter($key,$value); |
|
| 951 | + foreach($filters as $key => $value) { |
|
| 952 | + $es->addFilter($key, $value); |
|
| 953 | 953 | } |
| 954 | 954 | |
| 955 | 955 | $es->showResultsForEmptySearch(); |
@@ -968,7 +968,7 @@ discard block |
||
| 968 | 968 | * Test searching |
| 969 | 969 | * http://stackoverflow.com/questions/28305250/elasticsearch-customize-score-for-synonyms-stemming |
| 970 | 970 | */ |
| 971 | - private function search($queryText,$fields = array('Title' => 1, 'Description' => 1), |
|
| 971 | + private function search($queryText, $fields = array('Title' => 1, 'Description' => 1), |
|
| 972 | 972 | $filters = array()) { |
| 973 | 973 | $es = new ElasticSearcher(); |
| 974 | 974 | $es->setStart(0); |
@@ -977,8 +977,8 @@ discard block |
||
| 977 | 977 | $es->setQueryResultManipulator('FlickrPhotoTOElasticaSearchHelper'); |
| 978 | 978 | |
| 979 | 979 | //Add filters |
| 980 | - foreach ($filters as $key => $value) { |
|
| 981 | - $es->addFilter($key,$value); |
|
| 980 | + foreach($filters as $key => $value) { |
|
| 981 | + $es->addFilter($key, $value); |
|
| 982 | 982 | } |
| 983 | 983 | |
| 984 | 984 | $es->showResultsForEmptySearch(); |
@@ -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) { |
@@ -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' |
|
| 11 | + 'SearchableTestPage', 'FlickrPhotoTO', 'FlickrAuthorTO', 'FlickrSetTO', 'FlickrTagTO', |
|
| 12 | + 'SearchableTestFatherPage', 'SearchableTestGrandFatherPage' |
|
| 13 | 13 | ); |
| 14 | 14 | |
| 15 | 15 | |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | public function setUp() { |
| 26 | 26 | |
| 27 | - echo "*************** TEST: ".$this->getName(); |
|
| 27 | + echo "*************** TEST: " . $this->getName(); |
|
| 28 | 28 | |
| 29 | 29 | $cache = SS_Cache::factory('elasticsearch'); |
| 30 | 30 | $cache->clean(Zend_Cache::CLEANING_MODE_ALL); |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | // this needs to be called in order to create the list of searchable |
| 34 | 34 | // classes and fields that are available. Simulates part of a build |
| 35 | - $classes = array('SearchableTestPage','SiteTree','Page','FlickrPhotoTO','FlickrSetTO', |
|
| 35 | + $classes = array('SearchableTestPage', 'SiteTree', 'Page', 'FlickrPhotoTO', 'FlickrSetTO', |
|
| 36 | 36 | 'FlickrTagTO', 'FlickrAuthorTO'); |
| 37 | 37 | $this->requireDefaultRecordsFrom = $classes; |
| 38 | 38 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | $this->service->setTestMode(true); |
| 49 | 49 | |
| 50 | 50 | // A previous test may have deleted the index and then failed, so check for this |
| 51 | - if (!$this->service->getIndex()->exists()) { |
|
| 51 | + if(!$this->service->getIndex()->exists()) { |
|
| 52 | 52 | $this->service->getIndex()->create(); |
| 53 | 53 | } |
| 54 | 54 | $this->service->reset(); |
@@ -59,9 +59,9 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | $orig_fixture_file = static::$fixture_file; |
| 61 | 61 | |
| 62 | - foreach (static::$ignoreFixtureFileFor as $testPattern) { |
|
| 63 | - $pattern = '/'.$testPattern.'/'; |
|
| 64 | - if (preg_match($pattern, $this->getName())) { |
|
| 62 | + foreach(static::$ignoreFixtureFileFor as $testPattern) { |
|
| 63 | + $pattern = '/' . $testPattern . '/'; |
|
| 64 | + if(preg_match($pattern, $this->getName())) { |
|
| 65 | 65 | static::$fixture_file = null; |
| 66 | 66 | } |
| 67 | 67 | } |
@@ -83,11 +83,11 @@ discard block |
||
| 83 | 83 | |
| 84 | 84 | |
| 85 | 85 | private function publishSiteTree() { |
| 86 | - foreach (SiteTree::get()->getIterator() as $page) { |
|
| 86 | + foreach(SiteTree::get()->getIterator() as $page) { |
|
| 87 | 87 | // temporarily disable Elasticsearch indexing, it will be done in a batch |
| 88 | 88 | $page->IndexingOff = true; |
| 89 | 89 | |
| 90 | - $page->publish('Stage','Live'); |
|
| 90 | + $page->publish('Stage', 'Live'); |
|
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | $items = $this->cssParser()->getBySelector($selector); |
| 109 | 109 | |
| 110 | 110 | $ctr = 0; |
| 111 | - foreach ($items as $item) { |
|
| 111 | + foreach($items as $item) { |
|
| 112 | 112 | $text = strip_tags($item); |
| 113 | 113 | $escaped = str_replace("'", "\'", $text); |
| 114 | 114 | $ctr++; |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | */ |
| 131 | 131 | public function assertAttributeHasExactValue($selector, $attributeName, $expectedValue) { |
| 132 | 132 | $items = $this->cssParser()->getBySelector($selector); |
| 133 | - foreach ($items as $item) { |
|
| 133 | + foreach($items as $item) { |
|
| 134 | 134 | $this->assertEquals($expectedValue, $item['value']); |
| 135 | 135 | } |
| 136 | 136 | } |
@@ -139,9 +139,9 @@ discard block |
||
| 139 | 139 | public function assertAttributesHaveExactValues($selector, $expectedValues) { |
| 140 | 140 | $attributeNames = array_keys($expectedValues); |
| 141 | 141 | $items = $this->cssParser()->getBySelector($selector); |
| 142 | - foreach ($items as $item) { |
|
| 142 | + foreach($items as $item) { |
|
| 143 | 143 | $actualValues = array(); |
| 144 | - foreach ($attributeNames as $attributeName) { |
|
| 144 | + foreach($attributeNames as $attributeName) { |
|
| 145 | 145 | $actualValues[$attributeName] = (string)$item[$attributeName]; |
| 146 | 146 | } |
| 147 | 147 | $this->assertEquals($expectedValues, $actualValues); |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | |
| 152 | 152 | public function assertNumberOfNodes($selector, $expectedAmount) { |
| 153 | 153 | $items = $this->cssParser()->getBySelector($selector); |
| 154 | - foreach ($items as $item) { |
|
| 154 | + foreach($items as $item) { |
|
| 155 | 155 | $text = strip_tags($item); |
| 156 | 156 | } |
| 157 | 157 | |
@@ -164,9 +164,9 @@ discard block |
||
| 164 | 164 | public function collateSearchResults() { |
| 165 | 165 | $items = $this->cssParser()->getBySelector('div.searchResults .searchResult'); |
| 166 | 166 | $result = array(); |
| 167 | - foreach ($items as $item) { |
|
| 167 | + foreach($items as $item) { |
|
| 168 | 168 | $attr = $item->attributes()->id; |
| 169 | - array_push($result, $attr.""); |
|
| 169 | + array_push($result, $attr . ""); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | 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 | |
@@ -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','AutoCompleteOption' |
|
| 12 | + 'SearchableTestPage', 'FlickrPhotoTO', 'FlickrAuthorTO', 'FlickrSetTO', 'FlickrTagTO', |
|
| 13 | + 'SearchableTestFatherPage', 'SearchableTestGrandFatherPage', 'AutoCompleteOption' |
|
| 14 | 14 | ); |
| 15 | 15 | |
| 16 | 16 | |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | // this needs to be called in order to create the list of searchable |
| 41 | 41 | // classes and fields that are available. Simulates part of a build |
| 42 | - $classes = array('SearchableTestPage','SiteTree','Page','FlickrPhotoTO','FlickrSetTO', |
|
| 42 | + $classes = array('SearchableTestPage', 'SiteTree', 'Page', 'FlickrPhotoTO', 'FlickrSetTO', |
|
| 43 | 43 | 'FlickrTagTO', 'FlickrAuthorTO'); |
| 44 | 44 | $this->requireDefaultRecordsFrom = $classes; |
| 45 | 45 | |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $this->service->setTestMode(true); |
| 50 | 50 | |
| 51 | 51 | // A previous test may have deleted the index and then failed, so check for this |
| 52 | - if (!$this->service->getIndex()->exists()) { |
|
| 52 | + if(!$this->service->getIndex()->exists()) { |
|
| 53 | 53 | $this->service->getIndex()->create(); |
| 54 | 54 | } |
| 55 | 55 | $this->service->reset(); |
@@ -60,9 +60,9 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | $orig_fixture_file = static::$fixture_file; |
| 62 | 62 | |
| 63 | - foreach (static::$ignoreFixtureFileFor as $testPattern) { |
|
| 64 | - $pattern = '/'.$testPattern.'/'; |
|
| 65 | - if (preg_match($pattern, $this->getName())) { |
|
| 63 | + foreach(static::$ignoreFixtureFileFor as $testPattern) { |
|
| 64 | + $pattern = '/' . $testPattern . '/'; |
|
| 65 | + if(preg_match($pattern, $this->getName())) { |
|
| 66 | 66 | static::$fixture_file = null; |
| 67 | 67 | } |
| 68 | 68 | } |
@@ -91,55 +91,55 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | |
| 93 | 93 | private function publishSiteTree() { |
| 94 | - foreach (SiteTree::get()->getIterator() as $page) { |
|
| 94 | + foreach(SiteTree::get()->getIterator() as $page) { |
|
| 95 | 95 | // temporarily disable Elasticsearch indexing, it will be done in a batch |
| 96 | 96 | $page->IndexingOff = true; |
| 97 | - $page->publish('Stage','Live'); |
|
| 97 | + $page->publish('Stage', 'Live'); |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | |
| 102 | 102 | public function generateAssertionsFromArray($toAssert) { |
| 103 | - echo '$expected = array('."\n"; |
|
| 104 | - foreach ($toAssert as $key => $value) { |
|
| 103 | + echo '$expected = array(' . "\n"; |
|
| 104 | + foreach($toAssert as $key => $value) { |
|
| 105 | 105 | $escValue = str_replace("'", '\\\'', $value); |
| 106 | 106 | echo "'$key' => '$escValue',\n"; |
| 107 | 107 | } |
| 108 | 108 | echo ");\n"; |
| 109 | - echo '$this->assertEquals($expected, $somevar);'."\n"; |
|
| 109 | + echo '$this->assertEquals($expected, $somevar);' . "\n"; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | |
| 113 | 113 | public function generateAssertionsFromArray1D($toAssert) { |
| 114 | - echo '$expected = array('."\n"; |
|
| 115 | - foreach ($toAssert as $key => $value) { |
|
| 114 | + echo '$expected = array(' . "\n"; |
|
| 115 | + foreach($toAssert as $key => $value) { |
|
| 116 | 116 | $escValue = str_replace("'", '\\\'', $value); |
| 117 | 117 | echo "'$escValue',"; |
| 118 | 118 | } |
| 119 | 119 | echo ");\n"; |
| 120 | - echo '$this->assertEquals($expected, $somevar);'."\n"; |
|
| 120 | + echo '$this->assertEquals($expected, $somevar);' . "\n"; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | |
| 124 | 124 | public function generateAssertionsFromArrayRecurse($toAssert) { |
| 125 | 125 | echo '$expected = '; |
| 126 | - $this->recurseArrayAssertion($toAssert,1, 'FIXME'); |
|
| 127 | - echo '$this->assertEquals($expected, $somevar);'."\n"; |
|
| 126 | + $this->recurseArrayAssertion($toAssert, 1, 'FIXME'); |
|
| 127 | + echo '$this->assertEquals($expected, $somevar);' . "\n"; |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | |
| 131 | 131 | private function recurseArrayAssertion($toAssert, $depth, $parentKey) { |
| 132 | - $prefix = str_repeat("\t",$depth); |
|
| 132 | + $prefix = str_repeat("\t", $depth); |
|
| 133 | 133 | echo "\t{$prefix}'$parentKey' => array(\n"; |
| 134 | 134 | $ctr = 0; |
| 135 | 135 | $len = sizeof(array_keys($toAssert)); |
| 136 | - foreach ($toAssert as $key => $value) { |
|
| 137 | - if (is_array($value)) { |
|
| 138 | - $this->recurseArrayAssertion($value, $depth+1, $key); |
|
| 136 | + foreach($toAssert as $key => $value) { |
|
| 137 | + if(is_array($value)) { |
|
| 138 | + $this->recurseArrayAssertion($value, $depth + 1, $key); |
|
| 139 | 139 | } else { |
| 140 | 140 | $escValue = str_replace("'", '\\\'', $value); |
| 141 | 141 | $comma = ','; |
| 142 | - if ($ctr == $len-1) { |
|
| 142 | + if($ctr == $len - 1) { |
|
| 143 | 143 | $comma = ''; |
| 144 | 144 | } |
| 145 | 145 | echo "\t\t$prefix'$key' => '$escValue'$comma\n"; |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | $size = sizeof($splits); |
| 164 | 164 | $nameToCheck = end($splits); |
| 165 | 165 | $this->assertEquals($actualTabName, $nameToCheck); |
| 166 | - if ($size == 1) { |
|
| 166 | + if($size == 1) { |
|
| 167 | 167 | $this->assertEquals("Root_${tabName}", $tab->id()); |
| 168 | 168 | } else { |
| 169 | 169 | $expected = "Root_{$splits[0]}_set_{$splits[1]}"; |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | |
| 177 | - public function checkFieldExists($tab,$fieldName) { |
|
| 177 | + public function checkFieldExists($tab, $fieldName) { |
|
| 178 | 178 | $fields = $tab->Fields(); |
| 179 | 179 | $field = $tab->fieldByName($fieldName); |
| 180 | 180 | $this->assertTrue($field != null); |
@@ -207,11 +207,11 @@ discard block |
||
| 207 | 207 | $status = $index->getStatus()->getData(); |
| 208 | 208 | |
| 209 | 209 | $numberDocsInIndex = -1; // flag value for not yet indexed |
| 210 | - if (isset($status['indices']['elastica_ss_module_test_en_us']['docs'])) { |
|
| 210 | + if(isset($status['indices']['elastica_ss_module_test_en_us']['docs'])) { |
|
| 211 | 211 | $numberDocsInIndex = $status['indices']['elastica_ss_module_test_en_us']['docs']['num_docs']; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - $this->assertEquals($expectedAmount,$numberDocsInIndex); |
|
| 214 | + $this->assertEquals($expectedAmount, $numberDocsInIndex); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /* |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | $status = $index->getStatus()->getData(); |
| 223 | 223 | |
| 224 | 224 | $numberDocsInIndex = -1; // flag value for not yet indexed |
| 225 | - if (isset($status['indices']['elastica_ss_module_test_en_us']['docs'])) { |
|
| 225 | + if(isset($status['indices']['elastica_ss_module_test_en_us']['docs'])) { |
|
| 226 | 226 | $numberDocsInIndex = $status['indices']['elastica_ss_module_test_en_us']['docs']['num_docs']; |
| 227 | 227 | } |
| 228 | 228 | |
@@ -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; |