Skip to content

Commit

Permalink
Merge branch 'release/3.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
glorand committed Jul 1, 2019
2 parents f73ceed + cc9da43 commit 5bfef33
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Console/CreateSettingsFieldForModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/Console/CreateSettingsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
43 changes: 43 additions & 0 deletions tests/ConsoleCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Glorand\Model\Settings\Tests;

class ConsoleCommandTest extends TestCase
{
public function testModelSettingsTableCommand()
{
$this->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);
}
}
13 changes: 13 additions & 0 deletions tests/FieldSettingsManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 5bfef33

Please sign in to comment.