first commit

This commit is contained in:
2026-05-22 20:46:29 +08:00
commit b04f87f2b0
121 changed files with 14851 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
<?php
namespace Tests\Feature;
// use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*/
public function test_the_application_returns_a_successful_response(): void
{
$response = $this->get('/');
$response->assertStatus(302);
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use App\Models\User;
use App\Models\Survey;
use Illuminate\Support\Str;
class SurveyUuidTest extends TestCase
{
use RefreshDatabase;
// Actually, local test setup might use sqlite in memory. Let's assume standard Laravel test setup.
// Given the user is running `php artisan test` successfully, safe to use.
public function test_survey_generates_uuid_on_creation(): void
{
$user = User::factory()->create();
$survey = Survey::create([
'title' => 'Test Survey',
'date' => '2025-01-01',
'user_id' => $user->id,
]);
$this->assertNotEmpty($survey->uuid);
$this->assertTrue(Str::isUuid($survey->uuid));
}
public function test_public_can_access_survey_via_uuid(): void
{
$user = User::factory()->create();
$survey = Survey::create([
'title' => 'UUID Survey',
'date' => '2025-01-01',
'user_id' => $user->id,
]);
$response = $this->get(route('surveys.show', $survey)); // Should use UUID
$response->assertStatus(200);
$response->assertSee('UUID Survey');
}
public function test_public_cannot_access_survey_via_id(): void
{
$user = User::factory()->create();
$survey = Survey::create([
'title' => 'ID Survey',
'date' => '2025-01-01',
'user_id' => $user->id,
]);
// Construct URL manually with ID
$response = $this->get('/survey/' . $survey->id);
$response->assertStatus(404);
}
}

10
tests/TestCase.php Normal file
View File

@@ -0,0 +1,10 @@
<?php
namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
//
}

View File

@@ -0,0 +1,16 @@
<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*/
public function test_that_true_is_true(): void
{
$this->assertTrue(true);
}
}