<?php

namespace Tests\Routes;

use App\User;
use Illuminate\Support\Str;
use Tests\TestCase;

class WebTest extends TestCase
{
    const PARAM = 1;
    const GET = [
        "/home",
        "/homeTemp",
        "password/change",
        "password/update",
        "maintenance/commodity/import",
        "maintenance/owners/recycle",
        "maintenance/paperBox/index/model",
        "maintenance/paperBox/index/owner",
        "maintenance/paperBox/excel/goImport",
        "maintenance/waybillPriceModel/excel/goImport",
        "maintenance/waybillPriceModel/cities/".self::PARAM,
        "maintenance",
        "waybill/relating",
        "waybill/recycle",
        "waybill/index",
        "waybill/delivering",
        "rejected/relating",
        "rejected/recycle",
        "rejected/import",
        "package/weightExcepted/indexCreate",
        "package/weightExcepted/indexIssued",
        "package/statistics",
        "package/relating",
        "store",
        "process/relating",
        "process/statistic",
        "process/recycle",
        "personnel/checking-in/userDutyCheck/importAndExportClock",
        "personnel/checking-in/userDutyCheck/clock",
        "personnel/checking-in/userDutyCheck/createUserDetail/".self::PARAM,
        "personnel/checking-in/userDutyCheck/updateUserLaborCompanies/".self::PARAM,
        "personnel/checking-in/goGetQRCode",
        "personnel/checking-in/QRCode",
        "personnel/checking-in/importAndExportQRCode",
        "personnel/checking-in/createReplenishClock",
        "personnel/checking-in/clockAudit",
        "personnel/checking-in/missionAudit",
        "personnel/relating",
        "getLaborReport",
        "inventory/statement/changeInventory/downLoadExcel",
        "inventory/statement/changeInventory",
        "inventory/statement/allInventory",
        "inventory/statement/dailyLog",
        "inventory/statement/inventoryCompare",
        "inventory/stockInventory/mission",
        "inventory/syncOwners",
        "inventory/完结盘点任务/".self::PARAM,
        "order/wave/index",
        "order/issue/workLoad/index",
        "order/issue/orderIssuePerformance/index",
        "order/issue/index",
        "order/issue/create",
        "order/issue/excelImport",
        "order/issue/edit/".self::PARAM,
        "order/tracking/index",
        "order/tracking/export",
        "order/tracking/update",
    ];
    const POST = [
        "maintenance/commodity/import/excel",
        "maintenance/tutorial/showContent/".self::PARAM,
        "maintenance/userLabor/getWorkRecord",
        "maintenance/userLabor/getClockRecord",
        "maintenance/userLabor/relieve",
        "maintenance/paperBox/excel/import",
        "waybill/ontop/top",
        "waybill/ontop/cancel",
        "waybill/is/waybillPriceModel",
        "waybill/deleteImg",
        "waybill/upload",
        "waybill/refreshWaveHouseWeight",
        "waybill/storeCarrierBill",
        "waybill/addCounty",
        "waybillPriceModel/excel/import",
        "rejectedBill/".self::PARAM."/edit",
        "rejected/import/excel",
        "rejected/analyze/exportExcelOnParams",
        "rejected/analyze/exportAllExcelOnParams",
        "rejected/ajaxCheck",
        "rejected/ajaxCheckAll",
        "rejected/ajaxFinishAll",
        "rejected/ajaxGetRejected",
        //"package/measureMonitor/data",
        "process/getDailyParticipant",
        "process/reject/".self::PARAM,
        "process/receive/".self::PARAM,
        "process/accomplish",
        "process/updateDailyOutput",
        "process/storeProcessDailyParticipant",
        "process/verifyUserName",
        "process/updateProcessDailyParticipant",
        "process/processDailyParticipantAudit/".self::PARAM,
        "process/getTutorials/".self::PARAM,
        "process/selectedTutorial",
        "process/deleteTutorial",
        "process/ownerGetTutorials/".self::PARAM,
        "process/rollback",
        "process/recover",
        "process/audit",
        "process/processAccomplish",
        "process/checkAndAccept",
        "process/updateUnitPrice",
        "process/workGroupVerify",
        "process/accountantVerify",
        "process/updateStartDate",
        "process/updateEndDate",
        "process/importPasteData",
        "process/deleteProcessContent/".self::PARAM,
        "personnel/checking-in/userDutyCheck/storeClock",
        "personnel/checking-in/userDutyCheck/绑定临时工并进组",
        "personnel/checking-in/userDutyCheck/importGroupClock",
        "personnel/checking-in/userDutyCheck/storeUserDetail",
        "personnel/checking-in/userDutyCheck/storeUpdateUserLaborCompanies",
        "personnel/checking-in/refreshQRCode",
        "personnel/checking-in/checkUserLabors",
        "personnel/checking-in/storeReplenishClock",
        "personnel/checking-in/storeClockAudit",
        "personnel/checking-in/updateDutyCheckType",
        "personnel/checking-in/storeGroupAudit",
        "personnel/checking-in/isException",
        "personnel/checking-in/storeMissionAudit",
        "laborReport/guardClockAudit",
        "laborReport/groupClockAudit",
        "laborReport/addRemarkAndGroupClock",
        "laborReport/groupExport",
        "laborReport/groupExportEnsure",
        "inventory/statement/changeInventory/deleteExcel",
        "inventory/statement/dailyLog/getLoggingOwner",
        "inventory/statement/dailyLog/addLoggingOwner",
        "inventory/stockInventory/createStockInventoryMission",
        "inventory/inventoryCompare/import/excel",
        "inventory/修改质量状态",
        "inventory/增加系统之外的库位记录",
        "inventory/盘点选中任务",
        "inventory/stockInventoryEnd",
        "inventory/searchStockInventoryRecord",
        "order/create/batchComments",
        "order/wave/cancelPrinting",
        "order/issue/store",
        "order/issue/batchImport",
        "order/freeze",
        "order/freezeAll",
        "order/thaw",
        "order/deAllocation",
        "order/deAllocationAll",
        "order/resetLogisticsGetMark",
        "order/createRejectedBill",
        "order/isRejectedBillExist"
    ];
    const PUT = [

    ];
    const DELETE = [
        "process/destroyDailyParticipant/".self::PARAM,
    ];
    const RESTFUL = [
        "maintenance/log",
        "maintenance/user",
        "maintenance/role",
        "maintenance/authority",
        "maintenance/owner",
        "maintenance/logistic",
        "maintenance/qualityLabel",
        "maintenance/carrier",
        "maintenance/carType",
        "maintenance/unit",
        "maintenance/province",
        "maintenance/city",
        "maintenance/commodity",
        "maintenance/measuringMachine",
        "maintenance/userWorkgroup",
        "maintenance/laborCompany",
        "maintenance/warehouse",
        "maintenance/jobType",
        "maintenance/tutorial",
        "maintenance/userLabor",
        "maintenance/paperBox",
        "maintenance/waybillPriceModel",
        "waybill/waybillFinancialSnapshot",
        "waybill/waybillFinancialExcepted",
        "waybill",
        "rejectedBill",
        "rejected",
        "package/measureMonitor",
        "package",
        "store/fast",
        "store/storeItem",
        "process",
        "personnel/laborReport",
    ];
    const ANY = [
        "waybill/deliveringExport",
        "waybill/waybillAudit",
        "waybill/waybillEdit/".self::PARAM,
        "waybill/waybillRetreatAudit",
        "waybill/waybillEndAudit",
        "waybill/export",
        "waybill/waybillUpdate/".self::PARAM,
        "waybillFinancialSnapshot/export",
        "rejected/index/general",
        "rejected/index/analyze",
        "rejected/exportAnalyze",
        "rejected/export",
        //"package/measureMonitor/speech",
        "package/statistics/export",
        "package/weightExcepted/export/".self::PARAM,
        "package/export",
        "process/statistic/export",
        "process/export",
        "laborReport/export",
        "inventory/statement/changeInventory/export",
        "inventory/statement/allInventory/export",
        "inventory/statement/dailyLog/export",
        "inventory/stockInventory/enterStockInventory/".self::PARAM,
        "inventory/删除盘点记录",
        "inventory/deleteStockInventoryMission/".self::PARAM,
        "inventory/stockInventoryExport",
        "inventory/stockInventory",
        "order/index/delivering",
        "order/wave/exportExcel",
        "order/issue/workLoad/export",
        "order/issue/orderIssuePerformance/export",
    ];
    const MATCH = [
        "order/issue/export" => ['get','post'],
    ];
    public function testRoutes(){
/*        $superAdmin = config('users.superAdmin');
        $user = User::query()->where('name',$superAdmin[0])->first();
        if (!$user){
            $user = User::query()->create([
                'name' => $superAdmin[0],
                'email' => "test@example.com",
                'password' => "$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi",
                'remember_token' => Str::random(10),
            ]);
        }*/
        $getMethod = self::GET;
        $postMethod = self::POST;
        $putMethod = self::PUT;
        $deleteMethod = self::DELETE;
        foreach (self::MATCH as $route => $methods){
            foreach ($methods as $method){
                if ($method == 'get'){
                    array_push($getMethod,$route);
                }
                if ($method == 'post'){
                    array_push($postMethod,$route);
                }
                if ($method == 'put'){
                    array_push($putMethod,$route);
                }
                if ($method == 'delete'){
                    array_push($deleteMethod,$route);
                }
            }
        }
        foreach (self::ANY as $route){
            array_push($getMethod,$route);
            array_push($postMethod,$route);
            array_push($putMethod,$route);
            array_push($deleteMethod,$route);
        }
        foreach (self::RESTFUL as $route){
            array_push($getMethod,$route);
            array_push($getMethod,$route.'/'.self::PARAM);
            array_push($getMethod,$route.'/create');
            array_push($postMethod,$route);
            array_push($getMethod,$route.'/'.self::PARAM.'/edit');
            array_push($putMethod,$route.'/'.self::PARAM);
            array_push($deleteMethod,$route.'/'.self::PARAM);
        }

        /** @var User $user */
        foreach ($getMethod as $url){
            $response = $this/*->actingAs($user)*/->get($url);
            if ($response->getStatusCode() == 404)echo $url."\n";
            $this->assertNotEquals($response->getStatusCode(),404);
        }
        /** @var User $user */
        foreach ($postMethod as $url){
            $response = $this/*->actingAs($user)*/->post($url);
            if ($response->getStatusCode() == 404)echo $url."\n";
            $this->assertNotEquals($response->getStatusCode(),404);
        }
        /** @var User $user */
        foreach ($putMethod as $url){
            $response = $this/*->actingAs($user)*/->put($url);
            if ($response->getStatusCode() == 404)echo $url."\n";
            $this->assertNotEquals($response->getStatusCode(),404);
        }
        /** @var User $user */
        foreach ($deleteMethod as $url){
            $response = $this/*->actingAs($user)*/->delete($url);
            if ($response->getStatusCode() == 404)echo $url."\n";
            $this->assertNotEquals($response->getStatusCode(),404);
        }
    }
}
