]> BookStack Code Mirror - bookstack/blobdiff - tests/Entity/EntitySearchTest.php
Add optional OIDC avatar fetching from the “picture” claim
[bookstack] / tests / Entity / EntitySearchTest.php
index bb1021a67915620bddf9c61694c1702ac092c23d..5ace70e3ab2835c7bdebe6a05d2239eec6c762c3 100644 (file)
@@ -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' => '<p>' . $text . '</p>']);
+
+        $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' => '
@@ -573,8 +593,16 @@ class EntitySearchTest extends TestCase
 
     public function test_searches_with_terms_without_controls_includes_them_in_extras()
     {
-        $resp = $this->asEditor()->get('/search?term=' . urlencode('test {updated_by:dan} {created_by:dan} -{viewed_by_me} -[a=b] -"dog"'));
-        $this->withHtml($resp)->assertFieldHasValue('extras', '{updated_by:dan} {created_by:dan} -"dog" -[a=b] -{viewed_by_me}');
+        $resp = $this->asEditor()->get('/search?term=' . urlencode('test {updated_by:dan} {created_by:dan} -{viewed_by_me} -[a=b] -"dog" {is_template} {sort_by:last_commented}'));
+        $this->withHtml($resp)->assertFieldHasValue('extras', '{updated_by:dan} {created_by:dan} {is_template} {sort_by:last_commented} -"dog" -[a=b] -{viewed_by_me}');
+    }
+
+    public function test_negated_searches_dont_show_in_inputs()
+    {
+        $resp = $this->asEditor()->get('/search?term=' . urlencode('-{created_by:me} -[a=b] -"dog"'));
+        $this->withHtml($resp)->assertElementNotExists('input[name="tags[]"][value="a=b"]');
+        $this->withHtml($resp)->assertElementNotExists('input[name="exact[]"][value="dog"]');
+        $this->withHtml($resp)->assertElementNotExists('input[name="filters[created_by]"][value="me"][checked="checked"]');
     }
 
     public function test_searches_with_user_filters_using_me_adds_them_into_advanced_search_form()