Mercurial > packages > magicforger
comparison src/Generator/Test/stubs/test.stub @ 45:c7fd31303024 default tip
merging down to default
| author | Luka Sitas <sitas.luka.97@gmail.com> |
|---|---|
| date | Thu, 12 Nov 2026 21:19:53 -0500 |
| parents | 2cf26b593f4a |
| children |
comparison
equal
deleted
inserted
replaced
| 34:f65ab84ee47f | 45:c7fd31303024 |
|---|---|
| 1 <?php | |
| 2 | |
| 3 namespace Tests\CRUD; | |
| 4 | |
| 5 use {{ namespacedModel }}; | |
| 6 use Illuminate\Database\Eloquent\Factories\HasFactory; | |
| 7 use App\Models\User; | |
| 8 use Wizard\Framework\Tests\TestCase; | |
| 9 | |
| 10 class {{ class }} extends TestCase | |
| 11 { | |
| 12 /* use RefreshDatabase; */ | |
| 13 | |
| 14 public function test_{{ modelVariable }}_crud_index_access(): void | |
| 15 { | |
| 16 $response = $this | |
| 17 ->get(route('{{ tableName }}.index')); | |
| 18 | |
| 19 $response->assertStatus(200); | |
| 20 } | |
| 21 | |
| 22 public function test_{{ modelVariable }}_crud_get_data_access(): void | |
| 23 { | |
| 24 $response = $this | |
| 25 ->post(route('{{ tableName }}.get_data')); | |
| 26 | |
| 27 $response->assertStatus(200); | |
| 28 } | |
| 29 | |
| 30 public function test_{{ modelVariable }}_crud_create_access(): void | |
| 31 { | |
| 32 $response = $this | |
| 33 ->get(route('{{ tableName }}.create')); | |
| 34 | |
| 35 $response->assertStatus(200); | |
| 36 } | |
| 37 | |
| 38 public function test_{{ modelVariable }}_crud_edit_access(): void | |
| 39 { | |
| 40 $item = {{ model }}::factory()->create(); | |
| 41 | |
| 42 $response = $this | |
| 43 ->get(route('{{ tableName }}.edit', $item)); | |
| 44 | |
| 45 $response->assertStatus(200); | |
| 46 } | |
| 47 | |
| 48 public function test_{{ modelVariable }}_crud_create_usage(): void | |
| 49 { | |
| 50 $item = {{ model }}::factory()->make(); | |
| 51 | |
| 52 $response = $this | |
| 53 ->from(route('{{ tableName }}.create')) | |
| 54 ->post(route('{{ tableName }}.store'), | |
| 55 $item->toArray() | |
| 56 ); | |
| 57 | |
| 58 $response | |
| 59 ->assertSessionHasNoErrors() | |
| 60 ->assertRedirect(route('{{ tableName }}.index')); | |
| 61 | |
| 62 $this->assertDatabaseHas('{{ tableName }}', $item->toArray()); | |
| 63 } | |
| 64 | |
| 65 public function test_{{ modelVariable }}_crud_create_invalid_data(): void | |
| 66 { | |
| 67 $response = $this | |
| 68 ->from(route('{{ tableName }}.create')) | |
| 69 ->post(route('{{ tableName }}.store'), []); | |
| 70 | |
| 71 $response | |
| 72 ->assertSessionHasErrors() | |
| 73 ->assertRedirect(route('{{ tableName }}.create')); | |
| 74 | |
| 75 // Make sure no entry was added | |
| 76 $this->assertDatabaseCount('{{ tableName }}', 0); | |
| 77 } | |
| 78 | |
| 79 public function test_{{ modelVariable }}_crud_update_usage(): void | |
| 80 { | |
| 81 $item = {{ model }}::factory()->create(); | |
| 82 | |
| 83 $updateData = {{ model }}::factory()->make()->toArray(); | |
| 84 | |
| 85 $response = $this | |
| 86 ->from(route('{{ tableName }}.edit', $item)) | |
| 87 ->put(route('{{ tableName }}.update', $item), $updateData); | |
| 88 | |
| 89 $response | |
| 90 ->assertSessionHasNoErrors() | |
| 91 ->assertRedirect(route('{{ tableName }}.index')); | |
| 92 | |
| 93 $this->assertDatabaseHas('{{ tableName }}', $updateData); | |
| 94 } | |
| 95 | |
| 96 public function test_{{ modelVariable }}_crud_edit_invalid_data(): void | |
| 97 { | |
| 98 $item = {{ model }}::factory()->create(); | |
| 99 | |
| 100 $response = $this | |
| 101 ->from(route('{{ tableName }}.edit', $item)) | |
| 102 ->put(route('{{ tableName }}.update', $item), []); | |
| 103 | |
| 104 $response | |
| 105 ->assertSessionHasErrors() | |
| 106 ->assertRedirect(route('{{ tableName }}.edit', $item)); | |
| 107 | |
| 108 // Make sure no entry was added | |
| 109 $this->assertDatabaseHas('{{ tableName }}', array_intersect_key($item->toArray(), array_flip($item->getFillable()))); | |
| 110 } | |
| 111 | |
| 112 public function test_{{ modelVariable }}_crud_delete_usage(): void | |
| 113 { | |
| 114 $item = {{ model }}::factory()->create(); | |
| 115 | |
| 116 $response = $this | |
| 117 ->delete(route('{{ tableName }}.destroy', $item)); | |
| 118 | |
| 119 $response | |
| 120 ->assertSessionHasNoErrors() | |
| 121 ->assertRedirect(route('{{ tableName }}.index')); | |
| 122 | |
| 123 $this->assertSoftDeleted('{{ tableName }}', [ | |
| 124 'id' => $item->id, | |
| 125 ]); | |
| 126 } | |
| 127 | |
| 128 } |
