diff --git a/src/Console/CreateSettingsFieldForModel.php b/src/Console/CreateSettingsFieldForModel.php index 17a015d..68ee931 100644 --- a/src/Console/CreateSettingsFieldForModel.php +++ b/src/Console/CreateSettingsFieldForModel.php @@ -4,8 +4,8 @@ use Illuminate\Console\Command; use Illuminate\Filesystem\Filesystem; -use Illuminate\Support\Str; use Illuminate\Support\Facades\Schema; +use Illuminate\Support\Str; class CreateSettingsFieldForModel extends Command { diff --git a/src/Console/CreateSettingsTable.php b/src/Console/CreateSettingsTable.php index e4036c8..5a4b0f7 100644 --- a/src/Console/CreateSettingsTable.php +++ b/src/Console/CreateSettingsTable.php @@ -4,8 +4,8 @@ use Illuminate\Console\Command; use Illuminate\Filesystem\Filesystem; -use Illuminate\Support\Str; use Illuminate\Support\Facades\Schema; +use Illuminate\Support\Str; class CreateSettingsTable extends Command { diff --git a/tests/ConsoleCommandTest.php b/tests/ConsoleCommandTest.php new file mode 100644 index 0000000..f3e3fdc --- /dev/null +++ b/tests/ConsoleCommandTest.php @@ -0,0 +1,43 @@ +artisan('model-settings:model-settings-table') + ->assertExitCode(0); + + config(['model_settings.settings_table_name' => 'custom_settings_table']); + $this->artisan('model-settings:model-settings-table') + ->assertExitCode(0); + + config(['model_settings.settings_table_name' => null]); + $this->artisan('model-settings:model-settings-table') + ->assertExitCode(0); + } + + public function testModelSettingsFieldCommand() + { + $this->artisan('model-settings:model-settings-field') + ->expectsQuestion('What is the name of the table?', '') + ->assertExitCode(0); + + $this->artisan('model-settings:model-settings-field') + ->expectsQuestion('What is the name of the table?', 'users_with_field') + ->expectsQuestion('What is the name of the settings field name?', 'settings') + ->assertExitCode(0); + + $table = 'users_with_table'; + $fieldName = 'custom_settings_field'; + $this->artisan('model-settings:model-settings-field') + ->expectsQuestion('What is the name of the table?', $table) + ->expectsQuestion('What is the name of the settings field name?', $fieldName) + ->assertExitCode(0); + + $this->artisan('model-settings:model-settings-field') + ->expectsQuestion('What is the name of the table?', $table . '_wrong') + ->assertExitCode(0); + } +} diff --git a/tests/FieldSettingsManagerTest.php b/tests/FieldSettingsManagerTest.php index 81fa7b7..3d5ab70 100644 --- a/tests/FieldSettingsManagerTest.php +++ b/tests/FieldSettingsManagerTest.php @@ -74,6 +74,12 @@ public function testGet() * @throws \Exception */ public function testApply() + { + $this->model->settings()->apply($this->testArray); + $this->assertEquals($this->model->fresh()->settings()->all(), $this->testArray); + } + + public function testPersistence() { $this->model->settings()->apply($this->testArray); $this->assertEquals($this->model->fresh()->settings()->all(), $this->testArray); @@ -84,6 +90,13 @@ public function testApply() $this->model->settings()->apply($this->testArray); $this->assertEquals($this->model->fresh()->settings()->all(), []); + $this->model->setPersistSettings(false); + $this->model->settings()->apply($this->testArray); + $this->model->save(); + $this->assertEquals($this->model->fresh()->settings()->all(), $this->testArray); + + $this->model->settings()->delete(); + $this->model->fresh(); $this->model->setPersistSettings(true); $this->model->settings()->apply($this->testArray);