2021-06-26 23:23:15 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Tests\Entity;
|
2016-02-21 20:53:58 +08:00
|
|
|
|
|
2023-05-18 00:56:55 +08:00
|
|
|
|
use BookStack\Activity\Models\Tag;
|
2020-11-22 08:17:45 +08:00
|
|
|
|
use BookStack\Entities\Models\Book;
|
|
|
|
|
use BookStack\Entities\Models\Bookshelf;
|
2023-06-10 22:08:07 +08:00
|
|
|
|
use BookStack\Entities\Models\Chapter;
|
2024-12-11 23:53:57 +08:00
|
|
|
|
use Illuminate\Support\Str;
|
2020-04-04 08:16:05 +08:00
|
|
|
|
use Tests\TestCase;
|
2017-07-27 23:10:58 +08:00
|
|
|
|
|
2017-04-16 17:47:44 +08:00
|
|
|
|
class EntitySearchTest extends TestCase
|
2016-02-21 20:53:58 +08:00
|
|
|
|
{
|
|
|
|
|
public function test_page_search()
|
|
|
|
|
{
|
2022-09-30 05:11:16 +08:00
|
|
|
|
$book = $this->entities->book();
|
2016-02-21 20:53:58 +08:00
|
|
|
|
$page = $book->pages->first();
|
|
|
|
|
|
2017-04-16 17:47:44 +08:00
|
|
|
|
$search = $this->asEditor()->get('/search?term=' . urlencode($page->name));
|
|
|
|
|
$search->assertSee('Search Results');
|
2021-11-13 22:51:59 +08:00
|
|
|
|
$search->assertSeeText($page->name, true);
|
2016-02-21 20:53:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-23 19:34:30 +08:00
|
|
|
|
public function test_bookshelf_search()
|
|
|
|
|
{
|
2022-09-30 00:31:38 +08:00
|
|
|
|
$shelf = $this->entities->shelf();
|
2021-11-13 21:43:41 +08:00
|
|
|
|
|
2021-11-13 22:51:59 +08:00
|
|
|
|
$search = $this->asEditor()->get('/search?term=' . urlencode($shelf->name) . ' {type:bookshelf}');
|
|
|
|
|
$search->assertSee('Search Results');
|
|
|
|
|
$search->assertSeeText($shelf->name, true);
|
2018-09-23 19:34:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-21 20:53:58 +08:00
|
|
|
|
public function test_invalid_page_search()
|
|
|
|
|
{
|
2017-04-16 17:47:44 +08:00
|
|
|
|
$resp = $this->asEditor()->get('/search?term=' . urlencode('<p>test</p>'));
|
|
|
|
|
$resp->assertSee('Search Results');
|
|
|
|
|
$resp->assertStatus(200);
|
|
|
|
|
$this->get('/search?term=cat+-')->assertStatus(200);
|
2016-02-21 20:53:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-16 17:47:44 +08:00
|
|
|
|
public function test_empty_search_shows_search_page()
|
2016-02-21 20:53:58 +08:00
|
|
|
|
{
|
2017-04-16 17:47:44 +08:00
|
|
|
|
$res = $this->asEditor()->get('/search');
|
|
|
|
|
$res->assertStatus(200);
|
2016-02-21 20:53:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-16 17:47:44 +08:00
|
|
|
|
public function test_searching_accents_and_small_terms()
|
2016-02-21 20:53:58 +08:00
|
|
|
|
{
|
2022-09-29 23:49:25 +08:00
|
|
|
|
$page = $this->entities->newPage(['name' => 'My new test quaffleachits', 'html' => 'some áéííúü¿¡ test content a2 orange dog']);
|
2017-04-16 17:47:44 +08:00
|
|
|
|
$this->asEditor();
|
2016-02-21 20:53:58 +08:00
|
|
|
|
|
2017-04-16 17:47:44 +08:00
|
|
|
|
$accentSearch = $this->get('/search?term=' . urlencode('áéíí'));
|
|
|
|
|
$accentSearch->assertStatus(200)->assertSee($page->name);
|
2016-02-21 20:53:58 +08:00
|
|
|
|
|
2017-10-16 02:24:06 +08:00
|
|
|
|
$smallSearch = $this->get('/search?term=' . urlencode('a2'));
|
2017-04-16 17:47:44 +08:00
|
|
|
|
$smallSearch->assertStatus(200)->assertSee($page->name);
|
2016-02-21 20:53:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-16 17:47:44 +08:00
|
|
|
|
public function test_book_search()
|
2016-02-21 20:53:58 +08:00
|
|
|
|
{
|
2020-02-16 03:09:33 +08:00
|
|
|
|
$book = Book::first();
|
2017-04-16 17:47:44 +08:00
|
|
|
|
$page = $book->pages->last();
|
|
|
|
|
$chapter = $book->chapters->last();
|
2016-02-21 20:53:58 +08:00
|
|
|
|
|
2017-04-16 17:47:44 +08:00
|
|
|
|
$pageTestResp = $this->asEditor()->get('/search/book/' . $book->id . '?term=' . urlencode($page->name));
|
|
|
|
|
$pageTestResp->assertSee($page->name);
|
2016-02-21 20:53:58 +08:00
|
|
|
|
|
2017-04-16 17:47:44 +08:00
|
|
|
|
$chapterTestResp = $this->asEditor()->get('/search/book/' . $book->id . '?term=' . urlencode($chapter->name));
|
|
|
|
|
$chapterTestResp->assertSee($chapter->name);
|
2016-08-26 00:17:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-16 17:47:44 +08:00
|
|
|
|
public function test_chapter_search()
|
2016-02-21 20:53:58 +08:00
|
|
|
|
{
|
2022-09-30 05:11:16 +08:00
|
|
|
|
$chapter = $this->entities->chapterHasPages();
|
2017-04-16 17:47:44 +08:00
|
|
|
|
$page = $chapter->pages[0];
|
2016-06-12 19:48:06 +08:00
|
|
|
|
|
2017-04-16 17:47:44 +08:00
|
|
|
|
$pageTestResp = $this->asEditor()->get('/search/chapter/' . $chapter->id . '?term=' . urlencode($page->name));
|
|
|
|
|
$pageTestResp->assertSee($page->name);
|
2016-10-30 20:15:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-12 21:21:16 +08:00
|
|
|
|
public function test_tag_search()
|
|
|
|
|
{
|
|
|
|
|
$newTags = [
|
2020-02-16 03:09:33 +08:00
|
|
|
|
new Tag([
|
2021-06-26 23:23:15 +08:00
|
|
|
|
'name' => 'animal',
|
|
|
|
|
'value' => 'cat',
|
2016-11-12 21:21:16 +08:00
|
|
|
|
]),
|
2020-02-16 03:09:33 +08:00
|
|
|
|
new Tag([
|
2021-06-26 23:23:15 +08:00
|
|
|
|
'name' => 'color',
|
|
|
|
|
'value' => 'red',
|
|
|
|
|
]),
|
2016-11-12 21:21:16 +08:00
|
|
|
|
];
|
|
|
|
|
|
2022-09-30 05:11:16 +08:00
|
|
|
|
$pageA = $this->entities->page();
|
2016-11-12 21:21:16 +08:00
|
|
|
|
$pageA->tags()->saveMany($newTags);
|
|
|
|
|
|
2022-09-30 05:11:16 +08:00
|
|
|
|
$pageB = $this->entities->page();
|
2016-11-12 21:21:16 +08:00
|
|
|
|
$pageB->tags()->create(['name' => 'animal', 'value' => 'dog']);
|
|
|
|
|
|
2017-04-16 17:47:44 +08:00
|
|
|
|
$this->asEditor();
|
|
|
|
|
$tNameSearch = $this->get('/search?term=%5Banimal%5D');
|
|
|
|
|
$tNameSearch->assertSee($pageA->name)->assertSee($pageB->name);
|
2016-11-12 21:21:16 +08:00
|
|
|
|
|
2017-04-16 17:47:44 +08:00
|
|
|
|
$tNameSearch2 = $this->get('/search?term=%5Bcolor%5D');
|
|
|
|
|
$tNameSearch2->assertSee($pageA->name)->assertDontSee($pageB->name);
|
|
|
|
|
|
|
|
|
|
$tNameValSearch = $this->get('/search?term=%5Banimal%3Dcat%5D');
|
|
|
|
|
$tNameValSearch->assertSee($pageA->name)->assertDontSee($pageB->name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_exact_searches()
|
|
|
|
|
{
|
2022-09-29 23:49:25 +08:00
|
|
|
|
$page = $this->entities->newPage(['name' => 'My new test page', 'html' => 'this is a story about an orange donkey']);
|
2016-11-12 21:21:16 +08:00
|
|
|
|
|
2017-04-16 17:47:44 +08:00
|
|
|
|
$exactSearchA = $this->asEditor()->get('/search?term=' . urlencode('"story about an orange"'));
|
|
|
|
|
$exactSearchA->assertStatus(200)->assertSee($page->name);
|
2016-11-12 21:21:16 +08:00
|
|
|
|
|
2017-04-16 17:47:44 +08:00
|
|
|
|
$exactSearchB = $this->asEditor()->get('/search?term=' . urlencode('"story not about an orange"'));
|
|
|
|
|
$exactSearchB->assertStatus(200)->assertDontSee($page->name);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-04 02:27:03 +08:00
|
|
|
|
public function test_negated_searches()
|
|
|
|
|
{
|
|
|
|
|
$page = $this->entities->newPage(['name' => 'My new test negation page', 'html' => '<p>An angry tortoise wore trumpeted plimsoles</p>']);
|
|
|
|
|
$page->tags()->saveMany([new Tag(['name' => 'DonkCount', 'value' => '500'])]);
|
|
|
|
|
$page->created_by = $this->users->admin()->id;
|
|
|
|
|
$page->save();
|
|
|
|
|
|
|
|
|
|
$editor = $this->users->editor();
|
|
|
|
|
$this->actingAs($editor);
|
|
|
|
|
|
|
|
|
|
$exactSearch = $this->get('/search?term=' . urlencode('negation -"tortoise"'));
|
|
|
|
|
$exactSearch->assertStatus(200)->assertDontSeeText($page->name);
|
|
|
|
|
|
|
|
|
|
$tagSearchA = $this->get('/search?term=' . urlencode('negation [DonkCount=500]'));
|
|
|
|
|
$tagSearchA->assertStatus(200)->assertSeeText($page->name);
|
|
|
|
|
$tagSearchB = $this->get('/search?term=' . urlencode('negation -[DonkCount=500]'));
|
|
|
|
|
$tagSearchB->assertStatus(200)->assertDontSeeText($page->name);
|
|
|
|
|
|
|
|
|
|
$filterSearchA = $this->get('/search?term=' . urlencode('negation -{created_by:me}'));
|
|
|
|
|
$filterSearchA->assertStatus(200)->assertSeeText($page->name);
|
|
|
|
|
$page->created_by = $editor->id;
|
|
|
|
|
$page->save();
|
|
|
|
|
$filterSearchB = $this->get('/search?term=' . urlencode('negation -{created_by:me}'));
|
|
|
|
|
$filterSearchB->assertStatus(200)->assertDontSeeText($page->name);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-13 02:03:44 +08:00
|
|
|
|
public function test_search_terms_with_delimiters_are_converted_to_exact_matches()
|
|
|
|
|
{
|
|
|
|
|
$this->asEditor();
|
2022-09-29 23:49:25 +08:00
|
|
|
|
$page = $this->entities->newPage(['name' => 'Delimiter test', 'html' => '<p>1.1 2,2 3?3 4:4 5;5 (8) <9> "10" \'11\' `12`</p>']);
|
2021-11-13 02:03:44 +08:00
|
|
|
|
$terms = explode(' ', '1.1 2,2 3?3 4:4 5;5 (8) <9> "10" \'11\' `12`');
|
|
|
|
|
|
|
|
|
|
foreach ($terms as $term) {
|
|
|
|
|
$search = $this->get('/search?term=' . urlencode($term));
|
|
|
|
|
$search->assertSee($page->name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-16 17:47:44 +08:00
|
|
|
|
public function test_search_filters()
|
|
|
|
|
{
|
2022-09-29 23:49:25 +08:00
|
|
|
|
$page = $this->entities->newPage(['name' => 'My new test quaffleachits', 'html' => 'this is about an orange donkey danzorbhsing']);
|
2023-01-21 19:08:34 +08:00
|
|
|
|
$editor = $this->users->editor();
|
2022-10-12 19:12:36 +08:00
|
|
|
|
$this->actingAs($editor);
|
2017-04-16 17:47:44 +08:00
|
|
|
|
|
|
|
|
|
// Viewed filter searches
|
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {not_viewed_by_me}'))->assertSee($page->name);
|
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {viewed_by_me}'))->assertDontSee($page->name);
|
|
|
|
|
$this->get($page->getUrl());
|
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {not_viewed_by_me}'))->assertDontSee($page->name);
|
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {viewed_by_me}'))->assertSee($page->name);
|
|
|
|
|
|
|
|
|
|
// User filters
|
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {created_by:me}'))->assertDontSee($page->name);
|
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {updated_by:me}'))->assertDontSee($page->name);
|
2021-02-14 18:40:02 +08:00
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {owned_by:me}'))->assertDontSee($page->name);
|
2022-10-12 19:12:36 +08:00
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {updated_by:' . $editor->slug . '}'))->assertDontSee($page->name);
|
|
|
|
|
$page->created_by = $editor->id;
|
2017-04-16 17:47:44 +08:00
|
|
|
|
$page->save();
|
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {created_by:me}'))->assertSee($page->name);
|
2022-10-12 19:12:36 +08:00
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {created_by: ' . $editor->slug . '}'))->assertSee($page->name);
|
2017-04-16 17:47:44 +08:00
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {updated_by:me}'))->assertDontSee($page->name);
|
2021-02-14 18:40:02 +08:00
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {owned_by:me}'))->assertDontSee($page->name);
|
2022-10-12 19:12:36 +08:00
|
|
|
|
$page->updated_by = $editor->id;
|
2017-04-16 17:47:44 +08:00
|
|
|
|
$page->save();
|
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {updated_by:me}'))->assertSee($page->name);
|
2022-10-12 19:12:36 +08:00
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {updated_by:' . $editor->slug . '}'))->assertSee($page->name);
|
2021-02-14 18:40:02 +08:00
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {owned_by:me}'))->assertDontSee($page->name);
|
2022-10-12 19:12:36 +08:00
|
|
|
|
$page->owned_by = $editor->id;
|
2021-02-14 18:40:02 +08:00
|
|
|
|
$page->save();
|
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {owned_by:me}'))->assertSee($page->name);
|
2022-10-12 19:12:36 +08:00
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {owned_by:' . $editor->slug . '}'))->assertSee($page->name);
|
2017-04-16 17:47:44 +08:00
|
|
|
|
|
|
|
|
|
// Content filters
|
|
|
|
|
$this->get('/search?term=' . urlencode('{in_name:danzorbhsing}'))->assertDontSee($page->name);
|
|
|
|
|
$this->get('/search?term=' . urlencode('{in_body:danzorbhsing}'))->assertSee($page->name);
|
|
|
|
|
$this->get('/search?term=' . urlencode('{in_name:test quaffleachits}'))->assertSee($page->name);
|
|
|
|
|
$this->get('/search?term=' . urlencode('{in_body:test quaffleachits}'))->assertDontSee($page->name);
|
|
|
|
|
|
|
|
|
|
// Restricted filter
|
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {is_restricted}'))->assertDontSee($page->name);
|
2023-01-21 19:08:34 +08:00
|
|
|
|
$this->permissions->setEntityPermissions($page, ['view'], [$editor->roles->first()]);
|
2017-04-16 17:47:44 +08:00
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {is_restricted}'))->assertSee($page->name);
|
|
|
|
|
|
|
|
|
|
// Date filters
|
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {updated_after:2037-01-01}'))->assertDontSee($page->name);
|
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {updated_before:2037-01-01}'))->assertSee($page->name);
|
|
|
|
|
$page->updated_at = '2037-02-01';
|
|
|
|
|
$page->save();
|
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {updated_after:2037-01-01}'))->assertSee($page->name);
|
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {updated_before:2037-01-01}'))->assertDontSee($page->name);
|
|
|
|
|
|
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {created_after:2037-01-01}'))->assertDontSee($page->name);
|
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {created_before:2037-01-01}'))->assertSee($page->name);
|
|
|
|
|
$page->created_at = '2037-02-01';
|
|
|
|
|
$page->save();
|
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {created_after:2037-01-01}'))->assertSee($page->name);
|
|
|
|
|
$this->get('/search?term=' . urlencode('danzorbhsing {created_before:2037-01-01}'))->assertDontSee($page->name);
|
2016-11-12 21:21:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-21 18:29:12 +08:00
|
|
|
|
public function test_entity_selector_search()
|
2016-06-12 19:48:06 +08:00
|
|
|
|
{
|
2022-09-29 23:49:25 +08:00
|
|
|
|
$page = $this->entities->newPage(['name' => 'my ajax search test', 'html' => 'ajax test']);
|
2022-09-30 05:11:16 +08:00
|
|
|
|
$notVisitedPage = $this->entities->page();
|
2017-04-16 17:47:44 +08:00
|
|
|
|
|
|
|
|
|
// Visit the page to make popular
|
|
|
|
|
$this->asEditor()->get($page->getUrl());
|
|
|
|
|
|
2022-11-21 18:29:12 +08:00
|
|
|
|
$normalSearch = $this->get('/search/entity-selector?term=' . urlencode($page->name));
|
2017-04-16 17:47:44 +08:00
|
|
|
|
$normalSearch->assertSee($page->name);
|
|
|
|
|
|
2022-11-21 18:29:12 +08:00
|
|
|
|
$bookSearch = $this->get('/search/entity-selector?types=book&term=' . urlencode($page->name));
|
2017-04-16 17:47:44 +08:00
|
|
|
|
$bookSearch->assertDontSee($page->name);
|
|
|
|
|
|
2022-11-21 18:29:12 +08:00
|
|
|
|
$defaultListTest = $this->get('/search/entity-selector');
|
2017-04-16 17:47:44 +08:00
|
|
|
|
$defaultListTest->assertSee($page->name);
|
|
|
|
|
$defaultListTest->assertDontSee($notVisitedPage->name);
|
2016-06-12 19:48:06 +08:00
|
|
|
|
}
|
2017-07-27 23:10:58 +08:00
|
|
|
|
|
2022-11-21 18:29:12 +08:00
|
|
|
|
public function test_entity_selector_search_shows_breadcrumbs()
|
2017-07-27 23:10:58 +08:00
|
|
|
|
{
|
2022-09-30 05:11:16 +08:00
|
|
|
|
$chapter = $this->entities->chapter();
|
2017-07-27 23:10:58 +08:00
|
|
|
|
$page = $chapter->pages->first();
|
|
|
|
|
$this->asEditor();
|
|
|
|
|
|
2022-11-21 18:29:12 +08:00
|
|
|
|
$pageSearch = $this->get('/search/entity-selector?term=' . urlencode($page->name));
|
2017-07-27 23:10:58 +08:00
|
|
|
|
$pageSearch->assertSee($page->name);
|
2019-04-07 01:36:17 +08:00
|
|
|
|
$pageSearch->assertSee($chapter->getShortName(42));
|
|
|
|
|
$pageSearch->assertSee($page->book->getShortName(42));
|
2017-07-27 23:10:58 +08:00
|
|
|
|
|
2022-11-21 18:29:12 +08:00
|
|
|
|
$chapterSearch = $this->get('/search/entity-selector?term=' . urlencode($chapter->name));
|
2017-07-27 23:10:58 +08:00
|
|
|
|
$chapterSearch->assertSee($chapter->name);
|
2019-04-07 01:36:17 +08:00
|
|
|
|
$chapterSearch->assertSee($chapter->book->getShortName(42));
|
2017-07-27 23:10:58 +08:00
|
|
|
|
}
|
2020-02-16 03:09:33 +08:00
|
|
|
|
|
2023-06-10 22:08:07 +08:00
|
|
|
|
public function test_entity_selector_shows_breadcrumbs_on_default_view()
|
|
|
|
|
{
|
|
|
|
|
$page = $this->entities->pageWithinChapter();
|
|
|
|
|
$this->asEditor()->get($page->chapter->getUrl());
|
|
|
|
|
|
|
|
|
|
$resp = $this->asEditor()->get('/search/entity-selector?types=book,chapter&permission=page-create');
|
|
|
|
|
$html = $this->withHtml($resp);
|
|
|
|
|
$html->assertElementContains('.chapter.entity-list-item', $page->chapter->name);
|
|
|
|
|
$html->assertElementContains('.chapter.entity-list-item .entity-item-snippet', $page->book->getShortName(42));
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-21 18:29:12 +08:00
|
|
|
|
public function test_entity_selector_search_reflects_items_without_permission()
|
2022-07-17 17:18:24 +08:00
|
|
|
|
{
|
2022-09-30 00:31:38 +08:00
|
|
|
|
$page = $this->entities->page();
|
2022-07-17 17:18:24 +08:00
|
|
|
|
$baseSelector = 'a[data-entity-type="page"][data-entity-id="' . $page->id . '"]';
|
2022-11-21 18:29:12 +08:00
|
|
|
|
$searchUrl = '/search/entity-selector?permission=update&term=' . urlencode($page->name);
|
2022-07-17 17:18:24 +08:00
|
|
|
|
|
|
|
|
|
$resp = $this->asEditor()->get($searchUrl);
|
2022-07-23 22:10:18 +08:00
|
|
|
|
$this->withHtml($resp)->assertElementContains($baseSelector, $page->name);
|
|
|
|
|
$this->withHtml($resp)->assertElementNotContains($baseSelector, "You don't have the required permissions to select this item");
|
2022-07-17 17:18:24 +08:00
|
|
|
|
|
2023-01-21 19:08:34 +08:00
|
|
|
|
$resp = $this->actingAs($this->users->viewer())->get($searchUrl);
|
2022-07-23 22:10:18 +08:00
|
|
|
|
$this->withHtml($resp)->assertElementContains($baseSelector, $page->name);
|
|
|
|
|
$this->withHtml($resp)->assertElementContains($baseSelector, "You don't have the required permissions to select this item");
|
2022-07-17 17:18:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-12 23:38:09 +08:00
|
|
|
|
public function test_entity_template_selector_search()
|
|
|
|
|
{
|
|
|
|
|
$templatePage = $this->entities->newPage(['name' => 'Template search test', 'html' => 'template test']);
|
|
|
|
|
$templatePage->template = true;
|
|
|
|
|
$templatePage->save();
|
|
|
|
|
|
|
|
|
|
$nonTemplatePage = $this->entities->newPage(['name' => 'Nontemplate page', 'html' => 'nontemplate', 'template' => false]);
|
|
|
|
|
|
|
|
|
|
// Visit both to make popular
|
|
|
|
|
$this->asEditor()->get($templatePage->getUrl());
|
2023-12-12 23:41:56 +08:00
|
|
|
|
$this->get($nonTemplatePage->getUrl());
|
2023-12-12 23:38:09 +08:00
|
|
|
|
|
|
|
|
|
$normalSearch = $this->get('/search/entity-selector-templates?term=test');
|
|
|
|
|
$normalSearch->assertSee($templatePage->name);
|
|
|
|
|
$normalSearch->assertDontSee($nonTemplatePage->name);
|
|
|
|
|
|
|
|
|
|
$normalSearch = $this->get('/search/entity-selector-templates?term=beans');
|
|
|
|
|
$normalSearch->assertDontSee($templatePage->name);
|
|
|
|
|
$normalSearch->assertDontSee($nonTemplatePage->name);
|
|
|
|
|
|
|
|
|
|
$defaultListTest = $this->get('/search/entity-selector-templates');
|
|
|
|
|
$defaultListTest->assertSee($templatePage->name);
|
|
|
|
|
$defaultListTest->assertDontSee($nonTemplatePage->name);
|
2023-12-12 23:41:56 +08:00
|
|
|
|
|
|
|
|
|
$this->permissions->disableEntityInheritedPermissions($templatePage);
|
|
|
|
|
|
|
|
|
|
$normalSearch = $this->get('/search/entity-selector-templates?term=test');
|
|
|
|
|
$normalSearch->assertDontSee($templatePage->name);
|
|
|
|
|
|
|
|
|
|
$defaultListTest = $this->get('/search/entity-selector-templates');
|
|
|
|
|
$defaultListTest->assertDontSee($templatePage->name);
|
2023-12-12 23:38:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-16 03:09:33 +08:00
|
|
|
|
public function test_sibling_search_for_pages()
|
|
|
|
|
{
|
2022-09-30 05:11:16 +08:00
|
|
|
|
$chapter = $this->entities->chapterHasPages();
|
2020-02-16 03:09:33 +08:00
|
|
|
|
$this->assertGreaterThan(2, count($chapter->pages), 'Ensure we\'re testing with at least 1 sibling');
|
|
|
|
|
$page = $chapter->pages->first();
|
|
|
|
|
|
2023-01-21 19:08:34 +08:00
|
|
|
|
$search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$page->id}&entity_type=page");
|
2020-02-16 03:09:33 +08:00
|
|
|
|
$search->assertSuccessful();
|
|
|
|
|
foreach ($chapter->pages as $page) {
|
|
|
|
|
$search->assertSee($page->name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$search->assertDontSee($chapter->name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_sibling_search_for_pages_without_chapter()
|
|
|
|
|
{
|
2022-09-30 05:11:16 +08:00
|
|
|
|
$page = $this->entities->pageNotWithinChapter();
|
2024-02-08 00:37:36 +08:00
|
|
|
|
$bookChildren = $page->book->getDirectVisibleChildren();
|
2020-02-16 03:09:33 +08:00
|
|
|
|
$this->assertGreaterThan(2, count($bookChildren), 'Ensure we\'re testing with at least 1 sibling');
|
|
|
|
|
|
2023-01-21 19:08:34 +08:00
|
|
|
|
$search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$page->id}&entity_type=page");
|
2020-02-16 03:09:33 +08:00
|
|
|
|
$search->assertSuccessful();
|
|
|
|
|
foreach ($bookChildren as $child) {
|
|
|
|
|
$search->assertSee($child->name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$search->assertDontSee($page->book->name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_sibling_search_for_chapters()
|
|
|
|
|
{
|
2022-09-30 05:11:16 +08:00
|
|
|
|
$chapter = $this->entities->chapter();
|
2024-02-08 00:37:36 +08:00
|
|
|
|
$bookChildren = $chapter->book->getDirectVisibleChildren();
|
2020-02-16 03:09:33 +08:00
|
|
|
|
$this->assertGreaterThan(2, count($bookChildren), 'Ensure we\'re testing with at least 1 sibling');
|
|
|
|
|
|
2023-01-21 19:08:34 +08:00
|
|
|
|
$search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$chapter->id}&entity_type=chapter");
|
2020-02-16 03:09:33 +08:00
|
|
|
|
$search->assertSuccessful();
|
|
|
|
|
foreach ($bookChildren as $child) {
|
|
|
|
|
$search->assertSee($child->name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$search->assertDontSee($chapter->book->name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_sibling_search_for_books()
|
|
|
|
|
{
|
|
|
|
|
$books = Book::query()->take(10)->get();
|
|
|
|
|
$book = $books->first();
|
|
|
|
|
$this->assertGreaterThan(2, count($books), 'Ensure we\'re testing with at least 1 sibling');
|
|
|
|
|
|
2023-01-21 19:08:34 +08:00
|
|
|
|
$search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$book->id}&entity_type=book");
|
2020-02-16 03:09:33 +08:00
|
|
|
|
$search->assertSuccessful();
|
|
|
|
|
foreach ($books as $expectedBook) {
|
|
|
|
|
$search->assertSee($expectedBook->name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_sibling_search_for_shelves()
|
|
|
|
|
{
|
|
|
|
|
$shelves = Bookshelf::query()->take(10)->get();
|
|
|
|
|
$shelf = $shelves->first();
|
|
|
|
|
$this->assertGreaterThan(2, count($shelves), 'Ensure we\'re testing with at least 1 sibling');
|
|
|
|
|
|
2023-01-21 19:08:34 +08:00
|
|
|
|
$search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$shelf->id}&entity_type=bookshelf");
|
2020-02-16 03:09:33 +08:00
|
|
|
|
$search->assertSuccessful();
|
|
|
|
|
foreach ($shelves as $expectedShelf) {
|
|
|
|
|
$search->assertSee($expectedShelf->name);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-23 07:46:13 +08:00
|
|
|
|
|
2024-03-09 23:24:44 +08:00
|
|
|
|
public function test_sibling_search_for_books_provides_results_in_alphabetical_order()
|
|
|
|
|
{
|
|
|
|
|
$contextBook = $this->entities->book();
|
|
|
|
|
$searchBook = $this->entities->book();
|
|
|
|
|
|
|
|
|
|
$searchBook->name = 'Zebras';
|
|
|
|
|
$searchBook->save();
|
|
|
|
|
|
|
|
|
|
$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');
|
|
|
|
|
|
2024-11-08 19:35:18 +08:00
|
|
|
|
$searchBook->name = '1AAAAAAArdvarks';
|
2024-03-09 23:24:44 +08:00
|
|
|
|
$searchBook->save();
|
|
|
|
|
|
|
|
|
|
$search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$contextBook->id}&entity_type=book");
|
2024-11-08 19:35:18 +08:00
|
|
|
|
$this->withHtml($search)->assertElementContains('a:first-child', '1AAAAAAArdvarks');
|
2024-03-09 23:24:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_sibling_search_for_shelves_provides_results_in_alphabetical_order()
|
|
|
|
|
{
|
|
|
|
|
$contextShelf = $this->entities->shelf();
|
|
|
|
|
$searchShelf = $this->entities->shelf();
|
|
|
|
|
|
|
|
|
|
$searchShelf->name = 'Zebras';
|
|
|
|
|
$searchShelf->save();
|
|
|
|
|
|
|
|
|
|
$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');
|
|
|
|
|
|
2024-11-08 19:35:18 +08:00
|
|
|
|
$searchShelf->name = '1AAAAAAArdvarks';
|
2024-03-09 23:24:44 +08:00
|
|
|
|
$searchShelf->save();
|
|
|
|
|
|
|
|
|
|
$search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$contextShelf->id}&entity_type=bookshelf");
|
2024-11-08 19:35:18 +08:00
|
|
|
|
$this->withHtml($search)->assertElementContains('a:first-child', '1AAAAAAArdvarks');
|
2024-03-09 23:24:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-23 07:46:13 +08:00
|
|
|
|
public function test_search_works_on_updated_page_content()
|
|
|
|
|
{
|
2022-09-30 00:31:38 +08:00
|
|
|
|
$page = $this->entities->page();
|
2020-05-23 07:46:13 +08:00
|
|
|
|
$this->asEditor();
|
|
|
|
|
|
|
|
|
|
$update = $this->put($page->getUrl(), [
|
|
|
|
|
'name' => $page->name,
|
|
|
|
|
'html' => '<p>dog pandabearmonster spaghetti</p>',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$search = $this->asEditor()->get('/search?term=pandabearmonster');
|
|
|
|
|
$search->assertStatus(200);
|
|
|
|
|
$search->assertSeeText($page->name);
|
|
|
|
|
$search->assertSee($page->getUrl());
|
|
|
|
|
}
|
2021-11-09 23:05:02 +08:00
|
|
|
|
|
|
|
|
|
public function test_search_ranks_common_words_lower()
|
|
|
|
|
{
|
2022-09-29 23:49:25 +08:00
|
|
|
|
$this->entities->newPage(['name' => 'Test page A', 'html' => '<p>dog biscuit dog dog</p>']);
|
|
|
|
|
$this->entities->newPage(['name' => 'Test page B', 'html' => '<p>cat biscuit</p>']);
|
2021-11-09 23:05:02 +08:00
|
|
|
|
|
|
|
|
|
$search = $this->asEditor()->get('/search?term=cat+dog+biscuit');
|
2022-07-23 22:10:18 +08:00
|
|
|
|
$this->withHtml($search)->assertElementContains('.entity-list > .page:nth-child(1)', 'Test page A');
|
|
|
|
|
$this->withHtml($search)->assertElementContains('.entity-list > .page:nth-child(2)', 'Test page B');
|
2021-11-09 23:05:02 +08:00
|
|
|
|
|
|
|
|
|
for ($i = 0; $i < 2; $i++) {
|
2022-09-29 23:49:25 +08:00
|
|
|
|
$this->entities->newPage(['name' => 'Test page ' . $i, 'html' => '<p>dog</p>']);
|
2021-11-09 23:05:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$search = $this->asEditor()->get('/search?term=cat+dog+biscuit');
|
2022-07-23 22:10:18 +08:00
|
|
|
|
$this->withHtml($search)->assertElementContains('.entity-list > .page:nth-child(1)', 'Test page B');
|
|
|
|
|
$this->withHtml($search)->assertElementContains('.entity-list > .page:nth-child(2)', 'Test page A');
|
2021-11-09 23:05:02 +08:00
|
|
|
|
}
|
2021-11-12 21:47:23 +08:00
|
|
|
|
|
|
|
|
|
public function test_terms_in_headers_have_an_adjusted_index_score()
|
|
|
|
|
{
|
2022-09-29 23:49:25 +08:00
|
|
|
|
$page = $this->entities->newPage(['name' => 'Test page A', 'html' => '
|
2021-11-12 21:47:23 +08:00
|
|
|
|
<p>TermA</p>
|
|
|
|
|
<h1>TermB <strong>TermNested</strong></h1>
|
|
|
|
|
<h2>TermC</h2>
|
|
|
|
|
<h3>TermD</h3>
|
|
|
|
|
<h4>TermE</h4>
|
|
|
|
|
<h5>TermF</h5>
|
|
|
|
|
<h6>TermG</h6>
|
|
|
|
|
']);
|
|
|
|
|
|
2021-11-13 01:06:01 +08:00
|
|
|
|
$scoreByTerm = $page->searchTerms()->pluck('score', 'term');
|
2021-11-12 21:47:23 +08:00
|
|
|
|
|
|
|
|
|
$this->assertEquals(1, $scoreByTerm->get('TermA'));
|
|
|
|
|
$this->assertEquals(10, $scoreByTerm->get('TermB'));
|
|
|
|
|
$this->assertEquals(10, $scoreByTerm->get('TermNested'));
|
|
|
|
|
$this->assertEquals(5, $scoreByTerm->get('TermC'));
|
|
|
|
|
$this->assertEquals(4, $scoreByTerm->get('TermD'));
|
|
|
|
|
$this->assertEquals(3, $scoreByTerm->get('TermE'));
|
|
|
|
|
$this->assertEquals(2, $scoreByTerm->get('TermF'));
|
|
|
|
|
// Is 1.5 but stored as integer, rounding up
|
|
|
|
|
$this->assertEquals(2, $scoreByTerm->get('TermG'));
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-11 23:53:57 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-12 21:47:23 +08:00
|
|
|
|
public function test_name_and_content_terms_are_merged_to_single_score()
|
|
|
|
|
{
|
2022-09-29 23:49:25 +08:00
|
|
|
|
$page = $this->entities->newPage(['name' => 'TermA', 'html' => '
|
2021-11-12 21:47:23 +08:00
|
|
|
|
<p>TermA</p>
|
|
|
|
|
']);
|
|
|
|
|
|
2021-11-13 01:06:01 +08:00
|
|
|
|
$scoreByTerm = $page->searchTerms()->pluck('score', 'term');
|
2021-11-12 21:47:23 +08:00
|
|
|
|
|
|
|
|
|
// Scores 40 for being in the name then 1 for being in the content
|
|
|
|
|
$this->assertEquals(41, $scoreByTerm->get('TermA'));
|
|
|
|
|
}
|
2021-11-13 01:06:01 +08:00
|
|
|
|
|
|
|
|
|
public function test_tag_names_and_values_are_indexed_for_search()
|
|
|
|
|
{
|
2022-09-29 23:49:25 +08:00
|
|
|
|
$page = $this->entities->newPage(['name' => 'PageA', 'html' => '<p>content</p>', 'tags' => [
|
2021-11-13 01:06:01 +08:00
|
|
|
|
['name' => 'Animal', 'value' => 'MeowieCat'],
|
|
|
|
|
['name' => 'SuperImportant'],
|
|
|
|
|
]]);
|
|
|
|
|
|
|
|
|
|
$scoreByTerm = $page->searchTerms()->pluck('score', 'term');
|
|
|
|
|
$this->assertEquals(5, $scoreByTerm->get('MeowieCat'));
|
|
|
|
|
$this->assertEquals(3, $scoreByTerm->get('Animal'));
|
|
|
|
|
$this->assertEquals(3, $scoreByTerm->get('SuperImportant'));
|
|
|
|
|
}
|
2021-11-13 21:26:11 +08:00
|
|
|
|
|
|
|
|
|
public function test_matching_terms_in_search_results_are_highlighted()
|
|
|
|
|
{
|
2022-09-29 23:49:25 +08:00
|
|
|
|
$this->entities->newPage(['name' => 'My Meowie Cat', 'html' => '<p>A superimportant page about meowieable animals</p>', 'tags' => [
|
2021-11-13 21:26:11 +08:00
|
|
|
|
['name' => 'Animal', 'value' => 'MeowieCat'],
|
|
|
|
|
['name' => 'SuperImportant'],
|
|
|
|
|
]]);
|
|
|
|
|
|
|
|
|
|
$search = $this->asEditor()->get('/search?term=SuperImportant+Meowie');
|
|
|
|
|
// Title
|
|
|
|
|
$search->assertSee('My <strong>Meowie</strong> Cat', false);
|
|
|
|
|
// Content
|
|
|
|
|
$search->assertSee('A <strong>superimportant</strong> page about <strong>meowie</strong>able animals', false);
|
|
|
|
|
// Tag name
|
2022-07-23 22:10:18 +08:00
|
|
|
|
$this->withHtml($search)->assertElementContains('.tag-name.highlight', 'SuperImportant');
|
2021-11-13 21:26:11 +08:00
|
|
|
|
// Tag value
|
2022-07-23 22:10:18 +08:00
|
|
|
|
$this->withHtml($search)->assertElementContains('.tag-value.highlight', 'MeowieCat');
|
2021-11-13 21:26:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-18 18:38:33 +08:00
|
|
|
|
public function test_match_highlighting_works_with_multibyte_content()
|
|
|
|
|
{
|
2022-09-29 23:49:25 +08:00
|
|
|
|
$this->entities->newPage([
|
2021-12-18 18:38:33 +08:00
|
|
|
|
'name' => 'Test Page',
|
2021-12-18 19:43:05 +08:00
|
|
|
|
'html' => '<p>На мен ми трябва нещо добро test</p>',
|
2021-12-18 18:38:33 +08:00
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$search = $this->asEditor()->get('/search?term=' . urlencode('На мен ми трябва нещо добро'));
|
|
|
|
|
$search->assertSee('<strong>На</strong> <strong>мен</strong> <strong>ми</strong> <strong>трябва</strong> <strong>нещо</strong> <strong>добро</strong> test', false);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-13 21:26:11 +08:00
|
|
|
|
public function test_html_entities_in_item_details_remains_escaped_in_search_results()
|
|
|
|
|
{
|
2022-09-29 23:49:25 +08:00
|
|
|
|
$this->entities->newPage(['name' => 'My <cool> TestPageContent', 'html' => '<p>My supercool <great> TestPageContent page</p>']);
|
2021-11-13 21:26:11 +08:00
|
|
|
|
|
|
|
|
|
$search = $this->asEditor()->get('/search?term=TestPageContent');
|
|
|
|
|
$search->assertSee('My <cool> <strong>TestPageContent</strong>', false);
|
|
|
|
|
$search->assertSee('My supercool <great> <strong>TestPageContent</strong> page', false);
|
|
|
|
|
}
|
2021-11-14 23:07:13 +08:00
|
|
|
|
|
2022-06-21 06:47:42 +08:00
|
|
|
|
public function test_words_adjacent_to_lines_breaks_can_be_matched_with_normal_terms()
|
|
|
|
|
{
|
2022-09-29 23:49:25 +08:00
|
|
|
|
$page = $this->entities->newPage(['name' => 'TermA', 'html' => '
|
2022-06-21 06:47:42 +08:00
|
|
|
|
<p>TermA<br>TermB<br>TermC</p>
|
|
|
|
|
']);
|
|
|
|
|
|
|
|
|
|
$search = $this->asEditor()->get('/search?term=' . urlencode('TermB TermC'));
|
|
|
|
|
|
|
|
|
|
$search->assertSee($page->getUrl(), false);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-27 23:33:24 +08:00
|
|
|
|
public function test_backslashes_can_be_searched_upon()
|
|
|
|
|
{
|
|
|
|
|
$page = $this->entities->newPage(['name' => 'TermA', 'html' => '
|
|
|
|
|
<p>More info is at the path \\\\cat\\dog\\badger</p>
|
|
|
|
|
']);
|
|
|
|
|
$page->tags()->save(new Tag(['name' => '\\Category', 'value' => '\\animals\\fluffy']));
|
|
|
|
|
|
|
|
|
|
$search = $this->asEditor()->get('/search?term=' . urlencode('\\\\cat\\dog'));
|
|
|
|
|
$search->assertSee($page->getUrl(), false);
|
|
|
|
|
|
2023-09-23 20:41:10 +08:00
|
|
|
|
$search = $this->asEditor()->get('/search?term=' . urlencode('"\\dog\\\\"'));
|
2023-04-27 23:33:24 +08:00
|
|
|
|
$search->assertSee($page->getUrl(), false);
|
|
|
|
|
|
2023-09-23 20:41:10 +08:00
|
|
|
|
$search = $this->asEditor()->get('/search?term=' . urlencode('"\\badger\\\\"'));
|
2023-04-27 23:33:24 +08:00
|
|
|
|
$search->assertDontSee($page->getUrl(), false);
|
|
|
|
|
|
|
|
|
|
$search = $this->asEditor()->get('/search?term=' . urlencode('[\\Categorylike%\\fluffy]'));
|
|
|
|
|
$search->assertSee($page->getUrl(), false);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-03 22:59:50 +08:00
|
|
|
|
public function test_searches_with_terms_without_controls_includes_them_in_extras()
|
2021-11-14 23:07:13 +08:00
|
|
|
|
{
|
2024-10-05 21:47:00 +08:00
|
|
|
|
$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}');
|
2022-10-07 01:25:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-04 02:38:07 +08:00
|
|
|
|
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"]');
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-07 01:25:47 +08:00
|
|
|
|
public function test_searches_with_user_filters_using_me_adds_them_into_advanced_search_form()
|
|
|
|
|
{
|
|
|
|
|
$resp = $this->asEditor()->get('/search?term=' . urlencode('test {updated_by:me} {created_by:me}'));
|
|
|
|
|
$this->withHtml($resp)->assertElementExists('form input[name="filters[updated_by]"][value="me"][checked="checked"]');
|
|
|
|
|
$this->withHtml($resp)->assertElementExists('form input[name="filters[created_by]"][value="me"][checked="checked"]');
|
2021-11-14 23:07:13 +08:00
|
|
|
|
}
|
2022-11-21 18:29:12 +08:00
|
|
|
|
|
|
|
|
|
public function test_search_suggestion_endpoint()
|
|
|
|
|
{
|
|
|
|
|
$this->entities->newPage(['name' => 'My suggestion page', 'html' => '<p>My supercool suggestion page</p>']);
|
|
|
|
|
|
|
|
|
|
// Test specific search
|
|
|
|
|
$resp = $this->asEditor()->get('/search/suggest?term="supercool+suggestion"');
|
|
|
|
|
$resp->assertSee('My suggestion page');
|
|
|
|
|
$resp->assertDontSee('My supercool suggestion page');
|
|
|
|
|
$resp->assertDontSee('No items available');
|
|
|
|
|
$this->withHtml($resp)->assertElementCount('a', 1);
|
|
|
|
|
|
|
|
|
|
// Test search limit
|
|
|
|
|
$resp = $this->asEditor()->get('/search/suggest?term=et');
|
|
|
|
|
$this->withHtml($resp)->assertElementCount('a', 5);
|
|
|
|
|
|
|
|
|
|
// Test empty state
|
|
|
|
|
$resp = $this->asEditor()->get('/search/suggest?term=spaghettisaurusrex');
|
|
|
|
|
$this->withHtml($resp)->assertElementCount('a', 0);
|
|
|
|
|
$resp->assertSee('No items available');
|
|
|
|
|
}
|
2016-02-21 20:53:58 +08:00
|
|
|
|
}
|