| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace Tests\Unit;
- use App\Authority;
- use App\Role;
- use App\User;
- use App\WaybillFinancialSnapshot;
- use Illuminate\Support\Facades\DB;
- use Tests\TestCase;
- use Illuminate\Foundation\Testing\WithFaker;
- use Illuminate\Foundation\Testing\RefreshDatabase;
- class WaybillFinancialSnapshotTest 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 testAdd(){
- $waybillFinancialSnapshot=new WaybillFinancialSnapshot([
- 'waybill_id'=>1,
- 'json_content'=>"{'waybill_number':'BSZX5416854985'}"
- ]);
- $result=$waybillFinancialSnapshot->save();
- $this->assertTrue($result);
- return $waybillFinancialSnapshot;
- }
- /**
- * @depends testAdd
- * @depends testUser
- * @depends testUserMark
- */
- public function testIndex(WaybillFinancialSnapshot $waybillFinancialSnapshot, User $user,User $userMark){
- $response=$this->actingAs($user)->get('waybill/waybillFinancialSnapshot');
- $response->assertOk()->assertSee('1');
- $responseMark=$this->actingAs($userMark)->get('waybill/waybillFinancialSnapshot');
- $responseMark->assertStatus(302)->assertRedirect('/');
- $waybillFinancialSnapshot=WaybillFinancialSnapshot::paginate(10);
- $this->assertNotEmpty($waybillFinancialSnapshot);
- }
- /**
- * @depends testAdd
- * @depends testUser
- * @depends testUserMark
- * @depends testRole
- */
- public function testDestroy(WaybillFinancialSnapshot $waybillFinancialSnapshot,User $user,User $userMark,Role $role){
- $waybillFinancialSnapshot->delete();
- $result=WaybillFinancialSnapshot::find($waybillFinancialSnapshot->id);
- $this->assertEmpty($result);
- $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();
- }
- }
|