mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-04-27 06:34:05 +08:00
Adds test case for sorting permissions.
Signed-off-by: Abijeet <abijeetpatro@gmail.com>
This commit is contained in:
parent
e13e71cbe0
commit
e269cc7ea7
@ -3,7 +3,6 @@
|
|||||||
use BookStack\Entity;
|
use BookStack\Entity;
|
||||||
use BookStack\Role;
|
use BookStack\Role;
|
||||||
use BookStack\Services\PermissionService;
|
use BookStack\Services\PermissionService;
|
||||||
use BookStack\User;
|
|
||||||
use Illuminate\Contracts\Console\Kernel;
|
use Illuminate\Contracts\Console\Kernel;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
use Laravel\BrowserKitTesting\TestCase;
|
use Laravel\BrowserKitTesting\TestCase;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
use BookStack\Book;
|
use BookStack\Book;
|
||||||
use BookStack\Services\PermissionService;
|
use BookStack\Services\PermissionService;
|
||||||
use BookStack\User;
|
use BookStack\User;
|
||||||
|
use BookStack\Repos\EntityRepo;
|
||||||
|
|
||||||
class RestrictionsTest extends BrowserKitTest
|
class RestrictionsTest extends BrowserKitTest
|
||||||
{
|
{
|
||||||
@ -554,4 +555,70 @@ class RestrictionsTest extends BrowserKitTest
|
|||||||
$this->dontSee(substr($bookChapter->name, 0, 15));
|
$this->dontSee(substr($bookChapter->name, 0, 15));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_book_sort_view_permission()
|
||||||
|
{
|
||||||
|
$firstBook = Book::first();
|
||||||
|
$secondBook = Book::find(2);
|
||||||
|
$thirdBook = Book::find(3);
|
||||||
|
|
||||||
|
$this->setEntityRestrictions($firstBook, ['view', 'update']);
|
||||||
|
$this->setEntityRestrictions($secondBook, ['view']);
|
||||||
|
$this->setEntityRestrictions($thirdBook, ['view', 'update']);
|
||||||
|
|
||||||
|
// Test sort page visibility
|
||||||
|
$this->actingAs($this->user)->visit($secondBook->getUrl() . '/sort')
|
||||||
|
->see('You do not have permission')
|
||||||
|
->seePageIs('/');
|
||||||
|
|
||||||
|
// Check sort page on first book
|
||||||
|
$this->actingAs($this->user)->visit($firstBook->getUrl() . '/sort')
|
||||||
|
->see($thirdBook->name)
|
||||||
|
->dontSee($secondBook->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_book_sort_permission() {
|
||||||
|
$firstBook = Book::first();
|
||||||
|
$secondBook = Book::find(2);
|
||||||
|
|
||||||
|
$this->setEntityRestrictions($firstBook, ['view', 'update']);
|
||||||
|
$this->setEntityRestrictions($secondBook, ['view']);
|
||||||
|
|
||||||
|
$firstBookChapter = $this->app[EntityRepo::class]->createFromInput('chapter',
|
||||||
|
['name' => 'first book chapter'], $firstBook);
|
||||||
|
$secondBookChapter = $this->app[EntityRepo::class]->createFromInput('chapter',
|
||||||
|
['name' => 'second book chapter'], $secondBook);
|
||||||
|
|
||||||
|
// Create request data
|
||||||
|
$reqData = [
|
||||||
|
[
|
||||||
|
'id' => $firstBookChapter->id,
|
||||||
|
'sort' => 0,
|
||||||
|
'parentChapter' => false,
|
||||||
|
'type' => 'chapter',
|
||||||
|
'book' => $secondBook->id
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
// Move chapter from first book to a second book
|
||||||
|
$this->actingAs($this->user)->put($firstBook->getUrl() . '/sort', ['sort-tree' => json_encode($reqData)])
|
||||||
|
->followRedirects()
|
||||||
|
->see('You do not have permission')
|
||||||
|
->seePageIs('/');
|
||||||
|
|
||||||
|
$reqData = [
|
||||||
|
[
|
||||||
|
'id' => $secondBookChapter->id,
|
||||||
|
'sort' => 0,
|
||||||
|
'parentChapter' => false,
|
||||||
|
'type' => 'chapter',
|
||||||
|
'book' => $firstBook->id
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
// Move chapter from second book to first book
|
||||||
|
$this->actingAs($this->user)->put($firstBook->getUrl() . '/sort', ['sort-tree' => json_encode($reqData)])
|
||||||
|
->followRedirects()
|
||||||
|
->see('You do not have permission')
|
||||||
|
->seePageIs('/');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user