create(); $this->assertNotEmpty($userMark->id); return $userMark; } public function testRole(){ $role=Role::create([ 'name'=>'测试admin' ]); $this->assertNotEmpty($role->id); $authorities= Authority::get(); foreach ($authorities as $authority){ DB::table('authority_role')->insert(['id_authority'=>$authority->id,'id_role'=>$role->id]); } return $role; } /** * @depends testRole */ public function testUser(Role $role){ $user=factory(User::class)->create(); DB::table('user_role')->insert(['id_user'=>$user->id,'id_role'=>$role->id]); $this->assertNotEmpty($user->id); return $user; } public function testAddWaybill(){ $waybill=new Waybill([ 'type'=>'直发车', 'state'=>'未审核', 'waybill_number'=>'BSZX12345848854', 'owner_id'=>2, 'wms_bill_number'=>'zx1858545465', 'origination'=>'上海松江', 'destination'=>'郑州中原', 'recipient'=>'elder sister', 'recipient_mobile'=>'18458741254', 'charge'=>586, 'ordering_remark'=>'禁' ]); $result=$waybill->save(); $this->assertTrue($result); $this->assertNotEmpty($waybill); return $waybill; } /** * @depends testUser * @depends testAddWaybill * @depends testUserMark */ public function testIndex(User $user,Waybill $waybill,User $userMark){ $responseFalse=$this->actingAs($user)->get('waybill',[ 'waybill_number'=>'BSZX12345848854' ]); $responseFalse->assertOk()->assertSee('BSZX12345848854'); $responseMark=$this->actingAs($userMark)->get('waybill',[ 'waybill_number'=>'BSZX12345848854' ]); $responseMark->assertStatus(302)->assertRedirect('/'); $responseTrue=$this->actingAs($user)->get('waybill'); $responseTrue->assertOk()->assertSee('BSZX12345848854'); } /** * @depends testUser * @depends testUserMark */ public function testCreate(User $user,User $userMark){ $response=$this->actingAs($user)->get('waybill/create'); $response->assertOk()->assertSee('WMS单号'); $responseMark=$this->actingAs($userMark)->get('waybill/create'); $responseMark->assertStatus(302)->assertRedirect('/'); } /** * @depends testUser * @depends testUserMark */ public function testStore(User $user,User $userMark){ $response=$this->actingAs($user)->post('waybill',[ 'type'=>'专线', 'owner_id'=>1, 'wms_bill_number'=>'ad544da6584', 'origination'=>'上海', 'destination'=>'商丘', 'recipient'=>'周某', 'recipient_mobile'=>'01547896548', 'charge'=>58.6, 'ordering_remark'=>'' ]); $response->assertStatus(302)->assertRedirect('waybill')->assertSessionHas('successTip'); $responseMark=$this->actingAs($userMark)->post('waybill',[ 'type'=>'专线', 'owner_id'=>1, 'wms_bill_number'=>'ad544da6584', 'origination'=>'上海', 'destination'=>'商丘', 'recipient'=>'周某', 'recipient_mobile'=>'01547896548', 'charge'=>58.6, 'ordering_remark'=>'' ]); $responseMark->assertStatus(302)->assertRedirect('/'); } /** * @depends testUser * @depends testAddWaybill * @depends testUserMark */ public function testEdit(User $user,Waybill $waybill,User $userMark){ $response=$this->actingAs($user)->get('waybill/'.$waybill->id.'/edit'); $response->assertOk()->assertSee('BSZX12345848854'); $responseMark=$this->actingAs($userMark)->get('waybill/'.$waybill->id.'/edit'); $responseMark->assertStatus(302)->assertRedirect('/'); } /** * @depends testUser * @depends testAddWaybill * @depends testUserMark */ public function testUpdate(User $user,Waybill $waybill,User $userMark){ //直发车数据校验通过 $responseZFTrue=$this->actingAs($user)->put('waybill/'.$waybill->id,[ 'type'=>'直发车', 'carrier_id'=>1, 'carrier_bill'=>'0154786548', 'carType_id'=>1, 'fee'=>500, 'other_fee'=>20, 'collect_fee'=>30, 'dispatch_remark'=>'' ]); $responseZFTrue->assertStatus(302)->assertRedirect('waybill')->assertSessionHas('successTip'); $responseZFMark=$this->actingAs($userMark)->put('waybill/'.$waybill->id,[ 'type'=>'直发车', 'carrier_id'=>1, 'carrier_bill'=>'0154786548', 'carType_id'=>1, 'fee'=>500, 'other_fee'=>20, 'collect_fee'=>30, 'dispatch_remark'=>'' ]); $responseZFMark->assertStatus(302)->assertRedirect('/'); $waybillPayoffs=WaybillPayoff::where('waybill_id','=',$waybill->id)->first(); $this->assertNotEmpty($waybillPayoffs); $this->assertEquals(490.00,$waybillPayoffs->total_expense); $this->assertEquals(586.00,$waybillPayoffs->total_receivable); $this->assertEquals(96.00,$waybillPayoffs->gross_margin); //直发车数据校验失败 $responseZFFalse=$this->actingAs($user)->put('waybill/'.$waybill->id,[ 'type'=>'直发车', 'carrier_id'=>1, 'carrier_bill'=>'20', 'other_fee'=>'a456d', 'collect_fee'=>30, 'dispatch_remark'=>'' ]); $responseZFFalse->assertStatus(302)->assertRedirect('/'); //保留 //专线 $waybillZX=new Waybill([ 'type'=>'专线', 'state'=>'未审核', 'waybill_number'=>'BSZX12345146854854', 'owner_id'=>2, 'wms_bill_number'=>'01547860548', 'origination'=>'上海', 'destination'=>'郑州', 'recipient'=>'elder sister', 'recipient_mobile'=>'12364851478', 'charge'=>586, 'ordering_remark'=>'禁' ]); $waybillZX->save(); $this->assertNotEmpty($waybillZX); //未定义计费模型 $responseZXFalse=$this->actingAs($user)->put('waybill/'.$waybillZX->id,[ 'type'=>'专线', 'carrier_id'=>1, 'carrier_bill'=>'01547860548', 'origination_city_id'=>1, 'destination_city_id'=>2, 'warehouse_weight'=>25, 'warehouse_weight_unit_id'=>1, 'carrier_weight'=>25, 'carrier_weight_unit_id'=>1, 'pick_up_fee'=>500, 'other_fee'=>20, 'dispatch_remark'=>'' ]); $responseZXFalse->assertStatus(302)->assertRedirect('waybill'); $responseZXMark=$this->actingAs($userMark)->put('waybill/'.$waybillZX->id,[ 'type'=>'专线', 'carrier_id'=>1, 'carrier_bill'=>'01547860548', 'origination_city_id'=>1, 'destination_city_id'=>2, 'warehouse_weight'=>25, 'warehouse_weight_unit_id'=>1, 'carrier_weight'=>25, 'carrier_weight_unit_id'=>1, 'pick_up_fee'=>500, 'other_fee'=>20, 'dispatch_remark'=>'' ]); $responseZXMark->assertStatus(302)->assertRedirect('/'); $fee=Waybill::find($waybillZX->id); $this->assertEquals(null,$fee->fee); $waybillPayoffsZX=WaybillPayoff::where('waybill_id','=',$waybillZX->id)->first(); $this->assertNotEmpty($waybillPayoffsZX); $waybillPayoffsZX->delete(); //清除冗余数据 $result=$waybillZX->delete(); $this->assertTrue($result); } /** * @depends testUser * @depends testAddWaybill * @depends testUserMark */ public function testWaybillUpdate(User $user,Waybill $waybill,User $userMark){ $response=$this->actingAs($user)->put('waybill/'.$waybill->id,[ 'type'=>'直发车', 'carrier_id'=>2, 'carrier_bill'=>'5a4d664585', 'carType_id'=>2, 'fee'=>600, 'other_fee'=>30, 'collect_fee'=>50, 'dispatch_remark'=>'测试更改' ]); $response->assertStatus(302)->assertRedirect('waybill')->assertSessionHas('successTip'); $responseMark=$this->actingAs($userMark)->put('waybill/'.$waybill->id,[ 'type'=>'直发车', 'carrier_id'=>2, 'carrier_bill'=>'5a4d664585', 'carType_id'=>2, 'fee'=>600, 'other_fee'=>30, 'collect_fee'=>50, 'dispatch_remark'=>'测试更改' ]); $responseMark->assertStatus(302)->assertRedirect('/'); } /** * @depends testUser * @depends testAddWaybill * @depends testUserMark */ public function testWaybillAudit(User $user,Waybill $waybill,User $userMark){ //第一次请求成功 $response=$this->actingAs($user)->json('post','waybill/waybillAudit',['id'=>$waybill->id]); $response->assertJson(['success'=>true,'state'=>'已审核']); $responseMark=$this->actingAs($userMark)->json('post','waybill/waybillAudit',['id'=>$waybill->id]); $responseMark->assertStatus(302)->assertRedirect('/'); //第二次请求拦截 $responseRe=$this->actingAs($user)->json('post','waybill/waybillAudit',['id'=>$waybill->id]); $responseRe->assertJson(['exception'=>'请勿重复审核!']); } /** * @depends testUser * @depends testAddWaybill * @depends testUserMark */ public function testWaybillEdit(User $user,Waybill $waybill,User $userMark){ $response=$this->actingAs($user)->get('waybill/waybillEdit/'.$waybill->id); $response->assertOk()->assertSee('上海松江'); $responseMark=$this->actingAs($userMark)->get('waybill/waybillEdit/'.$waybill->id); $responseMark->assertStatus(302)->assertRedirect('/'); } /** * @depends testUser * @depends testAddWaybill * @depends testUserMark */ public function testWaybillRetreatAudit(User $user,Waybill $waybill,User $userMark){ $response=$this->actingAs($user)->json('post','waybill/waybillRetreatAudit',['id'=>$waybill->id]); $response->assertJson(['success'=>true,'state'=>'待重审']); $responseMark=$this->actingAs($userMark)->json('post','waybill/waybillRetreatAudit',['id'=>$waybill->id]); $responseMark->assertStatus(302)->assertRedirect('/'); } /** * @depends testUser * @depends testAddWaybill * @depends testUserMark */ public function testWaybillEndAudit(User $user,Waybill $waybill,User $userMark){ //第一次请求成功 $response=$this->actingAs($user)->json('post','waybill/waybillEndAudit',['id'=>$waybill->id]); $response->assertJson(['success'=>true,'state'=>'未定义计费模型']); $responseMark=$this->actingAs($userMark)->json('post','waybill/waybillEndAudit',['id'=>$waybill->id]); $responseMark->assertStatus(302)->assertRedirect('/'); //第二次请求拦截 $responseRe=$this->actingAs($user)->json('post','waybill/waybillEndAudit',['id'=>$waybill->id]); $responseRe->assertJson(['exception'=>'请勿重复审核!']); } /** * @depends testAddWaybill * @depends testUser * @depends testUserMark * @depends testRole */ public function testDestroy(Waybill $waybill,User $user,User $userMark,Role $role){ $this->assertNotEmpty($waybill); $result=$waybill->delete(); $this->assertTrue($result); $waybillPayoffs=WaybillPayoff::where('waybill_id','=',$waybill->id)->first(); $this->assertNotEmpty($waybillPayoffs); $resultWaybillPayoffs=$waybillPayoffs->delete(); $this->assertTrue($resultWaybillPayoffs); $waybillStore=Waybill::where('wms_bill_number','=','ad544da6584')->first(); $this->assertNotEmpty($waybillStore); $resultWaybillStore=$waybillStore->delete(); $this->assertTrue($resultWaybillStore); $waybillFinancialSnapshots=WaybillFinancialExcepted::where('waybill_id','=',$waybill->id)->first(); $r=$waybillFinancialSnapshots->delete(); $this->assertTrue($r); $isAudit=WaybillAuditLog::withTrashed()->whereRaw('waybill_id = ? and audit_stage = ?',[$waybill->id,"运单阶段"])->first(); $resultWaybillAuditLogWaybill=$isAudit->forceDelete(); $this->assertTrue($resultWaybillAuditLogWaybill); $waybillAuditLogDispatch=WaybillAuditLog::whereRaw('waybill_id = ? and audit_stage = ?',[$waybill->id,"调度阶段"])->first(); $resultWaybillAuditLogDispatch=$waybillAuditLogDispatch->forceDelete(); $this->assertTrue($resultWaybillAuditLogDispatch); $result=$user->delete(); $this->assertTrue($result); $this->assertNotEmpty($userMark->id); $resultUserMark=$userMark->delete(); $this->assertTrue($resultUserMark); $resultRole=$role->delete(); $this->assertTrue($resultRole); DB::table('authority_role')->where('id_role','=',$role->id)->delete(); DB::table('user_role')->where('id_role','=',$role->id)->delete(); } }