File manager - Edit - /var/www/html/spdc/api/tests/Feature/FieldTest.php
Back
<?php namespace Tests\Feature; use Tests\BaseTest; use App\Models\Field; use App\Models\Validation; use Illuminate\Http\JsonResponse; use AluisioPires\LaravelBaseTest\BaseTestTransactions; class FieldTest extends BaseTest { public function test_index() { // deleting existing fields Field::query()->delete(); // creating two fields Field::factory(2)->create(); $response = $this->authRequest( 'get', route('field.index'), JsonResponse::HTTP_OK ); $response->assertJsonCount(2, 'data.data'); } public function test_index_with_search() { // deleting existing fields Field::query()->delete(); // creating two fields $fields = Field::factory(2)->create(); $searchTerm = substr($fields[0]->label, strlen($fields[0]->label) - 3, strlen($fields[0]->label)); $response = $this->authRequest( 'get', route('field.index', [ 'search_term' => $searchTerm ]), JsonResponse::HTTP_OK ); } public function test_index_without_pages() { // deleting existing fields Field::query()->delete(); // creating two fields Field::factory(2)->create(); $response = $this->authRequest( 'get', route('field.index', [ 'without_pages' => true ]), JsonResponse::HTTP_OK ); } public function test_store() { // deleting existing fields Field::query()->delete(); // creating a text field $response = $this->authRequest( 'post', route('field.store'), JsonResponse::HTTP_CREATED, [ 'label' => fake()->word, 'type' => 'text', 'title' => null, 'description' => null, 'multiple' => null, 'options' => null, ] ); // creating a select field $response = $this->authRequest( 'post', route('field.store'), JsonResponse::HTTP_CREATED, [ 'label' => fake()->word, 'type' => 'select', 'title' => null, 'description' => null, 'multiple' => null, 'options' => [ 'Opção 1', 'Opção 2' ], ] ); } public function test_store_with_validations() { // deleting existing fields Field::query()->delete(); $validation = Validation::factory()->create(); // creating a text field $response = $this->authRequest( 'post', route('field.store'), JsonResponse::HTTP_CREATED, [ 'label' => fake()->word, 'type' => 'text', 'title' => null, 'description' => null, 'multiple' => null, 'options' => null, 'validations' => [$validation->id] ] ); // creating a select field $response = $this->authRequest( 'post', route('field.store'), JsonResponse::HTTP_CREATED, [ 'label' => fake()->word, 'type' => 'select', 'title' => null, 'description' => null, 'multiple' => null, 'options' => [ 'Opção 1', 'Opção 2' ], 'validations' => [$validation->id] ] ); } public function test_store_system_field() { // deleting existing fields Field::query()->delete(); // creating a text field $response = $this->authRequest( 'post', route('field.store'), JsonResponse::HTTP_CREATED, [ 'label' => fake()->word, 'type' => 'text', 'title' => null, 'description' => null, 'multiple' => null, 'options' => null, 'system_item' => true, 'system_item_type' => 'CURRENT_USER' ] ); // creating a select field $response = $this->authRequest( 'post', route('field.store'), JsonResponse::HTTP_CREATED, [ 'label' => fake()->word, 'type' => 'select', 'title' => null, 'description' => null, 'multiple' => null, 'options' => [ 'Opção 1', 'Opção 2' ], ] ); } public function test_show() { // deleting existing fields Field::query()->delete(); $field = Field::factory()->create(); // creating a text field $response = $this->authRequest( 'get', route('field.show', $field) ); } public function test_update() { // deleting existing fields Field::query()->delete(); $field = Field::factory()->create(); // creating a text field $response = $this->authRequest( 'put', route('field.update', $field), JsonResponse::HTTP_OK, [ 'label' => fake()->word, 'type' => 'text', 'title' => null, 'description' => null, 'multiple' => null, 'options' => null, ] ); } public function test_destroy() { // deleting existing fields Field::query()->delete(); $field = Field::factory()->create(); // creating a text field $response = $this->authRequest( 'delete', route('field.destroy', $field), JsonResponse::HTTP_NO_CONTENT ); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.06 |
proxy
|
phpinfo
|
Settings