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

namespace Tests\Unit\Admin;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use App\Models\Language;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Support\Str;


class LanguageTest extends TestCase
{
     protected $users , $clientData, $role;
    protected function setUp(): void 
    {
        parent::setUp();

        // $user = factory(\App\User::class)->make();
        // $this->users = $user;
        $this->role = \DB::table('roles')->where('id',1)->first();
       /* $client = factory(\App\Models\Language::class)->create();
        $this->clientData = $client;*/

    }

    public function test_admin_to_create_language()
    {
         $name = Str::random(10);
          $userAdmin = factory(\App\User::class)->create(['role'=>$this->role->id]);
        $this->withoutMiddleware();
        $this->withoutExceptionHandling();

        $this->actingAs($userAdmin)->json('GET','/admin/language');
        $data = [
            "language_l" => $name,
            "language_s" => $name.'1',
        ];
        
        $response = $this->json('POST', 'api/admin/language/store', $data, 
            [
                'Accept' => 'application/json', 
                'HTTP_Authorization' => 'Bearer' . $userAdmin->remember_token
            ])
            ->assertStatus(200);
        $response->assertOk();

        Language::where('language_l', $name)->delete();
        \App\User::where('id',$userAdmin->id)->delete();

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

    }

    public function test_admin_to_update_language ()
    {
         $userAdmin = factory(\App\User::class)->create(['role'=>$this->role->id]);
        $create = factory(Language::class)->create();
        $this->withoutMiddleware();
        $this->withoutExceptionHandling();

        $this->actingAs($userAdmin)->json('GET','/admin/language');
      
        $test ="Eddkvc";
       $data = [
            'language_id' => $create->id,
            "language_l" =>$test,
             "language_s" => $test.'1',
        ];
         
        $response = $this->json('POST', 'api/admin/language/update', $data, 
            [
                'Accept' => 'application/json', 
                'HTTP_Authorization' => 'Bearer' . $userAdmin->remember_token
            ])
            ->assertStatus(200);
        $response->assertOk();
           Language::where('id', $create->id)->delete();
        \App\User::where('id',$userAdmin->id)->delete();
     
    }



    public function test_admin_to_delete_language ()
    {
        $userAdmin = factory(\App\User::class)->create(['role'=>$this->role->id]);
        $this->withoutMiddleware();
        $this->withoutExceptionHandling();

        $this->actingAs($userAdmin)->json('GET','/admin/language');
        // $response->assertOk();

        $create = factory(Language::class)->create();

       $data = [
            'id' => $create->id,
        ];
         
        $response = $this->json('POST', 'api/admin/language/delete', $data, 
            [
                'Accept' => 'application/json', 
                'HTTP_Authorization' => 'Bearer' . $userAdmin->remember_token
            ])
            ->assertStatus(200);
           
        $response->assertOk();
        Language::where('id', $create->id)->delete();
         \App\User::where('id',$userAdmin->id)->delete();
       /* $response1 = $this->post('/api/admin/language/delete', $data);
        dd($response1->getContent()); // add this temporarily
        $response1->assertResponseStatus(200);*/
    }

    public function tearDown(): void
    {
        $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();
    }
}