Files
UNIT3D-Community-Edition/tests/Feature/Http/Controllers/Staff/MassActionControllerTest.php
T
2024-05-23 13:58:29 +00:00

94 lines
2.6 KiB
PHP

<?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\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\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();
}
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]
public function create_returns_an_ok_response(): void
{
$this->seed(GroupsTableSeeder::class);
$user = $this->createStaffUser();
$response = $this->actingAs($user)->get(route('staff.mass-pm.create'));
$response->assertOk();
$response->assertViewIs('Staff.masspm.index');
}
#[Test]
public function store_returns_an_ok_response(): void
{
$this->seed(GroupsTableSeeder::class);
$user = $this->createStaffUser();
$message = PrivateMessage::factory()->create();
$response = $this->actingAs($user)->post(route('staff.mass-pm.store'), [
'sender_id' => $user->id,
'receiver_id' => $message->receiver_id,
'subject' => $message->subject,
'message' => $message->message,
'read' => $message->read,
'related_to' => $message->related_to,
]);
$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'));
}
}