1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Added testing coverage for Bookshelves

Created modified TestResponse so we can use DOM operations in new
Testcases as we move away from the BrowserKit tests.
This commit is contained in:
Dan Brown
2018-09-21 15:15:16 +01:00
parent 8ff969dd17
commit b59e5942c8
8 changed files with 595 additions and 28 deletions

View File

@ -1,9 +1,11 @@
<?php namespace Tests;
use BookStack\Book;
use BookStack\Bookshelf;
use BookStack\Chapter;
use BookStack\Entity;
use BookStack\Repos\EntityRepo;
use BookStack\Repos\PermissionsRepo;
use BookStack\Role;
use BookStack\Services\PermissionService;
use BookStack\Services\SettingService;
@ -69,6 +71,25 @@ trait SharedTestHelpers
return $user;
}
/**
* Regenerate the permission for an entity.
* @param Entity $entity
*/
protected function regenEntityPermissions(Entity $entity)
{
$this->app[PermissionService::class]->buildJointPermissionsForEntity($entity);
$entity->load('jointPermissions');
}
/**
* Create and return a new bookshelf.
* @param array $input
* @return Bookshelf
*/
public function newShelf($input = ['name' => 'test shelf', 'description' => 'My new test shelf']) {
return $this->app[EntityRepo::class]->createFromInput('bookshelf', $input, false);
}
/**
* Create and return a new book.
* @param array $input
@ -140,4 +161,30 @@ trait SharedTestHelpers
$entity->load('jointPermissions');
}
/**
* Give the given user some permissions.
* @param \BookStack\User $user
* @param array $permissions
*/
protected function giveUserPermissions(\BookStack\User $user, $permissions = [])
{
$newRole = $this->createNewRole($permissions);
$user->attachRole($newRole);
$user->load('roles');
$user->permissions(false);
}
/**
* Create a new basic role for testing purposes.
* @param array $permissions
* @return Role
*/
protected function createNewRole($permissions = [])
{
$permissionRepo = app(PermissionsRepo::class);
$roleData = factory(Role::class)->make()->toArray();
$roleData['permissions'] = array_flip($permissions);
return $permissionRepo->saveNewRole($roleData);
}
}