AdminInitCommandTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Tests\Feature;
  3. use App\Console\Commands\AdminInitCommand;
  4. use Illuminate\Support\Facades\DB;
  5. use Tests\TestCase;
  6. use Illuminate\Foundation\Testing\RefreshDatabase;
  7. class AdminInitCommandTest extends TestCase
  8. {
  9. use RefreshDatabase;
  10. public function testInit()
  11. {
  12. $this->artisan('admin:init')
  13. ->expectsQuestion(AdminInitCommand::$initConfirmTip, false)
  14. ->assertExitCode(1);
  15. $this->artisan('admin:init')
  16. ->expectsQuestion(AdminInitCommand::$initConfirmTip, true)
  17. ->assertExitCode(0);
  18. $this->assertDatabaseHas('vue_routers', [
  19. 'id' => 1,
  20. 'path' => 'index',
  21. 'title' => '首页',
  22. ]);
  23. $this->assertDatabaseHas('admin_users', [
  24. 'username' => 'admin',
  25. ]);
  26. $this->assertDatabaseHas('admin_roles', [
  27. 'slug' => 'administrator',
  28. ]);
  29. $this->assertDatabaseHas('admin_permissions', [
  30. 'slug' => 'pass-all',
  31. 'http_path' => '*',
  32. ]);
  33. $this->assertDatabaseHas('config_categories', [
  34. 'id' => 1,
  35. 'slug' => 'system_basic',
  36. ]);
  37. $this->assertDatabaseHas('configs', [
  38. 'category_id' => 1,
  39. 'slug' => 'app_name',
  40. ]);
  41. // 命令中用了 truncate,会导致回滚失败,所以手动清理一下
  42. $tables = [
  43. 'vue_routers',
  44. 'admin_users',
  45. 'admin_roles',
  46. 'admin_permissions',
  47. 'config_categories',
  48. 'configs',
  49. 'admin_role_permission',
  50. 'admin_user_permission',
  51. 'admin_user_role',
  52. 'vue_router_role',
  53. ];
  54. foreach ($tables as $table) {
  55. DB::table($table)->truncate();
  56. }
  57. }
  58. }