use Illuminate\Database\Eloquent\Relations\MorphTo;
/**
- * @property int $id
- * @property string $text
- * @property string $html
+ * @property int $id
+ * @property string $text
+ * @property string $html
* @property int|null $parent_id
- * @property int $local_id
+ * @property int $local_id
*/
class Comment extends Model
{
/**
* Class Role.
*
- * @property int $id
- * @property string $display_name
- * @property string $description
- * @property string $external_auth_id
- * @property string $system_name
- * @property bool $mfa_enforced
+ * @property int $id
+ * @property string $display_name
+ * @property string $description
+ * @property string $external_auth_id
+ * @property string $system_name
+ * @property bool $mfa_enforced
* @property Collection $users
*/
class Role extends Model implements Loggable
/**
* Class Book.
*
- * @property string $description
- * @property int $image_id
- * @property Image|null $cover
+ * @property string $description
+ * @property int $image_id
+ * @property Image|null $cover
* @property \Illuminate\Database\Eloquent\Collection $chapters
* @property \Illuminate\Database\Eloquent\Collection $pages
* @property \Illuminate\Database\Eloquent\Collection $directPages
$this->get('/register');
$resp = $this->followingRedirects()->post('/register', [
- 'name' => '1',
- 'email' => '1',
+ 'name' => '1',
+ 'email' => '1',
'password' => '1',
]);
$resp->assertSee('The name must be at least 2 characters.');
->assertSee('Reset Password');
$resp = $this->post('/password/reset', [
- 'password' => 'randompass',
+ 'password' => 'randompass',
'password_confirmation' => 'randompass',
- 'token' => $n->first()->token
+ 'token' => $n->first()->token,
]);
$resp->assertRedirect('/');
$resp->assertSee('A password reset link will be sent to
[email protected] if that email address is found in the system.');
$resp->assertDontSee('We can\'t find a user');
-
$this->get('/password/reset/arandometokenvalue')->assertSee('Reset Password');
$resp = $this->post('/password/reset', [
- 'password' => 'randompass',
+ 'password' => 'randompass',
'password_confirmation' => 'randompass',
- 'token' => 'arandometokenvalue'
+ 'token' => 'arandometokenvalue',
]);
$resp->assertRedirect('/password/reset/arandometokenvalue');
class PageEditorTest extends TestCase
{
- /** @var Page */
+ /** @var Page */
protected $page;
public function setUp(): void
'draft' => false,
]);
}
-}
\ No newline at end of file
+}
// Need to save twice since revisions are not generated in seeder.
$this->asAdmin()->put($page->getUrl(), [
'name' => 'super test',
- 'html' => '<p></p>'
+ 'html' => '<p></p>',
]);
$page->refresh();
$this->put($pageUrl, [
'name' => 'super test page',
- 'html' => '<p></p>'
+ 'html' => '<p></p>',
]);
$this->get($pageUrl)
$this->get('/')
->assertElementContains('#recently-updated-pages', $page->name);
}
-
}
$this->setRestrictionsForTestRoles($book, ['view', 'create']);
$resp = $this->post($book->getUrl('/create-chapter'), [
- 'name' => 'test chapter',
+ 'name' => 'test chapter',
'description' => 'desc',
]);
$resp->assertRedirect($book->getUrl('/chapter/test-chapter'));
-
$this->get($book->getUrl('/create-page'));
/** @var Page $page */
$page = Page::query()->where('draft', '=', true)->orderBy('id', 'desc')->first();
->assertSee($title);
$this->put($modelInstance->getUrl('/permissions'), [
- 'restricted' => 'true',
+ 'restricted' => 'true',
'restrictions' => [
$roleId => [
- $permission => 'true'
- ]
+ $permission => 'true',
+ ],
],
]);
$this->setRestrictionsForTestRoles($book, ['view', 'create']);
$resp = $this->post($book->getUrl('/create-chapter'), [
- 'name' => 'test chapter',
+ 'name' => 'test chapter',
'description' => 'test desc',
]);
$resp->assertRedirect($book->getUrl('/chapter/test-chapter'));
-
$this->get($book->getUrl('/create-page'));
/** @var Page $page */
$page = Page::query()->where('draft', '=', true)->orderByDesc('id')->first();
$this->setRestrictionsForTestRoles($bookChapter, ['view', 'create']);
-
$this->get($bookChapter->getUrl('/create-page'));
/** @var Page $page */
$page = Page::query()->where('draft', '=', true)->orderByDesc('id')->first();
$resp = $this->post('/settings/roles/new', [
'display_name' => $testRoleName,
- 'description' => $testRoleDesc,
+ 'description' => $testRoleDesc,
]);
$resp->assertRedirect('/settings/roles');
$resp->assertSee($testRoleDesc);
$this->assertDatabaseHas('roles', [
'display_name' => $testRoleName,
- 'description' => $testRoleDesc,
+ 'description' => $testRoleDesc,
'mfa_enforced' => false,
]);
$resp = $this->put('/settings/roles/' . $role->id, [
'display_name' => $testRoleUpdateName,
- 'description' => $testRoleDesc,
+ 'description' => $testRoleDesc,
'mfa_enforced' => 'true',
]);
$resp->assertRedirect('/settings/roles');
$this->assertDatabaseHas('roles', [
'display_name' => $testRoleUpdateName,
- 'description' => $testRoleDesc,
+ 'description' => $testRoleDesc,
'mfa_enforced' => true,
]);
]);
$this->post('/shelves', [
- 'name' => 'test shelf',
+ 'name' => 'test shelf',
'description' => 'shelf desc',
])->assertRedirect('/shelves/test-shelf');
}
]);
$this->post('/books', [
- 'name' => 'test book',
+ 'name' => 'test book',
'description' => 'book desc',
])->assertRedirect('/books/test-book');
}
]);
$this->post($ownBook->getUrl('/create-chapter'), [
- 'name' => 'test chapter',
+ 'name' => 'test chapter',
'description' => 'chapter desc',
])->assertRedirect($ownBook->getUrl('/chapter/test-chapter'));
]);
$this->post($book->getUrl('/create-chapter'), [
- 'name' => 'test chapter',
+ 'name' => 'test chapter',
'description' => 'chapter desc',
])->assertRedirect($book->getUrl('/chapter/test-chapter'));
}
$page = Page::query()->first();
$image = factory(Image::class)->create([
'uploaded_to' => $page->id,
- 'created_by' => $this->user->id,
- 'updated_by' => $this->user->id,
+ 'created_by' => $this->user->id,
+ 'updated_by' => $this->user->id,
]);
$this->actingAs($this->user)->json('delete', '/images/' . $image->id)->assertStatus(403);
private function addComment(Page $page): TestResponse
{
$comment = factory(Comment::class)->make();
+
return $this->postJson("/comment/$page->id", $comment->only('text', 'html'));
}
private function updateComment(Comment $comment): TestResponse
{
$commentData = factory(Comment::class)->make();
+
return $this->putJson("/comment/{$comment->id}", $commentData->only('text', 'html'));
}
/**
* 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
class UserManagementTest extends TestCase
{
-
public function test_user_creation()
{
/** @var User $user */
->assertElementContains('form[action="' . url('/settings/users/create') . '"]', 'Save');
$resp = $this->post('/settings/users/create', [
- 'name' => $user->name,
- 'email' => $user->email,
- 'password' => $user->password,
- 'password-confirm' => $user->password,
+ 'name' => $user->name,
+ 'email' => $user->email,
+ 'password' => $user->password,
+ 'password-confirm' => $user->password,
'roles[' . $adminRole->id . ']' => 'true',
]);
$resp->assertRedirect('/settings/users');
$user = $this->getNormalUser();
$password = $user->password;
-
$resp = $this->asAdmin()->get('/settings/users/' . $user->id);
$resp->assertSee($user->email);
$this->put($user->getEditUrl(), [
- 'name' => 'Barry Scott'
+ 'name' => 'Barry Scott',
])->assertRedirect('/settings/users');
$this->assertDatabaseHas('users', ['id' => $user->id, 'name' => 'Barry Scott', 'password' => $password]);
$this->asAdmin()->get($userProfilePage);
$this->put($userProfilePage, [
- 'password' => 'newpassword'
+ 'password' => 'newpassword',
])->assertRedirect($userProfilePage);
$this->get($userProfilePage)->assertSee('Password confirmation required');
$this->put($userProfilePage, [
- 'password' => 'newpassword',
+ 'password' => 'newpassword',
'password-confirm' => 'newpassword',
])->assertRedirect('/settings/users');
$resp->assertSee('Guest');
$resp->assertElementContains('form[action$="/settings/users/' . $guestUser->id . '"] button', 'Confirm');
- $resp = $this->delete('/settings/users/' . $guestUser->id);
+ $resp = $this->delete('/settings/users/' . $guestUser->id);
$resp->assertRedirect('/settings/users/' . $guestUser->id);
$resp = $this->followRedirects($resp);
$resp->assertSee('cannot delete the guest user');