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/UserWorkHistoryTest.php
<?php

namespace Tests\Unit\Translator;

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

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Support\Str;
use App\Models\UserExperience;
use App\Models\UserExperienceType;
use App\Models\UserExperienceDoc;
use App\Models\ExperienceType;
use App\Models\Experience;
use App\User;
use DB ;

use Illuminate\Http\UploadedFile;

class UserWorkHistoryTest extends TestCase
{
    protected $users, $clientData, $experience, $experience_type, $image;
    protected function setUp(): void 
    {
        parent::setUp();
        $this->experience = Experience::inRandomOrder()->first();

        $this->experience_type = ExperienceType::inRandomOrder()->first();

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

    }

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

    /* Photo Identity Upload Test */
    public function test_to_update_user_work_history()
    {
        $file=UploadedFile::fake()->image($this->image);

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

        factory(UserExperience::class)->create(['user_id'=>$user->id,'experience_id'=>$this->experience->id]);

        factory(UserExperienceType::class)->create(['user_id'=>$user->id,'experience_type_id'=>$this->experience_type->id]);
        factory(UserExperienceDoc::class)->create(['user_id'=>$user->id,'doc_name'=>$file]);

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

        $this->actingAs($user)->json('GET','/getUserIdentification');
        $data = [
            "experience_id" => $this->experience->id,
            'experience_type_id' => [$this->experience_type->id],
            "experience_docs" => [$file],
        ];

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

        UserExperience::where('user_id', $user->id)->delete();
        UserExperienceDoc::where('user_id', $user->id)->delete();
        UserExperienceType::where('user_id', $user->id)->delete();
        \App\Models\Profile::where('user_id', $user->id)->delete();
        \App\User::where('id', $user->id)->delete();

 
        //    $response1 = $this->post('/api/updateWorkHistory', $data);
        // dd($response1->getContent()); // add this temporarily
        // $response1->assertResponseStatus(200);
    }

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

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

        $maxId = DB::table('user_experience_types')->max('id');
        DB::statement('ALTER TABLE user_experience_types 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();
    }

}