MOON
Server: Apache
System: Linux e2e-78-16.ssdcloudindia.net 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64
User: imensosw (1005)
PHP: 8.0.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/imensosw/.trash/tests.1/Unit/Translator/UserEvaluationTest.php
<?php

namespace Tests\Unit\Translator;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

use DB;
use App\Models\Language;
use App\Models\Proficiency;
use App\User;
use Illuminate\Http\UploadedFile;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use App\Models\Evaluation;


class UserEvaluationTest extends TestCase
{
    protected $users, $clientData, $language, $proficiency, $evaluation;
    protected function setUp(): void 
    {
        parent::setUp();
        
        // $this->language = Language::inRandomOrder()->first();

        // $this->proficiency = Proficiency::inRandomOrder()->first();

        // $this->evaluation = Evaluation::inRandomOrder()->where('status_id',1)->first();

        $this->image = 'balloons.pdf';

    }

    public function test_to_get_user_evaluation()
    {
        $this->withoutMiddleware();
        $this->withoutExceptionHandling();
        $response = $this->json('GET','/getUserEvaluations');
        $response->assertOk();
    }

    public function test_to_insert_user_evaluation()
    {
       // $file=UploadedFile::fake()->create($this->image);

        $user = factory(User::class)->create();
        $profile =  factory(\App\Models\Profile::class)->create(['user_id'=>$user->id]);


        $from_language = factory(\App\Models\Language::class)->create();
        $to_language = factory(\App\Models\Language::class)->create();

        $evaluation = factory(\App\Models\Evaluation::class)->create([
            'from_language_id' => $from_language->id,
            'to_language_id' => $to_language->id, 
        ]);

        $this->withoutMiddleware();
        $this->withoutExceptionHandling();

        $this->actingAs($user)->json('GET','/getUserEvaluations');

        $data = [
            "answer" => 'sfddsgd fhf gfdgfdg fd',
            'answer_file' => '',
            'evaluation_id' => $evaluation->id,
            'time_expend' => 10,
        ];

        $response = $this->json('POST', 'api/insertUserEvaluation', $data, 
            [
                'Accept' => 'application/json', 
                'HTTP_Authorization' => 'Bearer' . $user->remember_token
            ])
            ->assertStatus(200);
        $response->assertOk();

        \App\Models\UserEvaluation::where(array('user_id' => $user->id , 'evaluation_id' => $evaluation->id))->delete();
        \App\Models\Evaluation::where('id', $evaluation->id)->delete();
        \App\Models\Language::where('id', $from_language->id)->delete();
        \App\Models\Language::where('id', $to_language->id)->delete();
        \App\Models\Profile::where('user_id', $user->id)->delete();
        \App\User::where('id', $user->id)->delete();

    }

    public function tearDown(): void
    {
        $maxId = \DB::table('languages')->max('id');
        \DB::statement('ALTER TABLE languages AUTO_INCREMENT=' . intval($maxId + 1) . ';');

        $maxId = \DB::table('evaluations')->max('id');
        \DB::statement('ALTER TABLE evaluations AUTO_INCREMENT=' . intval($maxId + 1) . ';');

        $maxId = \DB::table('user_evaluations')->max('id');
        \DB::statement('ALTER TABLE user_evaluations AUTO_INCREMENT=' . intval($maxId + 1) . ';');

        $maxId = \DB::table('profiles')->max('id');
        \DB::statement('ALTER TABLE profiles AUTO_INCREMENT=' . intval($maxId + 1) . ';');

        $maxId = \DB::table('users')->max('id');
        \DB::statement('ALTER TABLE users AUTO_INCREMENT=' . intval($maxId + 1) . ';');
        parent::tearDown();
    }

}