<?php


namespace Tests\Inventory\Http\InventoryController;


use App\Authority;
use App\Owner;
use App\Role;
use App\User;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

class InventoryControllerMissionTest extends TestCase
{
    public $response=null;
    public $role;
    public $user;
    function setUp(): void
    {
        parent::setUp(); // TODO: Change the autogenerated stub
        if(!$this->user){
            $this->user = factory(User::class)->create();
            $this->role= Role::firstOrCreate([
                'name'=>'testRole',
            ]);
            $this->assertNotEmpty($this->role->id);
            $authority= Authority::where('name','库存管理-盘点')->first();
            DB::table('authority_role')->insert(['id_authority'=>$authority->id,'id_role'=>$this->role->id]);
            DB::table('user_role')->insert(['id_user'=>$this->user->id,'id_role'=>$this->role->id]);
        }
        $url = 'http://bswas/inventory/stockInventory/mission';
        $this->response=$this->actingAs($this->user)->get($url);
    }

    function testMissionNotHavingException(){
        $this->response->assertDontSee('Exception');
    }
    function testMissionViewIsRight(){
        $this->response->assertViewIs('inventory.stockInventory.mission');
    }
    function testMissionHasOwners(){
        $owners=Owner::select('id','name')->get();
        $this->response->assertViewHas('owners');
    }
    function testMissionHasInventories(){
        $this->response->assertViewHas('inventoryAccounts');
    }

    function tearDown(): void
    {
        DB::table('user_role')->where('id_role',$this->role['id'])->delete();
        DB::table('authority_role')->where('id_role',$this->role['id'])->delete();
        User::where('id',$this->user['id'])->delete();
        Role::where('id',$this->role['id'])->delete();
        parent::tearDown(); // TODO: Change the autogenerated stub
    }
}
