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

namespace Tests\Unit\Admin;

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

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Support\Str;
use Illuminate\Http\UploadedFile;

class Evaluation_testTest extends TestCase
{
    protected $randomName;
    protected function setUp(): void 
    {
        parent::setUp();
        $this->randomName = Str::random(10);
    }

    public function test_admin_to_insert_evaluation_test()
    {
        $userAdmin = factory(\App\User::class)->create(['role'=>1]);
        $user = \App\User::where('email','admin@gmail.com')->first();

        $this->withoutMiddleware();
        $this->withoutExceptionHandling();
        
        $from_language = factory(\App\Models\Language::class)->create();
        $to_language = factory(\App\Models\Language::class)->create();
        
        
        $this->actingAs($userAdmin)->json('GET','/admin/translators');
        $question_file=UploadedFile::fake()->create('a.pdf');
        $data = [
            'evaluation_name' => $this->randomName,
            // 'evaluation_description' => $this->randomName,
            'evaluation_text' => $this->randomName,
            'instructions' => $this->randomName,
            // 'evaluation_text_class' =>$this->randomName,
            'from_language_id' => $from_language->id,
            'to_language_id' => $to_language->id,
            'duration' => 10,
            'semantic_score' => 10,
            'terminology_score' => 10,
            'syntax_score' => 10,
            'quality_score' => 10,
            'beauty_score' => 10,
            // 'status_id' => 1,
            'evaluation_file' => $question_file,
        ];
         
        $response = $this->json('POST', 'api/insertTest', $data, 
            [
                'Accept' => 'application/json', 
                'HTTP_Authorization' => 'Bearer' . $userAdmin->remember_token
            ])
            ->assertStatus(200);           
        $response->assertOk();

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

        \App\Models\Evaluation::orderBy('id','DESC')->first()->delete();
        \App\Models\Language::where('id', $from_language->id)->delete();
        \App\Models\Language::where('id', $to_language->id)->delete();
        \App\User::where('id', $userAdmin->id)->delete();    
    }

    public function test_admin_to_change_evaluation_test_status()
    {
        $userAdmin = factory(\App\User::class)->create(['role'=>1]);
        $user = \App\User::where('email','admin@gmail.com')->first();

        $this->withoutMiddleware();
        $this->withoutExceptionHandling();
        
        $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,
            'status_id' => 0,
        ]);

        $this->actingAs($userAdmin)->json('GET','/admin/translators');
        $data = [
            'status_id' =>1,
            'id' => $evaluation->id 
        ];
         
        $response = $this->json('POST', 'api/changeTestStatus', $data, 
            [
                'Accept' => 'application/json', 
                'HTTP_Authorization' => 'Bearer' . $userAdmin->remember_token
            ])
            ->assertStatus(200);           
        $response->assertOk();
        \App\Models\Evaluation::orderBy('id','DESC')->first()->delete();
        \App\Models\Language::where('id', $from_language->id)->delete();
        \App\Models\Language::where('id', $to_language->id)->delete();
        \App\User::where('id', $userAdmin->id)->delete();
    }

    /*public function test_admin_to_update_evaluation_test()
    {

        $userAdmin = factory(\App\User::class)->create(['role'=>1]);
        $user = \App\User::where('email','admin@gmail.com')->first();

        $this->withoutMiddleware();
        $this->withoutExceptionHandling();
        
        $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->actingAs($userAdmin)->json('GET','/admin/translators');
        $question_file=UploadedFile::fake()->create('a.pdf');
        $data = [
            'evaluation_name' => $this->randomName,
            // 'evaluation_description' => $this->randomName,
            'evaluation_text' => $this->randomName,
            'instructions' => $this->randomName,
            // 'evaluation_text_class' =>$this->randomName,
            'from_language_id' => $from_language->id,
            'to_language_id' => $to_language->id,
            'duration' => 10,
            'semantic_score' => 10,
            'terminology_score' => 10,
            'syntax_score' => 10,
            'quality_score' => 10,
            'beauty_score' => 10,
            // 'status_id' => 1,
            'evaluation_file' => $question_file,
        ];
         
        $response = $this->json('POST', 'api/insertTest', $data, 
            [
                'Accept' => 'application/json', 
                'HTTP_Authorization' => 'Bearer' . $userAdmin->remember_token
            ])
            ->assertStatus(200);           
        $response->assertOk();
        \App\Models\Evaluation::orderBy('id','DESC')->first()->delete();
        \App\Models\Language::where('id', $from_language->id)->delete();
        \App\Models\Language::where('id', $to_language->id)->delete();
        \App\User::where('id', $userAdmin->id)->delete();    
    }*/

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

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

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