public function chapterCreation(\BookStack\Book $book) { $chapter = factory(\BookStack\Chapter::class)->make(['name' => 'My First Chapter']); $this->asAdmin()->visit($book->getUrl())->click('New Chapter')->seePageIs($book->getUrl() . '/chapter/create')->type($chapter->name, '#name')->type($chapter->description, '#description')->press('Save Chapter')->seePageIs($book->getUrl() . '/chapter/my-first-chapter')->see($chapter->name)->see($chapter->description); $chapter = \BookStack\Chapter::where('slug', '=', 'my-first-chapter')->where('book_id', '=', $book->id)->first(); return $chapter; }
public function testChaptersViewable() { $this->setSettings(['app-public' => 'true']); $chapterToVisit = \BookStack\Chapter::first(); $pageToVisit = $chapterToVisit->pages()->first(); // Check chapters index page is showing $this->visit($chapterToVisit->getUrl())->seeStatusCode(200)->see($chapterToVisit->name)->see($pageToVisit->name)->click($pageToVisit->name)->see($chapterToVisit->book->name)->see($chapterToVisit->name)->seePageIs($pageToVisit->getUrl()); }
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); }
public function test_public_page_creation() { $this->setSettings(['app-public' => 'true']); $publicRole = \BookStack\Role::getSystemRole('public'); // Grant all permissions to public $publicRole->permissions()->detach(); foreach (\BookStack\RolePermission::all() as $perm) { $publicRole->attachPermission($perm); } $this->app[\BookStack\Services\PermissionService::class]->buildJointPermissionForRole($publicRole); $chapter = \BookStack\Chapter::first(); $this->visit($chapter->book->getUrl()); $this->visit($chapter->getUrl())->click('New Page')->see('Create Page')->seePageIs($chapter->getUrl('/create-page')); $this->submitForm('Continue', ['name' => 'My guest page'])->seePageIs($chapter->book->getUrl('/page/my-guest-page/edit')); $user = \BookStack\User::getDefault(); $this->seeInDatabase('pages', ['name' => 'My guest page', 'chapter_id' => $chapter->id, 'created_by' => $user->id, 'updated_by' => $user->id]); }
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_page_create_all_permissions() { $book = \BookStack\Book::take(1)->get()->first(); $chapter = \BookStack\Chapter::take(1)->get()->first(); $baseUrl = $book->getUrl() . '/page'; $createUrl = $baseUrl . '/create'; $createUrlChapter = $chapter->getUrl() . '/create-page'; $accessUrls = [$createUrl, $createUrlChapter]; foreach ($accessUrls as $url) { $this->actingAs($this->user)->visit('/')->visit($url)->seePageIs('/'); } $this->checkAccessPermission('page-create-all', [], [$book->getUrl() => 'New Page', $chapter->getUrl() => 'New Page']); $this->giveUserPermissions($this->user, ['page-create-all']); foreach ($accessUrls as $index => $url) { $this->actingAs($this->user)->visit('/')->visit($url); $expectedUrl = \BookStack\Page::where('draft', '=', true)->orderBy('id', 'desc')->first()->getUrl(); $this->seePageIs($expectedUrl); } $this->visit($baseUrl . '/create')->type('test page', 'name')->type('page desc', 'html')->press('Save Page')->seePageIs($baseUrl . '/test-page'); $this->visit($chapter->getUrl() . '/create-page')->type('new test page', 'name')->type('page desc', 'html')->press('Save Page')->seePageIs($baseUrl . '/new-test-page'); }
/** * Changes the book relation of this chapter. * @param $bookId * @param Chapter $chapter * @param bool $rebuildPermissions * @return Chapter */ public function changeBook($bookId, Chapter $chapter, $rebuildPermissions = false) { $chapter->book_id = $bookId; // Update related activity foreach ($chapter->activity as $activity) { $activity->book_id = $bookId; $activity->save(); } $chapter->slug = $this->findSuitableSlug($chapter->name, $bookId, $chapter->id); $chapter->save(); // Update all child pages foreach ($chapter->pages as $page) { $this->pageRepo->changeBook($bookId, $page); } // Update permissions if applicable if ($rebuildPermissions) { $chapter->load('book'); $this->permissionService->buildJointPermissionsForEntity($chapter->book); } return $chapter; }
public function test_restricted_pages_not_visible_on_chapter_pages() { $chapter = \BookStack\Chapter::first(); $page = $chapter->pages->first(); $this->setEntityRestrictions($page, []); $this->actingAs($this->user)->visit($chapter->getUrl())->dontSee($page->name); }
/** * Changes the book relation of this chapter. * @param $bookId * @param Chapter $chapter * @return Chapter */ public function changeBook($bookId, Chapter $chapter) { $chapter->book_id = $bookId; foreach ($chapter->activity as $activity) { $activity->book_id = $bookId; $activity->save(); } $chapter->slug = $this->findSuitableSlug($chapter->name, $bookId, $chapter->id); $chapter->save(); return $chapter; }