Source of file InheritanceTest.php
Size: 2,829 Bytes - Last Modified: 2021-12-23T10:58:34+00:00
/var/www/docs.ssmods.com/process/src/tests/short/InheritanceTest.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 | <?php use SilverStripe\Elastica\Searchable; /** * Test that inheritance works correctly with configuration properties. */ class InheritanceTest extends ElasticsearchTestBase { public static $fixture_file = 'elastica/tests/ElasticaTest.yml'; /* Check that searchable and autocomplete are inherited mapping wise */ public function testSearchableAndAutocompleteInherited() { $page = $this->objFromFixture('SearchableTestPage', 'first'); $this->assertTrue($page->hasExtension('SilverStripe\Elastica\Searchable'), 'Page extending SiteTree has Searchable extension'); $fields = $page->getElasticaFields(); $terms = $page->getTermVectors(); $expected = array('first'); $this->assertEquals($expected, array_keys($terms['Title.standard']['terms'])); $expected = array('fi', 'fir', 'firs', 'first', 'ir', 'irs', 'irst', 'rs', 'rst', 'st'); $this->assertEquals($expected, array_keys($terms['Title.autocomplete']['terms'])); // ---- now a parental class page ---- $this->assertTrue(isset($fields['Title']['fields']['autocomplete'])); $page = $this->objFromFixture('SearchableTestFatherPage', 'father0001'); $this->assertTrue($page->hasExtension('SilverStripe\Elastica\Searchable'), 'Page extending SiteTree has Searchable extension'); $fields = $page->getElasticaFields(); $this->assertTrue(isset($fields['Title']['fields']['autocomplete'])); $page = $this->objFromFixture('SearchableTestGrandFatherPage', 'grandfather0001'); $this->assertTrue($page->hasExtension('SilverStripe\Elastica\Searchable'), 'Page extending SiteTree has Searchable extension'); $fields = $page->getElasticaFields(); $this->assertTrue(isset($fields['Title']['fields']['autocomplete'])); $terms = $page->getTermVectors(); //Check the expected fields are indexed $expected = array('Content', 'Content.shingles', 'Content.standard', 'FatherText', 'FatherText.shingles', 'FatherText.standard', 'GrandFatherText', 'GrandFatherText.shingles', 'GrandFatherText.standard', 'Link', 'Title', 'Title.autocomplete', 'Title.shingles', 'Title.standard', ); $indexedFields = array_keys($terms); sort($indexedFields); $this->assertEquals($expected, $indexedFields); $fatherTerms = $terms['FatherText.standard']['terms']; $grandFatherTerms = $terms['GrandFatherText.standard']['terms']; $expected = array('father', 'field', 'grandfather', 'page', 'trace3'); $this->assertEquals($expected, array_keys($fatherTerms)); $expected = array('grandfather', 'page', 'trace4'); $this->assertEquals($expected, array_keys($grandFatherTerms)); } } |