2
2
3
3
namespace Bakerkretzmar \NovaSettingsTool \Tests ;
4
4
5
+ use Bakerkretzmar \NovaSettingsTool \Events \SettingsChanged ;
6
+ use Illuminate \Support \Facades \Event ;
5
7
use Illuminate \Support \Facades \Storage ;
6
8
7
9
class SettingsToolControllerTest extends TestCase
8
10
{
9
11
/** @test */
10
12
public function can_read_settings ()
11
13
{
12
- $ response = $ this ->get ('nova-vendor/settings-tool ' );
13
-
14
- $ response ->assertSuccessful ();
15
- $ response ->assertJsonFragment ([
16
- 'key ' => 'test_setting ' ,
17
- 'value ' => 'https://example.com ' ,
18
- ]);
14
+ $ this ->get ('nova-vendor/settings-tool ' )
15
+ ->assertSuccessful ()
16
+ ->assertJsonFragment ([
17
+ 'key ' => 'test_setting ' ,
18
+ 'value ' => 'https://example.com ' ,
19
+ ]);
19
20
}
20
21
21
22
/** @test */
@@ -28,37 +29,49 @@ public function can_read_settings_from_custom_path()
28
29
29
30
config (['nova-settings-tool.path ' => base_path () . '/storage/app/public/custom/configurations.json ' ]);
30
31
31
- $ response = $ this ->get ('nova-vendor/settings-tool ' );
32
-
33
- $ response ->assertSuccessful ();
34
- $ response ->assertJsonFragment ([
35
- 'key ' => 'test_setting ' ,
36
- 'value ' => 'https://example.com ' ,
37
- ]);
32
+ $ this ->get ('nova-vendor/settings-tool ' )
33
+ ->assertSuccessful ()
34
+ ->assertJsonFragment ([
35
+ 'key ' => 'test_setting ' ,
36
+ 'value ' => 'https://example.com ' ,
37
+ ]);
38
38
}
39
39
40
40
/** @test */
41
41
public function can_fill_default_setting_metadata_automatically ()
42
42
{
43
- $ response = $ this ->get ('nova-vendor/settings-tool ' );
44
-
45
- $ response ->assertJsonFragment ([
46
- 'key ' => 'setting_with_no_metadata ' ,
47
- 'type ' => 'text ' ,
48
- 'label ' => 'Setting_with_no_metadata ' ,
49
- 'value ' => null ,
50
- ]);
43
+ $ this ->get ('nova-vendor/settings-tool ' )
44
+ ->assertJsonFragment ([
45
+ 'key ' => 'setting_with_no_metadata ' ,
46
+ 'type ' => 'text ' ,
47
+ 'label ' => 'Setting_with_no_metadata ' ,
48
+ 'value ' => null ,
49
+ ]);
51
50
}
52
51
53
52
/** @test */
54
53
public function can_write_settings ()
55
54
{
56
- $ response = $ this ->postJson ('nova-vendor/settings-tool ' , [
55
+ $ this ->postJson ('nova-vendor/settings-tool ' , [
57
56
'test_setting ' => 'http://google.ca ' ,
58
- ]);
59
-
60
- $ response ->assertSuccessful ();
57
+ ])->assertSuccessful ();
61
58
$ this ->assertArrayHasKey ('test_setting ' , json_decode (Storage::get ('settings.json ' ), true ));
62
59
$ this ->assertSame ('http://google.ca ' , json_decode (Storage::get ('settings.json ' ), true )['test_setting ' ]);
63
60
}
61
+
62
+ /** @test */
63
+ public function can_emit_event_when_settings_updated ()
64
+ {
65
+ Event::fake ();
66
+
67
+ $ this ->postJson ('nova-vendor/settings-tool ' , [
68
+ 'test_setting ' => 'http://google.ca ' ,
69
+ ])->assertSuccessful ();
70
+
71
+ Event::assertDispatched (function (SettingsChanged $ event ) {
72
+ $ this ->assertSame ('http://google.ca ' , $ event ->settings ['test_setting ' ]);
73
+ $ this ->assertSame ('https://example.com ' , $ event ->oldSettings ['test_setting ' ]);
74
+ return true ;
75
+ });
76
+ }
64
77
}
0 commit comments