Inheritance: extends Entity
Example #1
0
 public function pageCreation($chapter)
 {
     $page = factory(\BookStack\Page::class)->make(['name' => 'My First Page']);
     $this->asAdmin()->visit($chapter->getUrl())->click('New Page')->seePageIs($chapter->getUrl() . '/create-page')->type($page->name, '#name')->type($page->html, '#html')->press('Save Page')->seePageIs($chapter->book->getUrl() . '/page/my-first-page')->see($page->name);
     $page = \BookStack\Page::where('slug', '=', 'my-first-page')->where('chapter_id', '=', $chapter->id)->first();
     return $page;
 }
 public function test_ajax_entity_search()
 {
     $page = \BookStack\Page::all()->last();
     $notVisitedPage = \BookStack\Page::first();
     $this->visit($page->getUrl());
     $this->asAdmin()->visit('/ajax/search/entities?term=' . $page->name)->see('.entity-list', $page->name);
     $this->asAdmin()->visit('/ajax/search/entities?types=book&term=' . $page->name)->dontSee('.entity-list', $page->name);
     $this->asAdmin()->visit('/ajax/search/entities')->see('.entity-list', $page->name)->dontSee($notVisitedPage->name);
 }
Example #3
0
 /**
  * Get an instance of a page that has many tags.
  * @param Tag[]|bool $tags
  * @return mixed
  */
 protected function getPageWithTags($tags = false)
 {
     $page = Page::first();
     if (!$tags) {
         $tags = factory(Tag::class, $this->defaultTagCount)->make();
     }
     $page->tags()->saveMany($tags);
     return $page;
 }
 public function test_app_not_public()
 {
     $this->setSettings(['app-public' => 'false']);
     $book = \BookStack\Book::orderBy('name', 'asc')->first();
     $this->visit('/books')->seePageIs('/login');
     $this->visit($book->getUrl())->seePageIs('/login');
     $page = \BookStack\Page::first();
     $this->visit($page->getUrl())->seePageIs('/login');
 }
Example #5
0
 public function test_alert_message_shows_if_someone_else_editing()
 {
     $nonEditedPage = \BookStack\Page::take(10)->get()->last();
     $addedContent = '<p>test message content</p>';
     $this->asAdmin()->visit($this->page->getUrl() . '/edit')->dontSeeInField('html', $addedContent);
     $newContent = $this->page->html . $addedContent;
     $newUser = $this->getEditor();
     $this->pageRepo->saveUpdateDraft($this->page, ['html' => $newContent]);
     $this->actingAs($newUser)->visit($this->page->getUrl() . '/edit')->see('Admin has started editing this page');
     $this->flushSession();
     $this->visit($nonEditedPage->getUrl() . '/edit')->dontSeeInElement('.notification', 'Admin has started editing this page');
 }
Example #6
0
 public function test_image_delete()
 {
     $page = \BookStack\Page::first();
     $this->asAdmin();
     $imageName = 'first-image.jpg';
     $relPath = $this->uploadImage($imageName, $page->id);
     $image = \BookStack\Image::first();
     $this->call('DELETE', '/images/' . $image->id);
     $this->assertResponseOk();
     $this->dontSeeInDatabase('images', ['url' => $this->baseUrl . $relPath, 'type' => 'gallery']);
     $this->assertFalse(file_exists(public_path($relPath)), 'Uploaded image has been deleted');
 }
Example #7
0
 public function test_chapter_move()
 {
     $chapter = \BookStack\Chapter::first();
     $currentBook = $chapter->book;
     $pageToCheck = $chapter->pages->first();
     $newBook = \BookStack\Book::where('id', '!=', $currentBook->id)->first();
     $this->asAdmin()->visit($chapter->getUrl() . '/move')->see('Move Chapter')->see($chapter->name)->type('book:' . $newBook->id, 'entity_selection')->press('Move Chapter');
     $chapter = \BookStack\Chapter::find($chapter->id);
     $this->seePageIs($chapter->getUrl());
     $this->assertTrue($chapter->book->id === $newBook->id, 'Chapter Book is now the new book');
     $this->visit($newBook->getUrl())->seeInNthElement('.activity-list-item', 0, 'moved chapter')->seeInNthElement('.activity-list-item', 0, $chapter->name);
     $pageToCheck = \BookStack\Page::find($pageToCheck->id);
     $this->assertTrue($pageToCheck->book_id === $newBook->id, 'Chapter child page\'s book id has changed to the new book');
     $this->visit($pageToCheck->getUrl())->see($newBook->name);
 }
Example #8
0
 public function test_recently_updated_pages_on_home()
 {
     $page = \BookStack\Page::orderBy('updated_at', 'asc')->first();
     $this->asAdmin()->visit('/')->dontSeeInElement('#recently-updated-pages', $page->name);
     $this->visit($page->getUrl() . '/edit')->press('Save Page')->visit('/')->seeInElement('#recently-updated-pages', $page->name);
 }
Example #9
0
 /**
  * Get draft pages owned by the current user.
  * @param int $count
  * @param int $page
  */
 public function getUserDraftPages($count = 20, $page = 0)
 {
     return $this->page->where('draft', '=', true)->where('created_by', '=', user()->id)->orderBy('updated_at', 'desc')->skip($count * $page)->take($count)->get();
 }
Example #10
0
 /**
  * Changes the related book for the specified page.
  * Changes the book id of any relations to the page that store the book id.
  * @param int  $bookId
  * @param Page $page
  * @return Page
  */
 public function changeBook($bookId, Page $page)
 {
     $page->book_id = $bookId;
     foreach ($page->activity as $activity) {
         $activity->book_id = $bookId;
         $activity->save();
     }
     $page->slug = $this->findSuitableSlug($page->name, $bookId, $page->id);
     $page->save();
     return $page;
 }
Example #11
0
 public function test_attachment_deletion_on_page_deletion()
 {
     $page = \BookStack\Page::first();
     $this->asAdmin();
     $fileName = 'deletion_test.txt';
     $this->uploadFile($fileName, $page->id);
     $filePath = base_path('storage/' . $this->getUploadPath($fileName));
     $this->assertTrue(file_exists($filePath), 'File at path ' . $filePath . ' does not exist');
     $this->seeInDatabase('attachments', ['name' => $fileName]);
     $this->call('DELETE', $page->getUrl());
     $this->dontSeeInDatabase('attachments', ['name' => $fileName]);
     $this->assertFalse(file_exists($filePath), 'File at path ' . $filePath . ' was not deleted as expected');
     $this->deleteUploads();
 }
Example #12
0
 public function test_page_delete_all_permission()
 {
     $this->giveUserPermissions($this->user, ['page-update-all']);
     $otherPage = \BookStack\Page::take(1)->get()->first();
     $this->checkAccessPermission('page-delete-all', [$otherPage->getUrl() . '/delete'], [$otherPage->getUrl() => 'Delete']);
     $bookUrl = $otherPage->book->getUrl();
     $this->visit($otherPage->getUrl())->visit($otherPage->getUrl() . '/delete')->press('Confirm')->seePageIs($bookUrl)->dontSeeInElement('.book-content', $otherPage->name);
 }
Example #13
0
 /**
  * Change the page's parent to the given entity.
  * @param Page $page
  * @param Entity $parent
  */
 public function changePageParent(Page $page, Entity $parent)
 {
     $book = $parent->isA('book') ? $parent : $parent->book;
     $page->chapter_id = $parent->isA('chapter') ? $parent->id : 0;
     $page->save();
     $page = $this->changeBook($book->id, $page);
     $page->load('book');
     $this->permissionService->buildJointPermissionsForEntity($book);
 }
Example #14
0
 public function setUp()
 {
     parent::setUp();
     $this->page = \BookStack\Page::first();
 }
 public function test_page_restriction_form()
 {
     $page = \BookStack\Page::first();
     $this->asAdmin()->visit($page->getUrl() . '/permissions')->see('Page Permissions')->check('restricted')->check('restrictions[2][delete]')->press('Save Permissions')->seeInDatabase('pages', ['id' => $page->id, 'restricted' => true])->seeInDatabase('entity_permissions', ['restrictable_id' => $page->id, 'restrictable_type' => 'BookStack\\Page', 'role_id' => '2', 'action' => 'delete']);
 }