]> BookStack Code Mirror - bookstack/blobdiff - tests/Search/EntitySearchTest.php
Merge pull request #5917 from BookStackApp/copy_references
[bookstack] / tests / Search / EntitySearchTest.php
index 9c76d0f7136025c716e6965f07271f56504f7bb0..8501b65c43d8bb612e5709df0836d21066dcce1e 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-namespace Search;
+namespace Tests\Search;
 
 use BookStack\Activity\Models\Tag;
 use BookStack\Entities\Models\Book;
@@ -27,6 +27,12 @@ class EntitySearchTest extends TestCase
         $search->assertSeeText($shelf->name, true);
     }
 
+    public function test_search_shows_pagination()
+    {
+        $search = $this->asEditor()->get('/search?term=a');
+        $this->withHtml($search)->assertLinkExists('/search?term=a&page=2', '2');
+    }
+
     public function test_invalid_page_search()
     {
         $resp = $this->asEditor()->get('/search?term=' . urlencode('<p>test</p>'));
@@ -372,6 +378,21 @@ class EntitySearchTest extends TestCase
         $search->assertSee('<strong>На</strong> <strong>мен</strong> <strong>ми</strong> <strong>трябва</strong> <strong>нещо</strong> <strong>добро</strong> test', false);
     }
 
+    public function test_match_highlighting_is_efficient_with_large_frequency_in_content()
+    {
+        $content = str_repeat('superbeans ', 10000);
+        $this->entities->newPage([
+            'name' => 'Test Page',
+            'html' => "<p>{$content}</p>",
+        ]);
+
+        $time = microtime(true);
+        $resp = $this->asEditor()->get('/search?term=' . urlencode('superbeans'));
+        $this->assertLessThan(0.5, microtime(true) - $time);
+
+        $resp->assertSee('<strong>superbeans</strong>', false);
+    }
+
     public function test_html_entities_in_item_details_remains_escaped_in_search_results()
     {
         $this->entities->newPage(['name' => 'My <cool> TestPageContent', 'html' => '<p>My supercool &lt;great&gt; TestPageContent page</p>']);