Files
thrillwiki_laravel/tests/Feature/OperatorTest.php
pacnpal cc33781245 feat: Implement rides management with CRUD functionality
- Added rides index view with search and filter options.
- Created rides show view to display ride details.
- Implemented API routes for rides.
- Developed authentication routes for user registration, login, and email verification.
- Created tests for authentication, email verification, password reset, and user profile management.
- Added feature tests for rides and operators, including creation, updating, deletion, and searching.
- Implemented soft deletes and caching for rides and operators.
- Enhanced manufacturer and operator model tests for various functionalities.
2025-06-19 22:34:10 -04:00

101 lines
2.5 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Operator;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
/**
* Operator Model Feature Tests
*
* Tests for ThrillWiki Operator model functionality
*/
class OperatorTest extends TestCase
{
use RefreshDatabase, WithFaker;
/**
* Test model creation.
*/
public function test_can_create_operator(): void
{
$operator = Operator::factory()->create();
$this->assertDatabaseHas('operators', [
'id' => $operator->id,
'name' => $operator->name,
]);
}
/**
* Test model factory.
*/
public function test_operator_factory_works(): void
{
$operator = Operator::factory()->create();
$this->assertInstanceOf(Operator::class, $operator);
$this->assertNotEmpty($operator->name);
$this->assertIsBool($operator->is_active);
}
/**
* Test active scope.
*/
public function test_active_scope_filters_correctly(): void
{
Operator::factory()->active()->create();
Operator::factory()->inactive()->create();
$activeCount = Operator::active()->count();
$totalCount = Operator::count();
$this->assertEquals(1, $activeCount);
$this->assertEquals(2, $totalCount);
}
/**
* Test cache key generation.
*/
public function test_cache_key_generation(): void
{
$operator = Operator::factory()->create();
$cacheKey = $operator->getCacheKey();
$expectedKey = strtolower('operator') . '.' . $operator->id;
$this->assertEquals($expectedKey, $cacheKey);
}
/**
* Test cache key with suffix.
*/
public function test_cache_key_with_suffix(): void
{
$operator = Operator::factory()->create();
$cacheKey = $operator->getCacheKey('details');
$expectedKey = strtolower('operator') . '.' . $operator->id . '.details';
$this->assertEquals($expectedKey, $cacheKey);
}
/**
* Test soft deletes.
*/
public function test_soft_deletes_work(): void
{
$operator = Operator::factory()->create();
$operator->delete();
$this->assertSoftDeleted($operator);
// Test that it's excluded from normal queries
$this->assertEquals(0, Operator::count());
// Test that it's included in withTrashed queries
$this->assertEquals(1, Operator::withTrashed()->count());
}
}