$resp->assertRedirect();
$this->assertEquals('list', setting()->getUser($editor, 'books_view_type'));
}
+
+ public function test_slug_multi_byte_url_safe()
+ {
+ $book = $this->newBook([
+ 'name' => 'информация',
+ ]);
+
+ $this->assertEquals('informatsiya', $book->slug);
+
+ $book = $this->newBook([
+ 'name' => '¿Qué?',
+ ]);
+
+ $this->assertEquals('que', $book->slug);
+ }
+
+ public function test_slug_format()
+ {
+ $book = $this->newBook([
+ 'name' => 'PartA / PartB / PartC',
+ ]);
+
+ $this->assertEquals('parta-partb-partc', $book->slug);
+ }
}
use BookStack\Auth\UserRepo;
use BookStack\Entities\Models\Book;
-use BookStack\Entities\Models\Bookshelf;
use BookStack\Entities\Models\Chapter;
use BookStack\Entities\Models\Page;
use BookStack\Entities\Repos\PageRepo;
-use Carbon\Carbon;
use Tests\BrowserKitTest;
class EntityTest extends BrowserKitTest
return Book::find($book->id);
}
- public function test_book_sort_page_shows()
- {
- $books = Book::all();
- $bookToSort = $books[0];
- $this->asAdmin()
- ->visit($bookToSort->getUrl())
- ->click('Sort')
- ->seePageIs($bookToSort->getUrl() . '/sort')
- ->seeStatusCode(200)
- ->see($bookToSort->name);
- }
-
- public function test_book_sort_item_returns_book_content()
- {
- $books = Book::all();
- $bookToSort = $books[0];
- $firstPage = $bookToSort->pages[0];
- $firstChapter = $bookToSort->chapters[0];
- $this->asAdmin()
- ->visit($bookToSort->getUrl() . '/sort-item')
- // Ensure book details are returned
- ->see($bookToSort->name)
- ->see($firstPage->name)
- ->see($firstChapter->name);
- }
-
public function pageCreation($chapter)
{
$page = factory(Page::class)->make([
->click('Revisions')->seeStatusCode(200);
}
- public function test_recently_updated_pages_view()
- {
- $user = $this->getEditor();
- $content = $this->createEntityChainBelongingToUser($user);
-
- $this->asAdmin()->visit('/pages/recently-updated')
- ->seeInNthElement('.entity-list .page', 0, $content['page']->name);
- }
-
- public function test_old_page_slugs_redirect_to_new_pages()
- {
- $page = Page::first();
- $pageUrl = $page->getUrl();
- $newPageUrl = '/books/' . $page->book->slug . '/page/super-test-page';
- // Need to save twice since revisions are not generated in seeder.
- $this->asAdmin()->visit($pageUrl)
- ->clickInElement('#content', 'Edit')
- ->type('super test', '#name')
- ->press('Save Page');
-
- $page = Page::first();
- $pageUrl = $page->getUrl();
-
- // Second Save
- $this->visit($pageUrl)
- ->clickInElement('#content', 'Edit')
- ->type('super test page', '#name')
- ->press('Save Page')
- // Check redirect
- ->seePageIs($newPageUrl);
-
- $this->visit($pageUrl)
- ->seePageIs($newPageUrl);
- }
-
- public function test_recently_updated_pages_on_home()
- {
- $page = Page::orderBy('updated_at', 'asc')->first();
- Page::where('id', '!=', $page->id)->update([
- 'updated_at' => Carbon::now()->subSecond(1),
- ]);
- $this->asAdmin()->visit('/')
- ->dontSeeInElement('#recently-updated-pages', $page->name);
- $this->visit($page->getUrl() . '/edit')
- ->press('Save Page')
- ->visit('/')
- ->seeInElement('#recently-updated-pages', $page->name);
- }
-
- public function test_slug_multi_byte_url_safe()
- {
- $book = $this->newBook([
- 'name' => 'информация',
- ]);
-
- $this->assertEquals('informatsiya', $book->slug);
-
- $book = $this->newBook([
- 'name' => '¿Qué?',
- ]);
-
- $this->assertEquals('que', $book->slug);
- }
-
- public function test_slug_format()
- {
- $book = $this->newBook([
- 'name' => 'PartA / PartB / PartC',
- ]);
-
- $this->assertEquals('parta-partb-partc', $book->slug);
- }
-
- public function test_page_within_chapter_deletion_returns_to_chapter()
- {
- $chapter = Chapter::query()->first();
- $page = $chapter->pages()->first();
-
- $this->asEditor()->visit($page->getUrl('/delete'))
- ->submitForm('Confirm')
- ->seePageIs($chapter->getUrl());
- }
}
namespace Tests\Entity;
+use BookStack\Entities\Models\Book;
use BookStack\Entities\Models\Page;
use Tests\TestCase;
$this->asAdmin()->get($this->page->getUrl() . '/edit')
->assertElementContains('[name="markdown"]', $this->page->html);
}
+
+ public function test_empty_markdown_still_saves_without_error()
+ {
+ $this->setSettings(['app-editor' => 'markdown']);
+ /** @var Book $book */
+ $book = Book::query()->first();
+
+ $this->asEditor()->get($book->getUrl('/create-page'));
+ $draft = Page::query()->where('book_id', '=', $book->id)
+ ->where('draft', '=', true)->first();
+
+ $details = [
+ 'name' => 'my page',
+ 'markdown' => '',
+ ];
+ $resp = $this->post($book->getUrl("/draft/{$draft->id}"), $details);
+ $resp->assertRedirect();
+
+ $this->assertDatabaseHas('pages', [
+ 'markdown' => $details['markdown'],
+ 'id' => $draft->id,
+ 'draft' => false,
+ ]);
+ }
}
\ No newline at end of file
namespace Tests\Entity;
use BookStack\Entities\Models\Book;
+use BookStack\Entities\Models\Chapter;
use BookStack\Entities\Models\Page;
+use Carbon\Carbon;
use Tests\TestCase;
class PageTest extends TestCase
]);
}
- public function test_empty_markdown_still_saves_without_error()
+ public function test_old_page_slugs_redirect_to_new_pages()
{
- $this->setSettings(['app-editor' => 'markdown']);
- $book = Book::query()->first();
+ /** @var Page $page */
+ $page = Page::query()->first();
- $this->asEditor()->get($book->getUrl('/create-page'));
- $draft = Page::query()->where('book_id', '=', $book->id)
- ->where('draft', '=', true)->first();
+ // Need to save twice since revisions are not generated in seeder.
+ $this->asAdmin()->put($page->getUrl(), [
+ 'name' => 'super test',
+ 'html' => '<p></p>'
+ ]);
- $details = [
- 'name' => 'my page',
- 'markdown' => '',
- ];
- $resp = $this->post($book->getUrl("/draft/{$draft->id}"), $details);
- $resp->assertRedirect();
+ $page->refresh();
+ $pageUrl = $page->getUrl();
- $this->assertDatabaseHas('pages', [
- 'markdown' => $details['markdown'],
- 'id' => $draft->id,
- 'draft' => false,
+ $this->put($pageUrl, [
+ 'name' => 'super test page',
+ 'html' => '<p></p>'
]);
+
+ $this->get($pageUrl)
+ ->assertRedirect("/books/{$page->book->slug}/page/super-test-page");
}
+
+ public function test_page_within_chapter_deletion_returns_to_chapter()
+ {
+ /** @var Chapter $chapter */
+ $chapter = Chapter::query()->first();
+ $page = $chapter->pages()->first();
+
+ $this->asEditor()->delete($page->getUrl())
+ ->assertRedirect($chapter->getUrl());
+ }
+
+ public function test_recently_updated_pages_view()
+ {
+ $user = $this->getEditor();
+ $content = $this->createEntityChainBelongingToUser($user);
+
+ $this->asAdmin()->get('/pages/recently-updated')
+ ->assertElementContains('.entity-list .page:nth-child(1)', $content['page']->name);
+ }
+
+ public function test_recently_updated_pages_on_home()
+ {
+ /** @var Page $page */
+ $page = Page::query()->orderBy('updated_at', 'asc')->first();
+ Page::query()->where('id', '!=', $page->id)->update([
+ 'updated_at' => Carbon::now()->subSecond(1),
+ ]);
+
+ $this->asAdmin()->get('/')
+ ->assertElementNotContains('#recently-updated-pages', $page->name);
+
+ $this->put($page->getUrl(), [
+ 'name' => $page->name,
+ 'html' => $page->html,
+ ]);
+
+ $this->get('/')
+ ->assertElementContains('#recently-updated-pages', $page->name);
+ }
+
}
$this->assertEquals($newBook->id, $pageToCheck->book_id);
}
+ public function test_book_sort_page_shows()
+ {
+ /** @var Book $bookToSort */
+ $bookToSort = Book::query()->first();
+
+ $resp = $this->asAdmin()->get($bookToSort->getUrl());
+ $resp->assertElementExists('a[href="' . $bookToSort->getUrl('/sort') . '"]');
+
+ $resp = $this->get($bookToSort->getUrl('/sort'));
+ $resp->assertStatus(200);
+ $resp->assertSee($bookToSort->name);
+ }
+
public function test_book_sort()
{
$oldBook = Book::query()->first();
$checkResp->assertSee($newBook->name);
}
+ public function test_book_sort_item_returns_book_content()
+ {
+ $books = Book::all();
+ $bookToSort = $books[0];
+ $firstPage = $bookToSort->pages[0];
+ $firstChapter = $bookToSort->chapters[0];
+
+ $resp = $this->asAdmin()->get($bookToSort->getUrl() . '/sort-item');
+
+ // Ensure book details are returned
+ $resp->assertSee($bookToSort->name);
+ $resp->assertSee($firstPage->name);
+ $resp->assertSee($firstChapter->name);
+ }
+
public function test_pages_in_book_show_sorted_by_priority()
{
/** @var Book $book */
/**
* Create a group of entities that belong to a specific user.
+ * @return array{book: Book, chapter: Chapter, page: Page}
*/
protected function createEntityChainBelongingToUser(User $creatorUser, ?User $updaterUser = null): array
{