gordonbanderson /
freetextsearch
| 1 | <?php declare(strict_types = 1); |
||
| 2 | |||
| 3 | namespace Suilven\FreeTextSearch\Tests\Page; |
||
| 4 | |||
| 5 | use SilverStripe\Dev\SapphireTest; |
||
| 6 | use Suilven\FreeTextSearch\Container\SearchResults; |
||
| 7 | use Suilven\FreeTextSearch\Page\SearchPage; |
||
| 8 | |||
| 9 | class SearchPageTest extends SapphireTest |
||
| 10 | { |
||
| 11 | protected static $fixture_file = ['tests/fixtures/pages.yml']; |
||
| 12 | |||
| 13 | |||
| 14 | public function testGetIndex(): void |
||
| 15 | { |
||
| 16 | /** @var \Suilven\FreeTextSearch\Page\SearchPage $photoSearchPage */ |
||
| 17 | $photoSearchPage = $this->objFromFixture(SearchPage::class, 'photo-search'); |
||
| 18 | |||
| 19 | $this->assertEquals('flickrphotos', $photoSearchPage->IndexToSearch); |
||
| 20 | } |
||
| 21 | |||
| 22 | |||
| 23 | public function testGetFacets(): void |
||
| 24 | { |
||
| 25 | /** @var \Suilven\FreeTextSearch\Page\SearchPage $photoSearchPage */ |
||
| 26 | $photoSearchPage = $this->objFromFixture(SearchPage::class, 'photo-search'); |
||
| 27 | |||
| 28 | $this->assertEquals([ |
||
| 29 | 'Aperture', |
||
| 30 | 'ShutterSpeed', |
||
| 31 | 'ISO', |
||
| 32 | 'Photographer', |
||
| 33 | ], $photoSearchPage->getFacetFields()); |
||
| 34 | } |
||
| 35 | |||
| 36 | |||
| 37 | public function testGetHasManyFields(): void |
||
| 38 | { |
||
| 39 | /** @var \Suilven\FreeTextSearch\Page\SearchPage $photoSearchPage */ |
||
| 40 | $photoSearchPage = $this->objFromFixture(SearchPage::class, 'photo-search'); |
||
| 41 | |||
| 42 | $this->assertEquals(['tags'], $photoSearchPage->getHasManyFields()); |
||
| 43 | } |
||
| 44 | |||
| 45 | |||
| 46 | public function testGetCMSFields(): void |
||
| 47 | { |
||
| 48 | /** @var \Suilven\FreeTextSearch\Page\SearchPage $photoSearchPage */ |
||
| 49 | $photoSearchPage = $this->objFromFixture(SearchPage::class, 'photo-search'); |
||
| 50 | |||
| 51 | $fields = $photoSearchPage->getCMSFields(); |
||
| 52 | /** @var \Suilven\FreeTextSearch\Tests\Page\TabSet $rootTab */ |
||
| 53 | $rootTab = $fields->fieldByName('Root'); |
||
|
0 ignored issues
–
show
|
|||
| 54 | |||
| 55 | /** @var \Suilven\FreeTextSearch\Tests\Page\Tab $mainTab */ |
||
| 56 | $mainTab = $rootTab->fieldByName('Index'); |
||
| 57 | $fields = $mainTab->FieldList(); |
||
| 58 | |||
| 59 | // This is present for PostgresSQL on Travis only |
||
| 60 | $fields->removeByName('InstallWarningHeader'); |
||
| 61 | |||
| 62 | $names = \array_map( |
||
| 63 | static function ($field) { |
||
| 64 | return $field->Name; |
||
| 65 | }, |
||
| 66 | $fields->toArray() |
||
| 67 | ); |
||
| 68 | $this->assertEquals([ |
||
| 69 | 'IndexToSearch', |
||
| 70 | 'PageSize', |
||
| 71 | 'MaximumNumberOfFacets', |
||
| 72 | 'PageLandingMode', |
||
| 73 | 'ShowTagCloudFor', |
||
| 74 | ], $names); |
||
| 75 | } |
||
| 76 | |||
| 77 | |||
| 78 | public function testSetGetSearchResults(): void |
||
| 79 | { |
||
| 80 | /** @var \Suilven\FreeTextSearch\Page\SearchPage $photoSearchPage */ |
||
| 81 | $photoSearchPage = $this->objFromFixture(SearchPage::class, 'photo-search'); |
||
| 82 | |||
| 83 | $searchResults = new SearchResults(); |
||
| 84 | $searchResults->setQuery('test'); |
||
| 85 | $searchResults->setTime(9.58); |
||
| 86 | |||
| 87 | $photoSearchPage->setSearchResults($searchResults); |
||
| 88 | |||
| 89 | $obtainedSearchResults = $photoSearchPage->getSearchResults(); |
||
| 90 | $this->assertEquals('test', $obtainedSearchResults->getQuery()); |
||
| 91 | $this->assertEquals(9.58, $obtainedSearchResults->getTime()); |
||
| 92 | } |
||
| 93 | } |
||
| 94 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.