mirror of
https://github.com/HDInnovations/UNIT3D.git
synced 2026-01-31 01:35:31 +01:00
Update Pest tests
This commit is contained in:
@@ -45,7 +45,7 @@
|
||||
},
|
||||
"require-dev": {
|
||||
"barryvdh/laravel-debugbar": "^3.14.6",
|
||||
"brianium/paratest": "v7.4.0",
|
||||
"brianium/paratest": "^7.6",
|
||||
"calebdw/larastan": "2.10.5",
|
||||
"calebdw/larastan-livewire": "^1.1.0",
|
||||
"fakerphp/faker": "^1.23.1",
|
||||
@@ -54,11 +54,11 @@
|
||||
"laravel/sail": "1.31.1",
|
||||
"mockery/mockery": "^1.6.12",
|
||||
"nunomaduro/collision": "^8.5.0",
|
||||
"pestphp/pest": "^2.35.1",
|
||||
"pestphp/pest-plugin-laravel": "^2.4.0",
|
||||
"pestphp/pest-plugin-livewire": "^v2.1.0",
|
||||
"pestphp/pest": "^3.5",
|
||||
"pestphp/pest-plugin-laravel": "^3.0",
|
||||
"pestphp/pest-plugin-livewire": "^3.0",
|
||||
"phpstan/phpstan": "1.12.0",
|
||||
"phpunit/phpunit": "10.5.17",
|
||||
"phpunit/phpunit": "^11.0",
|
||||
"ryoluo/sail-ssl": "^1.3.2",
|
||||
"spatie/laravel-ignition": "^2.8.0",
|
||||
"tomasvotruba/bladestan": "^0.5.0"
|
||||
|
||||
704
composer.lock
generated
704
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -16,8 +16,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use App\Models\Group;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/** @extends Factory<Group> */
|
||||
class GroupFactory extends Factory
|
||||
@@ -62,4 +62,13 @@ class GroupFactory extends Factory
|
||||
'system_required' => false,
|
||||
];
|
||||
}
|
||||
|
||||
public function owner(): GroupFactory
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'is_owner' => true,
|
||||
'is_admin' => true,
|
||||
'is_modo' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -855,15 +855,15 @@
|
||||
<dl class="key-value">
|
||||
<div class="key-value__group">
|
||||
<dt>1 minute</dt>
|
||||
<dd>{{ $avg['1-minute'] }}</dd>
|
||||
<dd>{{ $avg['1-minute'] ?? 'N/A' }}</dd>
|
||||
</div>
|
||||
<div class="key-value__group">
|
||||
<dt>5 minutes</dt>
|
||||
<dd>{{ $avg['5-minute'] }}</dd>
|
||||
<dd>{{ $avg['5-minute'] ?? 'N/A' }}</dd>
|
||||
</div>
|
||||
<div class="key-value__group">
|
||||
<dt>15 minutes</dt>
|
||||
<dd>{{ $avg['15-minute'] }}</dd>
|
||||
<dd>{{ $avg['15-minute'] ?? 'N/A' }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
35
tests/CreatesUsers.php
Normal file
35
tests/CreatesUsers.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* NOTICE OF LICENSE.
|
||||
*
|
||||
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
|
||||
* The details is bundled with this project in the file LICENSE.txt.
|
||||
*
|
||||
* @project UNIT3D Community Edition
|
||||
*
|
||||
* @author HDVinnie <hdinnovations@protonmail.com>
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
||||
*/
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\Models\Group;
|
||||
use App\Models\User;
|
||||
|
||||
trait CreatesUsers
|
||||
{
|
||||
public function asStaffUser(): static
|
||||
{
|
||||
return $this->actingAs(User::factory()->create([
|
||||
'group_id' => Group::factory()->owner(),
|
||||
]));
|
||||
}
|
||||
|
||||
public function asAuthenticatedUser(): static
|
||||
{
|
||||
return $this->actingAs(User::factory()->create());
|
||||
}
|
||||
}
|
||||
@@ -14,95 +14,94 @@ declare(strict_types=1);
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
||||
*/
|
||||
|
||||
namespace Tests\Feature\Http\Controllers\Staff;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use App\Http\Controllers\Staff\ChatStatusController;
|
||||
use App\Http\Requests\Staff\StoreChatStatusRequest;
|
||||
use App\Http\Requests\Staff\UpdateChatStatusRequest;
|
||||
use App\Models\ChatStatus;
|
||||
use App\Models\Group;
|
||||
use App\Models\User;
|
||||
use Database\Seeders\GroupsTableSeeder;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @see \App\Http\Controllers\Staff\ChatStatusController
|
||||
*/
|
||||
final class ChatStatusControllerTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
use function Pest\Laravel\assertDatabaseHas;
|
||||
|
||||
protected function createStaffUser(): Collection|Model
|
||||
{
|
||||
return User::factory()->create([
|
||||
'group_id' => fn () => Group::factory()->create([
|
||||
'is_owner' => true,
|
||||
'is_admin' => true,
|
||||
'is_modo' => true,
|
||||
])->id,
|
||||
]);
|
||||
}
|
||||
test('create returns an ok response', function (): void {
|
||||
$this->get(route('staff.statuses.create'))
|
||||
->assertOk()
|
||||
->assertViewIs('Staff.chat.status.create');
|
||||
});
|
||||
|
||||
#[Test]
|
||||
public function destroy_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
test('destroy returns an ok response', function (): void {
|
||||
$chatStatus = ChatStatus::factory()->create();
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
$chat_status = ChatStatus::factory()->create();
|
||||
$this->delete(route('staff.statuses.destroy', [$chatStatus]))
|
||||
->assertRedirect(route('staff.statuses.index'))
|
||||
->assertSessionHasNoErrors();
|
||||
|
||||
$response = $this->actingAs($user)->delete(route('staff.statuses.destroy', ['chatStatus' => $chat_status]));
|
||||
$response->assertRedirect(route('staff.statuses.index'));
|
||||
}
|
||||
$this->assertModelMissing($chatStatus);
|
||||
});
|
||||
|
||||
#[Test]
|
||||
public function index_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
test('edit returns an ok response', function (): void {
|
||||
$chatStatus = ChatStatus::factory()->create();
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
$this->get(route('staff.statuses.edit', [$chatStatus]))
|
||||
->assertOk()
|
||||
->assertViewIs('Staff.chat.status.edit')
|
||||
->assertViewHas('chatstatus', $chatStatus);
|
||||
});
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.statuses.index'));
|
||||
test('index returns an ok response', function (): void {
|
||||
ChatStatus::factory()->times(3)->create();
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.chat.status.index');
|
||||
$response->assertViewHas('chatstatuses');
|
||||
}
|
||||
$this->get(route('staff.statuses.index'))
|
||||
->assertOk()
|
||||
->assertViewIs('Staff.chat.status.index')
|
||||
->assertViewHas('chatstatuses');
|
||||
});
|
||||
|
||||
#[Test]
|
||||
public function store_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
test('store validates with a form request', function (): void {
|
||||
$this->assertActionUsesFormRequest(
|
||||
ChatStatusController::class,
|
||||
'store',
|
||||
StoreChatStatusRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
$chat_status = ChatStatus::factory()->make();
|
||||
test('store returns an ok response', function (): void {
|
||||
$chatStatus = ChatStatus::factory()->make();
|
||||
|
||||
$response = $this->actingAs($user)->post(route('staff.statuses.store'), [
|
||||
'name' => $chat_status->name,
|
||||
'color' => $chat_status->color,
|
||||
'icon' => $chat_status->icon,
|
||||
]);
|
||||
$this->post(route('staff.statuses.store'), [
|
||||
'name' => $chatStatus->name,
|
||||
'color' => $chatStatus->color,
|
||||
'icon' => $chatStatus->icon,
|
||||
])
|
||||
->assertRedirect(route('staff.statuses.index'))
|
||||
->assertSessionHasNoErrors();
|
||||
|
||||
$response->assertRedirect(route('staff.statuses.index'));
|
||||
}
|
||||
assertDatabaseHas('chat_statuses', [
|
||||
'name' => $chatStatus->name,
|
||||
'color' => $chatStatus->color,
|
||||
'icon' => $chatStatus->icon,
|
||||
]);
|
||||
});
|
||||
|
||||
#[Test]
|
||||
public function update_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
test('update validates with a form request', function (): void {
|
||||
$this->assertActionUsesFormRequest(
|
||||
ChatStatusController::class,
|
||||
'update',
|
||||
UpdateChatStatusRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
$chat_status = ChatStatus::factory()->create();
|
||||
test('update returns an ok response', function (): void {
|
||||
$chatStatus = ChatStatus::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->post(route('staff.statuses.update', ['chatStatus' => $chat_status]), [
|
||||
'name' => $chat_status->name,
|
||||
'color' => $chat_status->color,
|
||||
'icon' => $chat_status->icon,
|
||||
]);
|
||||
$this->post(route('staff.statuses.update', [$chatStatus]), [
|
||||
'name' => 'new name',
|
||||
'color' => 'black',
|
||||
'icon' => 'cog',
|
||||
])
|
||||
->assertRedirect(route('staff.statuses.index'));
|
||||
|
||||
$response->assertRedirect(route('staff.statuses.index'));
|
||||
}
|
||||
}
|
||||
assertDatabaseHas('chat_statuses', [
|
||||
'name' => 'new name',
|
||||
'color' => 'black',
|
||||
'icon' => 'cog',
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* NOTICE OF LICENSE.
|
||||
*
|
||||
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
|
||||
* The details is bundled with this project in the file LICENSE.txt.
|
||||
*
|
||||
* @project UNIT3D Community Edition
|
||||
*
|
||||
* @author HDVinnie <hdinnovations@protonmail.com>
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
||||
*/
|
||||
|
||||
use App\Http\Controllers\Staff\ChatStatusController;
|
||||
use App\Http\Requests\Staff\StoreChatStatusRequest;
|
||||
use App\Http\Requests\Staff\UpdateChatStatusRequest;
|
||||
use App\Models\ChatStatus;
|
||||
use App\Models\User;
|
||||
|
||||
test('create returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.statuses.create'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.chat.status.create');
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
test('destroy returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$chatStatus = ChatStatus::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->delete(route('staff.statuses.destroy', [$chatStatus]));
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertModelMissing($chatStatus);
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
test('edit returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$chatStatus = ChatStatus::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.statuses.edit', [$chatStatus]));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.chat.status.edit');
|
||||
$response->assertViewHas('chatstatus');
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
test('index returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$chatStatuses = ChatStatus::factory()->times(3)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.statuses.index'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.chat.status.index');
|
||||
$response->assertViewHas('chatstatuses');
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
test('store validates with a form request', function (): void {
|
||||
$this->assertActionUsesFormRequest(
|
||||
ChatStatusController::class,
|
||||
'store',
|
||||
StoreChatStatusRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('store returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->post(route('staff.statuses.store'), [
|
||||
// TODO: send request data
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
test('update validates with a form request', function (): void {
|
||||
$this->assertActionUsesFormRequest(
|
||||
ChatStatusController::class,
|
||||
'update',
|
||||
UpdateChatStatusRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('update returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$chatStatus = ChatStatus::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->post(route('staff.statuses.update', [$chatStatus]), [
|
||||
// TODO: send request data
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
// test cases...
|
||||
@@ -14,155 +14,109 @@ declare(strict_types=1);
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
||||
*/
|
||||
|
||||
namespace Tests\Feature\Http\Controllers\Staff;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use App\Http\Controllers\Staff\GroupController;
|
||||
use App\Http\Requests\Staff\StoreGroupRequest;
|
||||
use App\Http\Requests\Staff\UpdateGroupRequest;
|
||||
use App\Models\Group;
|
||||
use App\Models\User;
|
||||
use Database\Seeders\GroupsTableSeeder;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @see \App\Http\Controllers\Staff\GroupController
|
||||
*/
|
||||
final class GroupControllerTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
use function Pest\Laravel\assertDatabaseHas;
|
||||
|
||||
protected function createStaffUser(): Collection|Model
|
||||
{
|
||||
return User::factory()->create([
|
||||
'group_id' => fn () => Group::factory()->create([
|
||||
'is_owner' => true,
|
||||
'is_admin' => true,
|
||||
'is_modo' => true,
|
||||
])->id,
|
||||
]);
|
||||
}
|
||||
test('create returns an ok response', function (): void {
|
||||
$this->get(route('staff.groups.create'))
|
||||
->assertOk()
|
||||
->assertViewIs('Staff.group.create');
|
||||
});
|
||||
|
||||
#[Test]
|
||||
public function create_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
test('edit returns an ok response', function (): void {
|
||||
$group = Group::factory()->create();
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
$this->get(route('staff.groups.edit', [$group]))
|
||||
->assertOk()
|
||||
->assertViewIs('Staff.group.edit')
|
||||
->assertViewHas('group', $group);
|
||||
});
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.groups.create'));
|
||||
test('index returns an ok response', function (): void {
|
||||
Group::factory()->times(3)->create();
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.group.create');
|
||||
}
|
||||
$this->get(route('staff.groups.index'))
|
||||
->assertOk()
|
||||
->assertViewIs('Staff.group.index')
|
||||
->assertViewHas('groups');
|
||||
});
|
||||
|
||||
#[Test]
|
||||
public function edit_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
test('store validates with a form request', function (): void {
|
||||
$this->assertActionUsesFormRequest(
|
||||
GroupController::class,
|
||||
'store',
|
||||
StoreGroupRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
$group = Group::factory()->create();
|
||||
test('store returns an ok response', function (): void {
|
||||
$group = Group::factory()->make();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.groups.edit', ['group' => $group]));
|
||||
$this->post(route('staff.groups.store'), [
|
||||
'name' => $group->name,
|
||||
'slug' => $group->slug,
|
||||
'position' => $group->position,
|
||||
'level' => $group->level,
|
||||
'color' => $group->color,
|
||||
'icon' => $group->icon,
|
||||
'effect' => $group->effect,
|
||||
'is_uploader' => $group->is_uploader,
|
||||
'is_internal' => $group->is_internal,
|
||||
'is_owner' => $group->is_owner,
|
||||
'is_admin' => $group->is_admin,
|
||||
'is_modo' => $group->is_modo,
|
||||
'is_editor' => $group->is_editor,
|
||||
'is_trusted' => $group->is_trusted,
|
||||
'is_immune' => $group->is_immune,
|
||||
'is_freeleech' => $group->is_freeleech,
|
||||
'is_double_upload' => $group->is_double_upload,
|
||||
'is_refundable' => $group->is_refundable,
|
||||
'can_chat' => $group->can_chat,
|
||||
'can_comment' => $group->can_comment,
|
||||
'can_invite' => $group->can_invite,
|
||||
'can_request' => $group->can_request,
|
||||
'can_upload' => $group->can_upload,
|
||||
'is_incognito' => $group->is_incognito,
|
||||
'autogroup' => $group->autogroup,
|
||||
])
|
||||
->assertRedirect(route('staff.groups.index'))
|
||||
->assertSessionHasNoErrors();
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.group.edit');
|
||||
$response->assertViewHas('group');
|
||||
}
|
||||
assertDatabaseHas('groups', [
|
||||
'name' => $group->name,
|
||||
'slug' => $group->slug,
|
||||
'position' => $group->position,
|
||||
]);
|
||||
});
|
||||
|
||||
#[Test]
|
||||
public function index_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
test('update validates with a form request', function (): void {
|
||||
$this->assertActionUsesFormRequest(
|
||||
GroupController::class,
|
||||
'update',
|
||||
UpdateGroupRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
test('update returns an ok response', function (): void {
|
||||
$group = Group::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.groups.index'));
|
||||
$this->patch(route('staff.groups.update', ['group' => $group]), [
|
||||
'name' => 'new name',
|
||||
'slug' => 'new-slug',
|
||||
'position' => -2,
|
||||
'level' => 1000,
|
||||
])
|
||||
->assertRedirect(route('staff.groups.index'))
|
||||
->assertSessionHasNoErrors();
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.group.index');
|
||||
$response->assertViewHas('groups');
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function store_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
$group = Group::factory()->make();
|
||||
|
||||
$response = $this->actingAs($user)->post(route('staff.groups.store'), [
|
||||
'name' => $group->name,
|
||||
'slug' => $group->slug,
|
||||
'position' => $group->position,
|
||||
'level' => $group->level,
|
||||
'color' => $group->color,
|
||||
'icon' => $group->icon,
|
||||
'effect' => $group->effect,
|
||||
'is_uploader' => $group->is_uploader,
|
||||
'is_internal' => $group->is_internal,
|
||||
'is_owner' => $group->is_owner,
|
||||
'is_admin' => $group->is_admin,
|
||||
'is_modo' => $group->is_modo,
|
||||
'is_editor' => $group->is_editor,
|
||||
'is_trusted' => $group->is_trusted,
|
||||
'is_immune' => $group->is_immune,
|
||||
'is_freeleech' => $group->is_freeleech,
|
||||
'is_double_upload' => $group->is_double_upload,
|
||||
'is_refundable' => $group->is_refundable,
|
||||
'can_chat' => $group->can_chat,
|
||||
'can_comment' => $group->can_comment,
|
||||
'can_invite' => $group->can_invite,
|
||||
'can_request' => $group->can_request,
|
||||
'can_upload' => $group->can_upload,
|
||||
'is_incognito' => $group->is_incognito,
|
||||
'autogroup' => $group->autogroup,
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('staff.groups.index'));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function update_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
$group = Group::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->patch(route('staff.groups.update', ['group' => $group]), [
|
||||
'name' => $group->name,
|
||||
'slug' => $group->slug,
|
||||
'position' => $group->position,
|
||||
'level' => $group->level,
|
||||
'color' => $group->color,
|
||||
'icon' => $group->icon,
|
||||
'effect' => $group->effect,
|
||||
'is_uploader' => $group->is_uploader,
|
||||
'is_internal' => $group->is_internal,
|
||||
'is_owner' => $group->is_owner,
|
||||
'is_admin' => $group->is_admin,
|
||||
'is_modo' => $group->is_modo,
|
||||
'is_editor' => $group->is_editor,
|
||||
'is_trusted' => $group->is_trusted,
|
||||
'is_immune' => $group->is_immune,
|
||||
'is_freeleech' => $group->is_freeleech,
|
||||
'is_double_upload' => $group->is_double_upload,
|
||||
'is_refundable' => $group->is_refundable,
|
||||
'can_chat' => $group->can_chat,
|
||||
'can_comment' => $group->can_comment,
|
||||
'can_invite' => $group->can_invite,
|
||||
'can_request' => $group->can_request,
|
||||
'can_upload' => $group->can_upload,
|
||||
'is_incognito' => $group->is_incognito,
|
||||
'autogroup' => $group->autogroup,
|
||||
'system_required' => $group->system_required,
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('staff.groups.index'));
|
||||
}
|
||||
}
|
||||
assertDatabaseHas('groups', [
|
||||
'name' => 'new name',
|
||||
'slug' => 'new-slug',
|
||||
'position' => -2,
|
||||
'level' => 1000,
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* NOTICE OF LICENSE.
|
||||
*
|
||||
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
|
||||
* The details is bundled with this project in the file LICENSE.txt.
|
||||
*
|
||||
* @project UNIT3D Community Edition
|
||||
*
|
||||
* @author HDVinnie <hdinnovations@protonmail.com>
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
||||
*/
|
||||
|
||||
use App\Http\Controllers\Staff\GroupController;
|
||||
use App\Http\Requests\Staff\StoreGroupRequest;
|
||||
use App\Http\Requests\Staff\UpdateGroupRequest;
|
||||
use App\Models\Group;
|
||||
use App\Models\User;
|
||||
|
||||
test('create returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.groups.create'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.group.create');
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
test('edit returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$group = Group::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.groups.edit', [$group]));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.group.edit');
|
||||
$response->assertViewHas('group', $group);
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
test('index returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$groups = Group::factory()->times(3)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.groups.index'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.group.index');
|
||||
$response->assertViewHas('groups', $groups);
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
test('store validates with a form request', function (): void {
|
||||
$this->assertActionUsesFormRequest(
|
||||
GroupController::class,
|
||||
'store',
|
||||
StoreGroupRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('store returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->post(route('staff.groups.store'), [
|
||||
// TODO: send request data
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
test('update validates with a form request', function (): void {
|
||||
$this->assertActionUsesFormRequest(
|
||||
GroupController::class,
|
||||
'update',
|
||||
UpdateGroupRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('update returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$group = Group::factory()->create();
|
||||
$users = User::factory()->times(3)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->patch(route('staff.groups.update', [$group]), [
|
||||
// TODO: send request data
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
// test cases...
|
||||
@@ -15,21 +15,18 @@ declare(strict_types=1);
|
||||
*/
|
||||
|
||||
use App\Models\User;
|
||||
use Database\Seeders\GroupsTableSeeder;
|
||||
|
||||
test('index returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.dashboard.index'));
|
||||
$response = $this->get('/dashboard');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.dashboard.index');
|
||||
$response->assertViewHas('users');
|
||||
$response->assertViewHas('torrents');
|
||||
$response->assertViewHas('peers');
|
||||
$response->assertViewHas('reports');
|
||||
$response->assertViewHas('apps');
|
||||
$response->assertViewHas('certificate');
|
||||
$response->assertViewHas('uptime');
|
||||
$response->assertViewHas('ram');
|
||||
@@ -37,8 +34,10 @@ test('index returns an ok response', function (): void {
|
||||
$response->assertViewHas('avg');
|
||||
$response->assertViewHas('basic');
|
||||
$response->assertViewHas('file_permissions');
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
// test cases...
|
||||
test('dashboard is not available to regular users', function (): void {
|
||||
$this->actingAs(User::factory()->create())
|
||||
->get('/dashboard')
|
||||
->assertForbidden();
|
||||
});
|
||||
|
||||
@@ -14,76 +14,50 @@ declare(strict_types=1);
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
||||
*/
|
||||
|
||||
namespace Tests\Feature\Http\Controllers\Staff;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use App\Http\Controllers\Staff\MassActionController;
|
||||
use App\Http\Requests\Staff\StoreMassActionRequest;
|
||||
use App\Models\Group;
|
||||
use App\Models\PrivateMessage;
|
||||
use App\Models\User;
|
||||
use Database\Seeders\GroupsTableSeeder;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @see \App\Http\Controllers\Staff\MassActionController
|
||||
*/
|
||||
final class MassActionControllerTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
test('create returns an ok response', function (): void {
|
||||
$response = $this->get(route('staff.mass-pm.create'));
|
||||
|
||||
protected function createStaffUser(): Collection|Model
|
||||
{
|
||||
return User::factory()->create([
|
||||
'group_id' => fn () => Group::factory()->create([
|
||||
'is_owner' => true,
|
||||
'is_admin' => true,
|
||||
'is_modo' => true,
|
||||
])->id,
|
||||
]);
|
||||
}
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.masspm.index');
|
||||
});
|
||||
|
||||
#[Test]
|
||||
public function create_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
test('store validates with a form request', function (): void {
|
||||
$this->assertActionUsesFormRequest(
|
||||
MassActionController::class,
|
||||
'store',
|
||||
StoreMassActionRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
test('store returns an ok response', function (): void {
|
||||
$message = PrivateMessage::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.mass-pm.create'));
|
||||
$response = $this->post(route('staff.mass-pm.store'), [
|
||||
'subject' => $message->conversation->subject,
|
||||
'message' => $message->message,
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.masspm.index');
|
||||
}
|
||||
$response->assertRedirect(route('staff.mass-pm.create'))
|
||||
->assertSessionHasNoErrors();
|
||||
});
|
||||
|
||||
#[Test]
|
||||
public function store_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
test('update returns an ok response', function (): void {
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
User::factory()->times(3)->create([
|
||||
'email_verified_at' => null,
|
||||
'group_id' => Group::firstWhere('slug', 'validating')
|
||||
]);
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
$message = PrivateMessage::factory()->create();
|
||||
$this->get(route('staff.mass-actions.validate'))
|
||||
->assertRedirect(route('staff.dashboard.index'));
|
||||
|
||||
$response = $this->actingAs($user)->post(route('staff.mass-pm.store'), [
|
||||
'subject' => $message->conversation->subject,
|
||||
'message' => $message->message,
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('staff.mass-pm.create'));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function update_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.mass-actions.validate'));
|
||||
|
||||
$response->assertRedirect(route('staff.dashboard.index'));
|
||||
}
|
||||
}
|
||||
expect(User::where('email_verified_at', '=', null)->count())
|
||||
->toBe(0, 'All users should be validated');
|
||||
});
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* NOTICE OF LICENSE.
|
||||
*
|
||||
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
|
||||
* The details is bundled with this project in the file LICENSE.txt.
|
||||
*
|
||||
* @project UNIT3D Community Edition
|
||||
*
|
||||
* @author HDVinnie <hdinnovations@protonmail.com>
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
||||
*/
|
||||
|
||||
use App\Http\Controllers\Staff\MassActionController;
|
||||
use App\Http\Requests\Staff\StoreMassActionRequest;
|
||||
use App\Models\User;
|
||||
|
||||
test('create returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.mass-pm.create'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.masspm.index');
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
test('store validates with a form request', function (): void {
|
||||
$this->assertActionUsesFormRequest(
|
||||
MassActionController::class,
|
||||
'store',
|
||||
StoreMassActionRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('store returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->post(route('staff.mass-pm.store'), [
|
||||
// TODO: send request data
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
test('update returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$users = User::factory()->times(3)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.mass-actions.validate'));
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
// test cases...
|
||||
@@ -14,122 +14,98 @@ declare(strict_types=1);
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
||||
*/
|
||||
|
||||
namespace Tests\Feature\Http\Controllers\Staff;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use App\Models\Group;
|
||||
use App\Http\Controllers\Staff\PageController;
|
||||
use App\Http\Requests\Staff\StorePageRequest;
|
||||
use App\Http\Requests\Staff\UpdatePageRequest;
|
||||
use App\Models\Page;
|
||||
use App\Models\User;
|
||||
use Database\Seeders\GroupsTableSeeder;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @see \App\Http\Controllers\Staff\PageController
|
||||
*/
|
||||
final class PageControllerTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
use function Pest\Laravel\assertDatabaseHas;
|
||||
|
||||
protected function createStaffUser(): Collection|Model
|
||||
{
|
||||
return User::factory()->create([
|
||||
'group_id' => fn () => Group::factory()->create([
|
||||
'is_owner' => true,
|
||||
'is_admin' => true,
|
||||
'is_modo' => true,
|
||||
])->id,
|
||||
]);
|
||||
}
|
||||
test('create returns an ok response', function (): void {
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
|
||||
#[Test]
|
||||
public function create_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
$this->get(route('staff.pages.create'))
|
||||
->assertOk()
|
||||
->assertViewIs('Staff.page.create');
|
||||
});
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
test('destroy returns an ok response', function (): void {
|
||||
$page = Page::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.pages.create'));
|
||||
$this->delete(route('staff.pages.destroy', ['page' => $page]))
|
||||
->assertRedirect(route('staff.pages.index'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.page.create');
|
||||
}
|
||||
$this->assertModelMissing($page);
|
||||
});
|
||||
|
||||
#[Test]
|
||||
public function destroy_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
test('edit returns an ok response', function (): void {
|
||||
$page = Page::factory()->create();
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
$page = Page::factory()->create();
|
||||
$this->get(route('staff.pages.edit', ['page' => $page]))
|
||||
->assertOk()
|
||||
->assertViewIs('Staff.page.edit')
|
||||
->assertViewHas('page');
|
||||
});
|
||||
|
||||
$response = $this->actingAs($user)->delete(route('staff.pages.destroy', ['page' => $page]));
|
||||
test('index returns an ok response', function (): void {
|
||||
$pages = Page::factory()->times(3)->create();
|
||||
|
||||
$response->assertRedirect(route('staff.pages.index'));
|
||||
}
|
||||
$this->get(route('staff.pages.index'))
|
||||
->assertOk()
|
||||
->assertViewIs('Staff.page.index')
|
||||
->assertViewHas('pages', $pages);
|
||||
});
|
||||
|
||||
#[Test]
|
||||
public function edit_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
test('store validates with a form request', function (): void {
|
||||
$this->assertActionUsesFormRequest(
|
||||
PageController::class,
|
||||
'store',
|
||||
StorePageRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
$page = Page::factory()->create();
|
||||
test('store returns an ok response', function (): void {
|
||||
$page = Page::factory()->make();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.pages.edit', ['page' => $page]));
|
||||
$this->post(route('staff.pages.store'), [
|
||||
'name' => $page->name,
|
||||
'content' => $page->content,
|
||||
])
|
||||
->assertRedirect(route('staff.pages.index'))
|
||||
->assertSessionHasNoErrors();
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.page.edit');
|
||||
$response->assertViewHas('page');
|
||||
}
|
||||
assertDatabaseHas('pages', [
|
||||
'name' => $page->name,
|
||||
'content' => $page->content,
|
||||
]);
|
||||
});
|
||||
|
||||
#[Test]
|
||||
public function index_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
test('update validates with a form request', function (): void {
|
||||
$this->assertActionUsesFormRequest(
|
||||
PageController::class,
|
||||
'update',
|
||||
UpdatePageRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
test('update returns an ok response', function (): void {
|
||||
$page = Page::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.pages.index'));
|
||||
$name = fake()->name;
|
||||
$content = fake()->text;
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.page.index');
|
||||
$response->assertViewHas('pages');
|
||||
}
|
||||
$this->patch(route('staff.pages.update', ['page' => $page]), [
|
||||
'name' => $name,
|
||||
'content' => $content,
|
||||
])
|
||||
->assertRedirect(route('staff.pages.index'))
|
||||
->assertSessionHasNoErrors();
|
||||
|
||||
#[Test]
|
||||
public function store_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
$page->refresh();
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
$page = Page::factory()->make();
|
||||
|
||||
$response = $this->actingAs($user)->post(route('staff.pages.store'), [
|
||||
'name' => $page->name,
|
||||
'content' => $page->content,
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('staff.pages.index'));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function update_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
$page = Page::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->patch(route('staff.pages.update', ['page' => $page]), [
|
||||
'name' => $page->name,
|
||||
'content' => $page->content,
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('staff.pages.index'));
|
||||
}
|
||||
}
|
||||
expect($page->name)
|
||||
->toBe($name)
|
||||
->and($page->content)
|
||||
->toBe($content);
|
||||
});
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* NOTICE OF LICENSE.
|
||||
*
|
||||
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
|
||||
* The details is bundled with this project in the file LICENSE.txt.
|
||||
*
|
||||
* @project UNIT3D Community Edition
|
||||
*
|
||||
* @author HDVinnie <hdinnovations@protonmail.com>
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
||||
*/
|
||||
|
||||
use App\Http\Controllers\Staff\PageController;
|
||||
use App\Http\Requests\Staff\StorePageRequest;
|
||||
use App\Http\Requests\Staff\UpdatePageRequest;
|
||||
use App\Models\Page;
|
||||
use App\Models\User;
|
||||
|
||||
test('create returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.pages.create'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.page.create');
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
test('destroy returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$page = Page::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->delete(route('staff.pages.destroy', [$page]));
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertModelMissing($page);
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
test('edit returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$page = Page::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.pages.edit', [$page]));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.page.edit');
|
||||
$response->assertViewHas('page', $page);
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
test('index returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$pages = Page::factory()->times(3)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.pages.index'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.page.index');
|
||||
$response->assertViewHas('pages', $pages);
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
test('store validates with a form request', function (): void {
|
||||
$this->assertActionUsesFormRequest(
|
||||
PageController::class,
|
||||
'store',
|
||||
StorePageRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('store returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->post(route('staff.pages.store'), [
|
||||
// TODO: send request data
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
test('update validates with a form request', function (): void {
|
||||
$this->assertActionUsesFormRequest(
|
||||
PageController::class,
|
||||
'update',
|
||||
UpdatePageRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('update returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$page = Page::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->patch(route('staff.pages.update', [$page]), [
|
||||
// TODO: send request data
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
// test cases...
|
||||
@@ -14,122 +14,91 @@ declare(strict_types=1);
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
||||
*/
|
||||
|
||||
namespace Tests\Feature\Http\Controllers\Staff;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use App\Models\Group;
|
||||
use App\Http\Controllers\Staff\TypeController;
|
||||
use App\Http\Requests\Staff\StoreTypeRequest;
|
||||
use App\Http\Requests\Staff\UpdateTypeRequest;
|
||||
use App\Models\Type;
|
||||
use App\Models\User;
|
||||
use Database\Seeders\GroupsTableSeeder;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @see \App\Http\Controllers\Staff\TypeController
|
||||
*/
|
||||
final class TypeControllerTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
use function Pest\Laravel\assertDatabaseHas;
|
||||
|
||||
protected function createStaffUser(): Collection|Model
|
||||
{
|
||||
return User::factory()->create([
|
||||
'group_id' => fn () => Group::factory()->create([
|
||||
'is_owner' => true,
|
||||
'is_admin' => true,
|
||||
'is_modo' => true,
|
||||
])->id,
|
||||
]);
|
||||
}
|
||||
test('create returns an ok response', function (): void {
|
||||
$this->get(route('staff.types.create'))
|
||||
->assertOk()
|
||||
->assertViewIs('Staff.type.create');
|
||||
});
|
||||
|
||||
#[Test]
|
||||
public function create_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
test('destroy returns an ok response', function (): void {
|
||||
$type = Type::factory()->create();
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
$this->delete(route('staff.types.destroy', [$type]))
|
||||
->assertRedirect(route('staff.types.index'))
|
||||
->assertSessionHasNoErrors();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.types.create'));
|
||||
$this->assertModelMissing($type);
|
||||
});
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.type.create');
|
||||
}
|
||||
test('edit returns an ok response', function (): void {
|
||||
$type = Type::factory()->create();
|
||||
|
||||
#[Test]
|
||||
public function destroy_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
$this->get(route('staff.types.edit', [$type]))
|
||||
->assertOk()
|
||||
->assertViewIs('Staff.type.edit')
|
||||
->assertViewHas('type', $type);
|
||||
});
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
$type = Type::factory()->create();
|
||||
test('index returns an ok response', function (): void {
|
||||
Type::factory()->times(3)->create();
|
||||
|
||||
$response = $this->actingAs($user)->delete(route('staff.types.destroy', ['type' => $type]));
|
||||
$this->get(route('staff.types.index'))
|
||||
->assertOk()
|
||||
->assertViewIs('Staff.type.index')
|
||||
->assertViewHas('types');
|
||||
});
|
||||
|
||||
$response->assertRedirect(route('staff.types.index'));
|
||||
}
|
||||
test('store validates with a form request', function (): void {
|
||||
$this->assertActionUsesFormRequest(
|
||||
TypeController::class,
|
||||
'store',
|
||||
StoreTypeRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
#[Test]
|
||||
public function edit_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
test('store returns an ok response', function (): void {
|
||||
$type = Type::factory()->make();
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
$type = Type::factory()->create();
|
||||
$response = $this->post(route('staff.types.store'), [
|
||||
'name' => $type->name,
|
||||
'position' => $type->position,
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.types.edit', ['type' => $type]));
|
||||
$response->assertRedirect(route('staff.types.index'))->assertSessionHasNoErrors();
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.type.edit');
|
||||
$response->assertViewHas('type');
|
||||
}
|
||||
assertDatabaseHas('types', [
|
||||
'name' => $type->name,
|
||||
'position' => $type->position,
|
||||
]);
|
||||
});
|
||||
|
||||
#[Test]
|
||||
public function index_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
test('update validates with a form request', function (): void {
|
||||
$this->assertActionUsesFormRequest(
|
||||
TypeController::class,
|
||||
'update',
|
||||
UpdateTypeRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
test('update returns an ok response', function (): void {
|
||||
$type = Type::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.types.index'));
|
||||
$response = $this->patch(route('staff.types.update', ['type' => $type]), [
|
||||
'name' => 'test_name',
|
||||
'position' => 999,
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.type.index');
|
||||
$response->assertViewHas('types');
|
||||
}
|
||||
$response->assertRedirect(route('staff.types.index'))->assertSessionHasNoErrors();
|
||||
|
||||
#[Test]
|
||||
public function store_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
$type = Type::factory()->make();
|
||||
|
||||
$response = $this->actingAs($user)->post(route('staff.types.store'), [
|
||||
'name' => $type->name,
|
||||
'position' => $type->position,
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('staff.types.index'));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function update_returns_an_ok_response(): void
|
||||
{
|
||||
$this->seed(GroupsTableSeeder::class);
|
||||
|
||||
$user = $this->createStaffUser();
|
||||
$type = Type::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->patch(route('staff.types.update', ['type' => $type]), [
|
||||
'name' => $type->name,
|
||||
'position' => $type->position,
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('staff.types.index'));
|
||||
}
|
||||
}
|
||||
assertDatabaseHas('types', [
|
||||
'name' => 'test_name',
|
||||
'position' => 999,
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* NOTICE OF LICENSE.
|
||||
*
|
||||
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
|
||||
* The details is bundled with this project in the file LICENSE.txt.
|
||||
*
|
||||
* @project UNIT3D Community Edition
|
||||
*
|
||||
* @author HDVinnie <hdinnovations@protonmail.com>
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
||||
*/
|
||||
|
||||
use App\Http\Controllers\Staff\TypeController;
|
||||
use App\Http\Requests\Staff\StoreTypeRequest;
|
||||
use App\Http\Requests\Staff\UpdateTypeRequest;
|
||||
use App\Models\Type;
|
||||
use App\Models\User;
|
||||
|
||||
test('create returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.types.create'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.type.create');
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
test('destroy returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$type = Type::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->delete(route('staff.types.destroy', [$type]));
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertModelMissing($type);
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
test('edit returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$type = Type::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.types.edit', [$type]));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.type.edit');
|
||||
$response->assertViewHas('type', $type);
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
test('index returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$types = Type::factory()->times(3)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('staff.types.index'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewIs('Staff.type.index');
|
||||
$response->assertViewHas('types', $types);
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
test('store validates with a form request', function (): void {
|
||||
$this->assertActionUsesFormRequest(
|
||||
TypeController::class,
|
||||
'store',
|
||||
StoreTypeRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('store returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->post(route('staff.types.store'), [
|
||||
// TODO: send request data
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
test('update validates with a form request', function (): void {
|
||||
$this->assertActionUsesFormRequest(
|
||||
TypeController::class,
|
||||
'update',
|
||||
UpdateTypeRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('update returns an ok response', function (): void {
|
||||
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
|
||||
|
||||
$type = Type::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->patch(route('staff.types.update', [$type]), [
|
||||
// TODO: send request data
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
// TODO: perform additional assertions
|
||||
});
|
||||
|
||||
// test cases...
|
||||
@@ -12,10 +12,14 @@ declare(strict_types=1);
|
||||
|
|
||||
*/
|
||||
|
||||
uses(
|
||||
pest()->extend(
|
||||
Tests\TestCase::class,
|
||||
)->in('Feature', 'Unit');
|
||||
|
||||
pest()->beforeEach(function (): void {
|
||||
$this->asStaffUser();
|
||||
})->in('Feature/Http/Controllers/Staff');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Expectations
|
||||
|
||||
@@ -24,6 +24,7 @@ abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
use AdditionalAssertions;
|
||||
use CreatesApplication;
|
||||
use CreatesUsers;
|
||||
use LazilyRefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
|
||||
Reference in New Issue
Block a user