mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-08-26 20:22:18 +00:00
Updated testcases for new search system.
Finishes implementation of new search system. Closes #271 Closes #344 Fixes #285 Fixes #269 Closes #64
This commit is contained in:
parent
73844b9eeb
commit
a15b179676
@ -219,6 +219,7 @@ class EntityRepo
|
|||||||
* @param int $count
|
* @param int $count
|
||||||
* @param int $page
|
* @param int $page
|
||||||
* @param bool|callable $additionalQuery
|
* @param bool|callable $additionalQuery
|
||||||
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function getRecentlyCreated($type, $count = 20, $page = 0, $additionalQuery = false)
|
public function getRecentlyCreated($type, $count = 20, $page = 0, $additionalQuery = false)
|
||||||
{
|
{
|
||||||
@ -237,6 +238,7 @@ class EntityRepo
|
|||||||
* @param int $count
|
* @param int $count
|
||||||
* @param int $page
|
* @param int $page
|
||||||
* @param bool|callable $additionalQuery
|
* @param bool|callable $additionalQuery
|
||||||
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function getRecentlyUpdated($type, $count = 20, $page = 0, $additionalQuery = false)
|
public function getRecentlyUpdated($type, $count = 20, $page = 0, $additionalQuery = false)
|
||||||
{
|
{
|
||||||
@ -330,7 +332,7 @@ class EntityRepo
|
|||||||
if ($rawEntity->entity_type === 'BookStack\\Page') {
|
if ($rawEntity->entity_type === 'BookStack\\Page') {
|
||||||
$entities[$index] = $this->page->newFromBuilder($rawEntity);
|
$entities[$index] = $this->page->newFromBuilder($rawEntity);
|
||||||
if ($renderPages) {
|
if ($renderPages) {
|
||||||
$entities[$index]->html = $rawEntity->description;
|
$entities[$index]->html = $rawEntity->html;
|
||||||
$entities[$index]->html = $this->renderPage($entities[$index]);
|
$entities[$index]->html = $this->renderPage($entities[$index]);
|
||||||
};
|
};
|
||||||
} else if ($rawEntity->entity_type === 'BookStack\\Chapter') {
|
} else if ($rawEntity->entity_type === 'BookStack\\Chapter') {
|
||||||
@ -357,6 +359,7 @@ class EntityRepo
|
|||||||
* Get the child items for a chapter sorted by priority but
|
* Get the child items for a chapter sorted by priority but
|
||||||
* with draft items floated to the top.
|
* with draft items floated to the top.
|
||||||
* @param Chapter $chapter
|
* @param Chapter $chapter
|
||||||
|
* @return \Illuminate\Database\Eloquent\Collection|static[]
|
||||||
*/
|
*/
|
||||||
public function getChapterChildren(Chapter $chapter)
|
public function getChapterChildren(Chapter $chapter)
|
||||||
{
|
{
|
||||||
@ -470,7 +473,7 @@ class EntityRepo
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Update entity details from request input.
|
* Update entity details from request input.
|
||||||
* Use for books and chapters
|
* Used for books and chapters
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param Entity $entityModel
|
* @param Entity $entityModel
|
||||||
* @param array $input
|
* @param array $input
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php namespace Tests;
|
<?php namespace Tests;
|
||||||
|
|
||||||
class EntitySearchTest extends BrowserKitTest
|
|
||||||
|
class EntitySearchTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
public function test_page_search()
|
public function test_page_search()
|
||||||
@ -8,32 +9,35 @@ class EntitySearchTest extends BrowserKitTest
|
|||||||
$book = \BookStack\Book::all()->first();
|
$book = \BookStack\Book::all()->first();
|
||||||
$page = $book->pages->first();
|
$page = $book->pages->first();
|
||||||
|
|
||||||
$this->asAdmin()
|
$search = $this->asEditor()->get('/search?term=' . urlencode($page->name));
|
||||||
->visit('/')
|
$search->assertSee('Search Results');
|
||||||
->type($page->name, 'term')
|
$search->assertSee($page->name);
|
||||||
->press('header-search-box-button')
|
|
||||||
->see('Search Results')
|
|
||||||
->seeInElement('.entity-list', $page->name)
|
|
||||||
->clickInElement('.entity-list', $page->name)
|
|
||||||
->seePageIs($page->getUrl());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_invalid_page_search()
|
public function test_invalid_page_search()
|
||||||
{
|
{
|
||||||
$this->asAdmin()
|
$resp = $this->asEditor()->get('/search?term=' . urlencode('<p>test</p>'));
|
||||||
->visit('/')
|
$resp->assertSee('Search Results');
|
||||||
->type('<p>test</p>', 'term')
|
$resp->assertStatus(200);
|
||||||
->press('header-search-box-button')
|
$this->get('/search?term=cat+-')->assertStatus(200);
|
||||||
->see('Search Results')
|
|
||||||
->seeStatusCode(200);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_empty_search_redirects_back()
|
public function test_empty_search_shows_search_page()
|
||||||
{
|
{
|
||||||
$this->asAdmin()
|
$res = $this->asEditor()->get('/search');
|
||||||
->visit('/')
|
$res->assertStatus(200);
|
||||||
->visit('/search/all')
|
}
|
||||||
->seePageIs('/');
|
|
||||||
|
public function test_searching_accents_and_small_terms()
|
||||||
|
{
|
||||||
|
$page = $this->newPage(['name' => 'My new test quaffleachits', 'html' => 'some áéííúü¿¡ test content {a2 orange dog']);
|
||||||
|
$this->asEditor();
|
||||||
|
|
||||||
|
$accentSearch = $this->get('/search?term=' . urlencode('áéíí'));
|
||||||
|
$accentSearch->assertStatus(200)->assertSee($page->name);
|
||||||
|
|
||||||
|
$smallSearch = $this->get('/search?term=' . urlencode('{a'));
|
||||||
|
$smallSearch->assertStatus(200)->assertSee($page->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_book_search()
|
public function test_book_search()
|
||||||
@ -42,57 +46,20 @@ class EntitySearchTest extends BrowserKitTest
|
|||||||
$page = $book->pages->last();
|
$page = $book->pages->last();
|
||||||
$chapter = $book->chapters->last();
|
$chapter = $book->chapters->last();
|
||||||
|
|
||||||
$this->asAdmin()
|
$pageTestResp = $this->asEditor()->get('/search/book/' . $book->id . '?term=' . urlencode($page->name));
|
||||||
->visit('/search/book/' . $book->id . '?term=' . urlencode($page->name))
|
$pageTestResp->assertSee($page->name);
|
||||||
->see($page->name)
|
|
||||||
|
|
||||||
->visit('/search/book/' . $book->id . '?term=' . urlencode($chapter->name))
|
$chapterTestResp = $this->asEditor()->get('/search/book/' . $book->id . '?term=' . urlencode($chapter->name));
|
||||||
->see($chapter->name);
|
$chapterTestResp->assertSee($chapter->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_empty_book_search_redirects_back()
|
public function test_chapter_search()
|
||||||
{
|
{
|
||||||
$book = \BookStack\Book::all()->first();
|
$chapter = \BookStack\Chapter::has('pages')->first();
|
||||||
$this->asAdmin()
|
$page = $chapter->pages[0];
|
||||||
->visit('/books')
|
|
||||||
->visit('/search/book/' . $book->id . '?term=')
|
|
||||||
->seePageIs('/books');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
$pageTestResp = $this->asEditor()->get('/search/chapter/' . $chapter->id . '?term=' . urlencode($page->name));
|
||||||
public function test_pages_search_listing()
|
$pageTestResp->assertSee($page->name);
|
||||||
{
|
|
||||||
$page = \BookStack\Page::all()->last();
|
|
||||||
$this->asAdmin()->visit('/search/pages?term=' . $page->name)
|
|
||||||
->see('Page Search Results')->see('.entity-list', $page->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_chapters_search_listing()
|
|
||||||
{
|
|
||||||
$chapter = \BookStack\Chapter::all()->last();
|
|
||||||
$this->asAdmin()->visit('/search/chapters?term=' . $chapter->name)
|
|
||||||
->see('Chapter Search Results')->seeInElement('.entity-list', $chapter->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_search_quote_term_preparation()
|
|
||||||
{
|
|
||||||
$termString = '"192" cat "dog hat"';
|
|
||||||
$repo = $this->app[\BookStack\Repos\EntityRepo::class];
|
|
||||||
$preparedTerms = $repo->prepareSearchTerms($termString);
|
|
||||||
$this->assertTrue($preparedTerms === ['"192"','"dog hat"', 'cat']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_books_search_listing()
|
|
||||||
{
|
|
||||||
$book = \BookStack\Book::all()->last();
|
|
||||||
$this->asAdmin()->visit('/search/books?term=' . $book->name)
|
|
||||||
->see('Book Search Results')->see('.entity-list', $book->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_searching_hypen_doesnt_break()
|
|
||||||
{
|
|
||||||
$this->visit('/search/all?term=cat+-')
|
|
||||||
->seeStatusCode(200);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_tag_search()
|
public function test_tag_search()
|
||||||
@ -114,27 +81,99 @@ class EntitySearchTest extends BrowserKitTest
|
|||||||
$pageB = \BookStack\Page::all()->last();
|
$pageB = \BookStack\Page::all()->last();
|
||||||
$pageB->tags()->create(['name' => 'animal', 'value' => 'dog']);
|
$pageB->tags()->create(['name' => 'animal', 'value' => 'dog']);
|
||||||
|
|
||||||
$this->asAdmin()->visit('/search/all?term=%5Banimal%5D')
|
$this->asEditor();
|
||||||
->seeLink($pageA->name)
|
$tNameSearch = $this->get('/search?term=%5Banimal%5D');
|
||||||
->seeLink($pageB->name);
|
$tNameSearch->assertSee($pageA->name)->assertSee($pageB->name);
|
||||||
|
|
||||||
$this->visit('/search/all?term=%5Bcolor%5D')
|
$tNameSearch2 = $this->get('/search?term=%5Bcolor%5D');
|
||||||
->seeLink($pageA->name)
|
$tNameSearch2->assertSee($pageA->name)->assertDontSee($pageB->name);
|
||||||
->dontSeeLink($pageB->name);
|
|
||||||
|
|
||||||
$this->visit('/search/all?term=%5Banimal%3Dcat%5D')
|
$tNameValSearch = $this->get('/search?term=%5Banimal%3Dcat%5D');
|
||||||
->seeLink($pageA->name)
|
$tNameValSearch->assertSee($pageA->name)->assertDontSee($pageB->name);
|
||||||
->dontSeeLink($pageB->name);
|
}
|
||||||
|
|
||||||
|
public function test_exact_searches()
|
||||||
|
{
|
||||||
|
$page = $this->newPage(['name' => 'My new test page', 'html' => 'this is a story about an orange donkey']);
|
||||||
|
|
||||||
|
$exactSearchA = $this->asEditor()->get('/search?term=' . urlencode('"story about an orange"'));
|
||||||
|
$exactSearchA->assertStatus(200)->assertSee($page->name);
|
||||||
|
|
||||||
|
$exactSearchB = $this->asEditor()->get('/search?term=' . urlencode('"story not about an orange"'));
|
||||||
|
$exactSearchB->assertStatus(200)->assertDontSee($page->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_search_filters()
|
||||||
|
{
|
||||||
|
$page = $this->newPage(['name' => 'My new test quaffleachits', 'html' => 'this is about an orange donkey danzorbhsing']);
|
||||||
|
$this->asEditor();
|
||||||
|
$editorId = $this->getEditor()->id;
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
$this->get('/search?term=' . urlencode('danzorbhsing {updated_by:'.$editorId.'}'))->assertDontSee($page->name);
|
||||||
|
$page->created_by = $editorId;
|
||||||
|
$page->save();
|
||||||
|
$this->get('/search?term=' . urlencode('danzorbhsing {created_by:me}'))->assertSee($page->name);
|
||||||
|
$this->get('/search?term=' . urlencode('danzorbhsing {created_by:'.$editorId.'}'))->assertSee($page->name);
|
||||||
|
$this->get('/search?term=' . urlencode('danzorbhsing {updated_by:me}'))->assertDontSee($page->name);
|
||||||
|
$page->updated_by = $editorId;
|
||||||
|
$page->save();
|
||||||
|
$this->get('/search?term=' . urlencode('danzorbhsing {updated_by:me}'))->assertSee($page->name);
|
||||||
|
$this->get('/search?term=' . urlencode('danzorbhsing {updated_by:'.$editorId.'}'))->assertSee($page->name);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
$page->restricted = true;
|
||||||
|
$page->save();
|
||||||
|
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_ajax_entity_search()
|
public function test_ajax_entity_search()
|
||||||
{
|
{
|
||||||
$page = \BookStack\Page::all()->last();
|
$page = \BookStack\Page::all()->last();
|
||||||
$notVisitedPage = \BookStack\Page::first();
|
$notVisitedPage = \BookStack\Page::first();
|
||||||
$this->visit($page->getUrl());
|
|
||||||
$this->asAdmin()->visit('/ajax/search/entities?term=' . $page->name)->see('.entity-list', $page->name);
|
// Visit the page to make popular
|
||||||
$this->asAdmin()->visit('/ajax/search/entities?types=book&term=' . $page->name)->dontSee('.entity-list', $page->name);
|
$this->asEditor()->get($page->getUrl());
|
||||||
$this->asAdmin()->visit('/ajax/search/entities')->see('.entity-list', $page->name)->dontSee($notVisitedPage->name);
|
|
||||||
|
$normalSearch = $this->get('/ajax/search/entities?term=' . urlencode($page->name));
|
||||||
|
$normalSearch->assertSee($page->name);
|
||||||
|
|
||||||
|
$bookSearch = $this->get('/ajax/search/entities?types=book&term=' . urlencode($page->name));
|
||||||
|
$bookSearch->assertDontSee($page->name);
|
||||||
|
|
||||||
|
$defaultListTest = $this->get('/ajax/search/entities');
|
||||||
|
$defaultListTest->assertSee($page->name);
|
||||||
|
$defaultListTest->assertDontSee($notVisitedPage->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,4 +76,16 @@ abstract class TestCase extends BaseTestCase
|
|||||||
public function newChapter($input = ['name' => 'test chapter', 'description' => 'My new test chapter'], Book $book) {
|
public function newChapter($input = ['name' => 'test chapter', 'description' => 'My new test chapter'], Book $book) {
|
||||||
return $this->app[EntityRepo::class]->createFromInput('chapter', $input, $book);
|
return $this->app[EntityRepo::class]->createFromInput('chapter', $input, $book);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create and return a new test page
|
||||||
|
* @param array $input
|
||||||
|
* @return Chapter
|
||||||
|
*/
|
||||||
|
public function newPage($input = ['name' => 'test page', 'html' => 'My new test page']) {
|
||||||
|
$book = Book::first();
|
||||||
|
$entityRepo = $this->app[EntityRepo::class];
|
||||||
|
$draftPage = $entityRepo->getDraftPage($book);
|
||||||
|
return $entityRepo->publishPageDraft($draftPage, $input);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user