X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/51287d545b1e6a7054726e5bccefae03839229ad..refs/pull/5405/head:/tests/Entity/EntitySearchTest.php diff --git a/tests/Entity/EntitySearchTest.php b/tests/Entity/EntitySearchTest.php index 57b7c3f6b..5ace70e3a 100644 --- a/tests/Entity/EntitySearchTest.php +++ b/tests/Entity/EntitySearchTest.php @@ -6,6 +6,7 @@ use BookStack\Activity\Models\Tag; use BookStack\Entities\Models\Book; use BookStack\Entities\Models\Bookshelf; use BookStack\Entities\Models\Chapter; +use Illuminate\Support\Str; use Tests\TestCase; class EntitySearchTest extends TestCase @@ -393,11 +394,11 @@ class EntitySearchTest extends TestCase $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$contextBook->id}&entity_type=book"); $this->withHtml($search)->assertElementNotContains('a:first-child', 'Zebras'); - $searchBook->name = 'AAAAAAArdvarks'; + $searchBook->name = '1AAAAAAArdvarks'; $searchBook->save(); $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$contextBook->id}&entity_type=book"); - $this->withHtml($search)->assertElementContains('a:first-child', 'AAAAAAArdvarks'); + $this->withHtml($search)->assertElementContains('a:first-child', '1AAAAAAArdvarks'); } public function test_sibling_search_for_shelves_provides_results_in_alphabetical_order() @@ -411,11 +412,11 @@ class EntitySearchTest extends TestCase $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$contextShelf->id}&entity_type=bookshelf"); $this->withHtml($search)->assertElementNotContains('a:first-child', 'Zebras'); - $searchShelf->name = 'AAAAAAArdvarks'; + $searchShelf->name = '1AAAAAAArdvarks'; $searchShelf->save(); $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$contextShelf->id}&entity_type=bookshelf"); - $this->withHtml($search)->assertElementContains('a:first-child', 'AAAAAAArdvarks'); + $this->withHtml($search)->assertElementContains('a:first-child', '1AAAAAAArdvarks'); } public function test_search_works_on_updated_page_content() @@ -477,6 +478,25 @@ class EntitySearchTest extends TestCase $this->assertEquals(2, $scoreByTerm->get('TermG')); } + public function test_indexing_works_as_expected_for_page_with_lots_of_terms() + { + $this->markTestSkipped('Time consuming test'); + + $count = 100000; + $text = ''; + $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_#'; + for ($i = 0; $i < $count; $i++) { + $text .= substr(str_shuffle($chars), 0, 5) . ' '; + } + + $page = $this->entities->newPage(['name' => 'Test page A', 'html' => '
' . $text . '
']); + + $termCount = $page->searchTerms()->count(); + + // Expect at least 90% unique rate + $this->assertGreaterThan($count * 0.9, $termCount); + } + public function test_name_and_content_terms_are_merged_to_single_score() { $page = $this->entities->newPage(['name' => 'TermA', 'html' => '