| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497 |
- <?php
- namespace Tests\Unit;
- use App\Carrier;
- use App\WaybillAuditLog;
- use App\Authority;
- use App\WaybillPriceModel;
- use App\Role;
- use App\User;
- use App\Waybill;
- use App\WaybillPayoff;
- use App\WaybillFinancialExcepted;
- use App\WaybillFinancialSnapshot;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Request;
- use Tests\TestCase;
- use Illuminate\Foundation\Testing\WithFaker;
- use Illuminate\Foundation\Testing\RefreshDatabase;
- class WaybillTest extends TestCase
- {
- public function testUserMark(){
- $userMark=factory(User::class)->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'=>'直发车',
- 'waybill_number'=>'TestBSZF12345848854',
- 'owner_id'=>1,
- 'wms_bill_number'=>'test1858545465',
- 'origination'=>'test',
- 'destination'=>'test',
- 'recipient'=>'test sister',
- 'recipient_mobile'=>'025487456',
- 'charge'=>586.5,
- 'collect_fee'=>30,
- 'ordering_remark'=>'test'
- ]);
- $result=$waybill->save();
- $this->assertTrue($result);
- $this->assertNotEmpty($waybill->charge);
- return $waybill;
- }
- public function testAddWaybillZX(){
- $waybillZX=new Waybill([
- 'type'=>'专线',
- 'status'=>'未审核',
- 'waybill_number'=>'testBSZX123451468',
- 'owner_id'=>1,
- 'wms_bill_number'=>'test01547860548',
- 'origination'=>'上海',
- 'destination'=>'郑州',
- 'recipient'=>'elder sister',
- 'recipient_mobile'=>'12364851478',
- 'charge'=>586,
- 'ordering_remark'=>'禁'
- ]);
- $waybillZX->save();
- $this->assertNotEmpty($waybillZX);
- return $waybillZX;
- }
- public function testAddWaybillPriceModel(){
- $waybillPriceModel=WaybillPriceModel::create([
- 'logistic_id'=>1,
- 'province_id'=>1,
- 'city_id'=>1,
- 'unit_id'=>1,
- 'range_min'=>0,
- 'range_max'=>2000,
- 'unit_price'=>5,
- 'base_fee'=>10,
- 'initial_weight'=>10
- ]);
- $this->assertNotEmpty($waybillPriceModel);
- return $waybillPriceModel;
- }
- public function testAddWaybillPriceModelTwo(){
- $waybillPriceModelTwo=WaybillPriceModel::create([
- 'logistic_id'=>1,
- 'province_id'=>1,
- 'unit_id'=>3,
- 'unit_price'=>5,
- 'base_fee'=>10,
- 'initial_weight'=>10
- ]);
- $this->assertNotEmpty($waybillPriceModelTwo);
- return $waybillPriceModelTwo;
- }
- public function testAddCarrier(){
- $carrier=Carrier::create([
- 'name'=>'test承运商',
- 'mobile'=>'000005416',
- 'remark'=>'test',
- 'delivery_fee'=>170
- ]);
- $this->assertNotEmpty($carrier);
- return $carrier;
- }
- /**
- * @depends testUser
- * @depends testAddWaybill
- * @depends testUserMark
- */
- public function testIndex(User $user,Waybill $waybill,User $userMark){
- $responseFalse=$this->actingAs($user)->get('waybill/index',[
- 'waybill_number'=>'TestBSZF12345848854'
- ]);
- $responseFalseZX=$this->actingAs($user)->get('waybill/index/ZX');
- $responseFalseZF=$this->actingAs($user)->get('waybill/index/ZF');
- $responseFalseZX->assertOk();
- $responseFalseZF->assertOk();
- $responseFalse->assertOk()->assertSee('TestBSZF12345848854');
- $responseMark=$this->actingAs($userMark)->get('waybill/index',[
- 'waybill_number'=>'TestBSZF12345848854'
- ]);
- $responseMark->assertStatus(302)->assertRedirect('/');
- $responseTrue=$this->actingAs($user)->get('waybill');
- $responseTrue->assertOk()->assertSee('TestBSZF12345848854');
- }
- /**
- * @depends testUser
- * @depends testUserMark
- */
- public function testCreate(User $user,User $userMark){
- $response=$this->actingAs($user)->get('waybill/create/ZX');
- $response->assertOk()->assertSee('WMS单号');
- $responseZF=$this->actingAs($user)->get('waybill/create/ZF');
- $responseZF->assertOk();
- $responseMark=$this->actingAs($userMark)->get('waybill/create/ZX');
- $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'=>'test上海',
- 'destination'=>'test商丘',
- 'recipient'=>'test周某',
- 'recipient_mobile'=>'01547896548',
- 'charge'=>58.6,
- 'ordering_remark'=>'test'
- ]);
- $response->assertStatus(302)->assertRedirect('waybill')->assertSessionHas('successTip');
- $responseMark=$this->actingAs($userMark)->post('waybill',[
- 'type'=>'专线',
- 'owner_id'=>1,
- 'wms_bill_number'=>'ad544da6584',
- 'origination'=>'test上海',
- 'destination'=>'test商丘',
- 'recipient'=>'test周某',
- 'recipient_mobile'=>'01547896548',
- 'charge'=>58.6,
- 'ordering_remark'=>'test'
- ]);
- $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('TestBSZF12345848854');
- $responseMark=$this->actingAs($userMark)->get('waybill/'.$waybill->id.'/edit');
- $responseMark->assertStatus(302)->assertRedirect('/');
- }
- /**
- * @depends testUser
- * @depends testAddWaybillPriceModel
- * @depends testAddWaybillPriceModelTwo
- */
- public function testIsWaybillPriceModel(User $user,WaybillPriceModel $waybillPriceModel,WaybillPriceModel $waybillPriceModelTwo){
- $response=$this->actingAs($user)->post('waybill/is/waybillPriceModel',[
- 'logistic_id'=>'1',
- 'destination_city_id'=>'1',
- 'carrier_weight'=>['50','20'],
- 'carrier_weight_unit_id'=>['1','1'],
- ]);
- $response->assertOk()->assertJson(['success'=>$waybillPriceModel->id]);
- $response=$this->actingAs($user)->post('waybill/is/waybillPriceModel',[
- 'logistic_id'=>'2',
- 'destination_city_id'=>'2',
- 'carrier_weight'=>['50','20'],
- 'carrier_weight_unit_id'=>['1','1'],
- ]);
- $response->assertOk()->assertJson(['success'=>false]);
- $response=$this->actingAs($user)->post('waybill/is/waybillPriceModel',[
- 'logistic_id'=>'1',
- 'destination_city_id'=>'2',
- 'carrier_weight'=>['50','20'],
- 'carrier_weight_unit_id'=>['1','1'],
- ]);
- $response->assertOk()->assertJson(['success'=>$waybillPriceModelTwo->id]);
- }
- /**
- * @depends testUser
- * @depends testAddWaybill
- * @depends testUserMark
- * @depends testAddWaybillZX
- * @depends testAddWaybillPriceModel
- * @depends testAddCarrier
- */
- public function testUpdate(User $user,Waybill $waybill,User $userMark,Waybill $waybillZX,WaybillPriceModel $waybillPriceModel,Carrier $carrier){
- //直发车数据校验通过
- $responseZFTrue=$this->actingAs($user)->put('waybill/'.$waybill->id,[
- 'type'=>'直发车',
- 'logistic_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'=>'直发车',
- 'logistic_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.50,$waybillPayoffs->total_receivable);
- $this->assertEquals(96.50,$waybillPayoffs->gross_margin);
- //直发车数据校验失败
- $responseZFFalse=$this->actingAs($user)->put('waybill/'.$waybill->id,[
- 'type'=>'直发车',
- 'logistic_id'=>1,
- 'carrier_bill'=>'20',
- 'other_fee'=>'a456d',
- 'collect_fee'=>30,
- 'dispatch_remark'=>''
- ]);
- $responseZFFalse->assertStatus(302)->assertRedirect('/'); //保留
- //无模型
- $responseZXFalse=$this->actingAs($user)->put('waybill/'.$waybillZX->id,[
- 'type'=>'专线',
- 'logistic_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'=>'专线',
- 'logistic_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);
- //有模型
- $responseZX=$this->actingAs($user)->put('waybill/'.$waybillZX->id,[
- 'type'=>'专线',
- 'logistic_id'=>$carrier->id,
- 'carrier_bill'=>'test01547860548',
- 'origination_city_id'=>1,
- 'destination_city_id'=>1,
- 'warehouse_weight'=>25,
- 'warehouse_weight_unit_id'=>1,
- 'carrier_weight'=>50,
- 'carrier_weight_unit_id'=>1,
- 'carrier_weight_other'=>5,
- 'carrier_weight_unit_id_other'=>2,
- 'pick_up_fee'=>20,
- 'other_fee'=>20,
- 'waybillPriceModel'=>$waybillPriceModel->id,
- 'dispatch_remark'=>''
- ]);
- $responseZX->assertStatus(302)->assertRedirect('waybill');
- $waybillPayoff=WaybillPayoff::where('waybill_id',$waybillZX->id)->first();
- $this->assertNotEmpty($waybillPayoff);
- $this->assertEquals(460.00,$waybillPayoff->total_expense);
- $this->assertEquals(126.00,$waybillPayoff->gross_margin);
- }
- /**
- * @depends testUser
- * @depends testAddWaybill
- * @depends testUserMark
- */
- public function testWaybillUpdate(User $user,Waybill $waybill,User $userMark){
- $response=$this->actingAs($user)->put('waybill/'.$waybill->id,[
- 'type'=>'直发车',
- 'logistic_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'=>'直发车',
- 'logistic_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,'status'=>'已审核']);
- $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();
- $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,'status'=>'待重审']);
- $responseMark=$this->actingAs($userMark)->json('post','waybill/waybillRetreatAudit',['id'=>$waybill->id]);
- $responseMark->assertStatus(302)->assertRedirect('/');
- }
- /**
- * @depends testUser
- * @depends testAddWaybill
- * @depends testUserMark
- * @depends testAddWaybillZX
- */
- public function testWaybillEndAudit(User $user,Waybill $waybill,User $userMark,Waybill $waybillZX){
- //第一次请求成功
- $response=$this->actingAs($user)->json('post','waybill/waybillEndAudit',['id'=>$waybill->id]);
- $response->assertJson(['success'=>true]);
- $responseMark=$this->actingAs($userMark)->json('post','waybill/waybillEndAudit',['id'=>$waybill->id]);
- $responseMark->assertStatus(302)->assertRedirect('/');
- //异常时
- $waybillZX->waybill_price_model_id=null;
- $waybillZX->save();
- $response=$this->actingAs($user)->json('post','waybill/waybillEndAudit',['id'=>$waybillZX->id]);
- $response->assertJson(['success'=>true]);
- //第二次请求拦截
- $responseRe=$this->actingAs($user)->json('post','waybill/waybillEndAudit',['id'=>$waybill->id]);
- $responseRe->assertJson(['exception'=>'请勿重复审核!']);
- }
- /**
- * @depends testAddWaybill
- * @depends testUser
- * @depends testUserMark
- * @depends testRole
- * @depends testAddWaybillZX
- * @depends testAddWaybillZX
- * @depends testAddWaybillPriceModel
- * @depends testAddCarrier
- * @depends testAddWaybillPriceModelTwo
- */
- public function testDestroy(Waybill $waybill,User $user,User $userMark,Role $role,Waybill $waybillZX,WaybillPriceModel $waybillPriceModel,Carrier $carrier,WaybillPriceModel $waybillPriceModelTwo){
- $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);
- $waybillPayoffsZX=WaybillPayoff::where('waybill_id','=',$waybillZX->id)->first();
- $this->assertNotEmpty($waybillPayoffsZX);
- $waybillPayoffsZX->delete();
- $result=$waybillZX->delete();
- $this->assertTrue($result);
- $this->assertNotEmpty($waybillPriceModel);
- $resultWaybillPriceModel=$waybillPriceModel->delete();
- $this->assertTrue($resultWaybillPriceModel);
- $this->assertNotEmpty($waybillPriceModelTwo);
- $resultWaybillPriceModelTwo=$waybillPriceModelTwo->delete();
- $this->assertTrue($resultWaybillPriceModelTwo);
- $this->assertNotEmpty($carrier);
- $resultCarrier=$carrier->delete();
- $this->assertTrue($resultCarrier);
- $waybillFinancialSnapshots=WaybillFinancialSnapshot::where('waybill_id','=',$waybill->id)->first();
- $r=$waybillFinancialSnapshots->delete();
- $this->assertTrue($r);
- $waybillFinancialSnapshotsZX=WaybillFinancialExcepted::where('waybill_id','=',$waybillZX->id)->first();
- $resultZX=$waybillFinancialSnapshotsZX->delete();
- $this->assertTrue($resultZX);
- $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();
- }
- }
|