WaybillFinancialSnapshotTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace Tests\Unit;
  3. use App\Authority;
  4. use App\Role;
  5. use App\User;
  6. use App\WaybillFinancialSnapshot;
  7. use Illuminate\Support\Facades\DB;
  8. use Tests\TestCase;
  9. use Illuminate\Foundation\Testing\WithFaker;
  10. use Illuminate\Foundation\Testing\RefreshDatabase;
  11. class WaybillFinancialSnapshotTest extends TestCase
  12. {
  13. public function testUserMark(){
  14. $userMark=factory(User::class)->create();
  15. $this->assertNotEmpty($userMark->id);
  16. return $userMark;
  17. }
  18. public function testRole(){
  19. $role=Role::create([
  20. 'name'=>'测试admin'
  21. ]);
  22. $this->assertNotEmpty($role->id);
  23. $authorities= Authority::get();
  24. foreach ($authorities as $authority){
  25. DB::table('authority_role')->insert(['id_authority'=>$authority->id,'id_role'=>$role->id]);
  26. }
  27. return $role;
  28. }
  29. /**
  30. * @depends testRole
  31. */
  32. public function testUser(Role $role){
  33. $user=factory(User::class)->create();
  34. DB::table('user_role')->insert(['id_user'=>$user->id,'id_role'=>$role->id]);
  35. $this->assertNotEmpty($user->id);
  36. return $user;
  37. }
  38. public function testAdd(){
  39. $waybillFinancialSnapshot=new WaybillFinancialSnapshot([
  40. 'waybill_id'=>1,
  41. 'json_content'=>"{'waybill_number':'BSZX5416854985'}"
  42. ]);
  43. $result=$waybillFinancialSnapshot->save();
  44. $this->assertTrue($result);
  45. return $waybillFinancialSnapshot;
  46. }
  47. /**
  48. * @depends testAdd
  49. * @depends testUser
  50. * @depends testUserMark
  51. */
  52. public function testIndex(WaybillFinancialSnapshot $waybillFinancialSnapshot, User $user,User $userMark){
  53. $response=$this->actingAs($user)->get('waybill/waybillFinancialSnapshot');
  54. $response->assertOk()->assertSee('1');
  55. $responseMark=$this->actingAs($userMark)->get('waybill/waybillFinancialSnapshot');
  56. $responseMark->assertStatus(302)->assertRedirect('/');
  57. $waybillFinancialSnapshot=WaybillFinancialSnapshot::paginate(10);
  58. $this->assertNotEmpty($waybillFinancialSnapshot);
  59. }
  60. /**
  61. * @depends testAdd
  62. * @depends testUser
  63. * @depends testUserMark
  64. * @depends testRole
  65. */
  66. public function testDestroy(WaybillFinancialSnapshot $waybillFinancialSnapshot,User $user,User $userMark,Role $role){
  67. $waybillFinancialSnapshot->delete();
  68. $result=WaybillFinancialSnapshot::find($waybillFinancialSnapshot->id);
  69. $this->assertEmpty($result);
  70. $result=$user->delete();
  71. $this->assertTrue($result);
  72. $this->assertNotEmpty($userMark->id);
  73. $resultUserMark=$userMark->delete();
  74. $this->assertTrue($resultUserMark);
  75. $resultRole=$role->delete();
  76. $this->assertTrue($resultRole);
  77. DB::table('authority_role')->where('id_role','=',$role->id)->delete();
  78. DB::table('user_role')->where('id_role','=',$role->id)->delete();
  79. }
  80. }