|
1 | 1 | <?php |
2 | 2 |
|
3 | | -namespace Tests\Entity; |
| 3 | +namespace Search; |
4 | 4 |
|
5 | 5 | use BookStack\Activity\Models\Tag; |
6 | 6 | use BookStack\Entities\Models\Book; |
7 | | -use BookStack\Entities\Models\Bookshelf; |
8 | | -use BookStack\Entities\Models\Chapter; |
9 | | -use Illuminate\Support\Str; |
10 | 7 | use Tests\TestCase; |
11 | 8 |
|
12 | 9 | class EntitySearchTest extends TestCase |
@@ -312,113 +309,6 @@ public function test_entity_template_selector_search() |
312 | 309 | $defaultListTest->assertDontSee($templatePage->name); |
313 | 310 | } |
314 | 311 |
|
315 | | - public function test_sibling_search_for_pages() |
316 | | - { |
317 | | - $chapter = $this->entities->chapterHasPages(); |
318 | | - $this->assertGreaterThan(2, count($chapter->pages), 'Ensure we\'re testing with at least 1 sibling'); |
319 | | - $page = $chapter->pages->first(); |
320 | | - |
321 | | - $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$page->id}&entity_type=page"); |
322 | | - $search->assertSuccessful(); |
323 | | - foreach ($chapter->pages as $page) { |
324 | | - $search->assertSee($page->name); |
325 | | - } |
326 | | - |
327 | | - $search->assertDontSee($chapter->name); |
328 | | - } |
329 | | - |
330 | | - public function test_sibling_search_for_pages_without_chapter() |
331 | | - { |
332 | | - $page = $this->entities->pageNotWithinChapter(); |
333 | | - $bookChildren = $page->book->getDirectVisibleChildren(); |
334 | | - $this->assertGreaterThan(2, count($bookChildren), 'Ensure we\'re testing with at least 1 sibling'); |
335 | | - |
336 | | - $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$page->id}&entity_type=page"); |
337 | | - $search->assertSuccessful(); |
338 | | - foreach ($bookChildren as $child) { |
339 | | - $search->assertSee($child->name); |
340 | | - } |
341 | | - |
342 | | - $search->assertDontSee($page->book->name); |
343 | | - } |
344 | | - |
345 | | - public function test_sibling_search_for_chapters() |
346 | | - { |
347 | | - $chapter = $this->entities->chapter(); |
348 | | - $bookChildren = $chapter->book->getDirectVisibleChildren(); |
349 | | - $this->assertGreaterThan(2, count($bookChildren), 'Ensure we\'re testing with at least 1 sibling'); |
350 | | - |
351 | | - $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$chapter->id}&entity_type=chapter"); |
352 | | - $search->assertSuccessful(); |
353 | | - foreach ($bookChildren as $child) { |
354 | | - $search->assertSee($child->name); |
355 | | - } |
356 | | - |
357 | | - $search->assertDontSee($chapter->book->name); |
358 | | - } |
359 | | - |
360 | | - public function test_sibling_search_for_books() |
361 | | - { |
362 | | - $books = Book::query()->take(10)->get(); |
363 | | - $book = $books->first(); |
364 | | - $this->assertGreaterThan(2, count($books), 'Ensure we\'re testing with at least 1 sibling'); |
365 | | - |
366 | | - $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$book->id}&entity_type=book"); |
367 | | - $search->assertSuccessful(); |
368 | | - foreach ($books as $expectedBook) { |
369 | | - $search->assertSee($expectedBook->name); |
370 | | - } |
371 | | - } |
372 | | - |
373 | | - public function test_sibling_search_for_shelves() |
374 | | - { |
375 | | - $shelves = Bookshelf::query()->take(10)->get(); |
376 | | - $shelf = $shelves->first(); |
377 | | - $this->assertGreaterThan(2, count($shelves), 'Ensure we\'re testing with at least 1 sibling'); |
378 | | - |
379 | | - $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$shelf->id}&entity_type=bookshelf"); |
380 | | - $search->assertSuccessful(); |
381 | | - foreach ($shelves as $expectedShelf) { |
382 | | - $search->assertSee($expectedShelf->name); |
383 | | - } |
384 | | - } |
385 | | - |
386 | | - public function test_sibling_search_for_books_provides_results_in_alphabetical_order() |
387 | | - { |
388 | | - $contextBook = $this->entities->book(); |
389 | | - $searchBook = $this->entities->book(); |
390 | | - |
391 | | - $searchBook->name = 'Zebras'; |
392 | | - $searchBook->save(); |
393 | | - |
394 | | - $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$contextBook->id}&entity_type=book"); |
395 | | - $this->withHtml($search)->assertElementNotContains('a:first-child', 'Zebras'); |
396 | | - |
397 | | - $searchBook->name = '1AAAAAAArdvarks'; |
398 | | - $searchBook->save(); |
399 | | - |
400 | | - $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$contextBook->id}&entity_type=book"); |
401 | | - $this->withHtml($search)->assertElementContains('a:first-child', '1AAAAAAArdvarks'); |
402 | | - } |
403 | | - |
404 | | - public function test_sibling_search_for_shelves_provides_results_in_alphabetical_order() |
405 | | - { |
406 | | - $contextShelf = $this->entities->shelf(); |
407 | | - $searchShelf = $this->entities->shelf(); |
408 | | - |
409 | | - $searchShelf->name = 'Zebras'; |
410 | | - $searchShelf->save(); |
411 | | - |
412 | | - $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$contextShelf->id}&entity_type=bookshelf"); |
413 | | - $this->withHtml($search)->assertElementNotContains('a:first-child', 'Zebras'); |
414 | | - |
415 | | - $searchShelf->name = '1AAAAAAArdvarks'; |
416 | | - $searchShelf->save(); |
417 | | - |
418 | | - $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$contextShelf->id}&entity_type=bookshelf"); |
419 | | - $this->withHtml($search)->assertElementContains('a:first-child', '1AAAAAAArdvarks'); |
420 | | - } |
421 | | - |
422 | 312 | public function test_search_works_on_updated_page_content() |
423 | 313 | { |
424 | 314 | $page = $this->entities->page(); |
@@ -453,75 +343,6 @@ public function test_search_ranks_common_words_lower() |
453 | 343 | $this->withHtml($search)->assertElementContains('.entity-list > .page:nth-child(2)', 'Test page A'); |
454 | 344 | } |
455 | 345 |
|
456 | | - public function test_terms_in_headers_have_an_adjusted_index_score() |
457 | | - { |
458 | | - $page = $this->entities->newPage(['name' => 'Test page A', 'html' => ' |
459 | | - <p>TermA</p> |
460 | | - <h1>TermB <strong>TermNested</strong></h1> |
461 | | - <h2>TermC</h2> |
462 | | - <h3>TermD</h3> |
463 | | - <h4>TermE</h4> |
464 | | - <h5>TermF</h5> |
465 | | - <h6>TermG</h6> |
466 | | - ']); |
467 | | - |
468 | | - $scoreByTerm = $page->searchTerms()->pluck('score', 'term'); |
469 | | - |
470 | | - $this->assertEquals(1, $scoreByTerm->get('TermA')); |
471 | | - $this->assertEquals(10, $scoreByTerm->get('TermB')); |
472 | | - $this->assertEquals(10, $scoreByTerm->get('TermNested')); |
473 | | - $this->assertEquals(5, $scoreByTerm->get('TermC')); |
474 | | - $this->assertEquals(4, $scoreByTerm->get('TermD')); |
475 | | - $this->assertEquals(3, $scoreByTerm->get('TermE')); |
476 | | - $this->assertEquals(2, $scoreByTerm->get('TermF')); |
477 | | - // Is 1.5 but stored as integer, rounding up |
478 | | - $this->assertEquals(2, $scoreByTerm->get('TermG')); |
479 | | - } |
480 | | - |
481 | | - public function test_indexing_works_as_expected_for_page_with_lots_of_terms() |
482 | | - { |
483 | | - $this->markTestSkipped('Time consuming test'); |
484 | | - |
485 | | - $count = 100000; |
486 | | - $text = ''; |
487 | | - $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_#'; |
488 | | - for ($i = 0; $i < $count; $i++) { |
489 | | - $text .= substr(str_shuffle($chars), 0, 5) . ' '; |
490 | | - } |
491 | | - |
492 | | - $page = $this->entities->newPage(['name' => 'Test page A', 'html' => '<p>' . $text . '</p>']); |
493 | | - |
494 | | - $termCount = $page->searchTerms()->count(); |
495 | | - |
496 | | - // Expect at least 90% unique rate |
497 | | - $this->assertGreaterThan($count * 0.9, $termCount); |
498 | | - } |
499 | | - |
500 | | - public function test_name_and_content_terms_are_merged_to_single_score() |
501 | | - { |
502 | | - $page = $this->entities->newPage(['name' => 'TermA', 'html' => ' |
503 | | - <p>TermA</p> |
504 | | - ']); |
505 | | - |
506 | | - $scoreByTerm = $page->searchTerms()->pluck('score', 'term'); |
507 | | - |
508 | | - // Scores 40 for being in the name then 1 for being in the content |
509 | | - $this->assertEquals(41, $scoreByTerm->get('TermA')); |
510 | | - } |
511 | | - |
512 | | - public function test_tag_names_and_values_are_indexed_for_search() |
513 | | - { |
514 | | - $page = $this->entities->newPage(['name' => 'PageA', 'html' => '<p>content</p>', 'tags' => [ |
515 | | - ['name' => 'Animal', 'value' => 'MeowieCat'], |
516 | | - ['name' => 'SuperImportant'], |
517 | | - ]]); |
518 | | - |
519 | | - $scoreByTerm = $page->searchTerms()->pluck('score', 'term'); |
520 | | - $this->assertEquals(5, $scoreByTerm->get('MeowieCat')); |
521 | | - $this->assertEquals(3, $scoreByTerm->get('Animal')); |
522 | | - $this->assertEquals(3, $scoreByTerm->get('SuperImportant')); |
523 | | - } |
524 | | - |
525 | 346 | public function test_matching_terms_in_search_results_are_highlighted() |
526 | 347 | { |
527 | 348 | $this->entities->newPage(['name' => 'My Meowie Cat', 'html' => '<p>A superimportant page about meowieable animals</p>', 'tags' => [ |
|
0 commit comments