2
2
3
3
namespace Hyde \Framework \Testing \Unit ;
4
4
5
+ use Hyde \Framework \Contracts \AssetServiceContract ;
6
+ use Hyde \Framework \Hyde ;
5
7
use Hyde \Framework \HydeServiceProvider ;
8
+ use Hyde \Framework \Models \Pages \BladePage ;
9
+ use Hyde \Framework \Models \Pages \DocumentationPage ;
10
+ use Hyde \Framework \Models \Pages \MarkdownPage ;
11
+ use Hyde \Framework \Models \Pages \MarkdownPost ;
12
+ use Hyde \Framework \Modules \DataCollections \DataCollectionServiceProvider ;
13
+ use Hyde \Framework \Services \AssetService ;
14
+ use Hyde \Framework \StaticPageBuilder ;
6
15
use Hyde \Testing \TestCase ;
16
+ use Illuminate \Support \Facades \Artisan ;
7
17
18
+ /**
19
+ * @todo #162 Improve testing for this class.
20
+ *
21
+ * @covers \Hyde\Framework\HydeServiceProvider
22
+ * @covers \Hyde\Framework\Concerns\RegistersFileLocations
23
+ */
8
24
class HydeServiceProviderTest extends TestCase
9
25
{
10
26
protected HydeServiceProvider $ provider ;
11
27
12
28
public function setUp (): void
13
29
{
14
- $ this ->provider = new HydeServiceProvider (app ());
15
-
16
30
parent ::setUp ();
31
+
32
+ $ this ->provider = new HydeServiceProvider (app ());
17
33
}
18
34
19
35
public function test_provider_is_constructed ()
@@ -30,4 +46,114 @@ public function test_provider_has_boot_method()
30
46
{
31
47
$ this ->assertTrue (method_exists ($ this ->provider , 'boot ' ));
32
48
}
49
+
50
+ public function test_provider_registers_asset_service_contract ()
51
+ {
52
+ $ this ->assertTrue ($ this ->app ->bound (AssetServiceContract::class));
53
+ $ this ->assertInstanceOf (AssetServiceContract::class, $ this ->app ->make (AssetServiceContract::class));
54
+ $ this ->assertInstanceOf (AssetService::class, $ this ->app ->make (AssetServiceContract::class));
55
+ }
56
+
57
+ public function test_provider_registers_source_directories ()
58
+ {
59
+ BladePage::$ sourceDirectory = '' ;
60
+ MarkdownPage::$ sourceDirectory = '' ;
61
+ MarkdownPost::$ sourceDirectory = '' ;
62
+ DocumentationPage::$ sourceDirectory = '' ;
63
+
64
+ $ this ->assertEquals ('' , BladePage::getSourceDirectory ());
65
+ $ this ->assertEquals ('' , MarkdownPage::getSourceDirectory ());
66
+ $ this ->assertEquals ('' , MarkdownPost::getSourceDirectory ());
67
+ $ this ->assertEquals ('' , DocumentationPage::getSourceDirectory ());
68
+
69
+ $ this ->provider ->register ();
70
+
71
+ $ this ->assertEquals ('_pages ' , BladePage::getSourceDirectory ());
72
+ $ this ->assertEquals ('_pages ' , MarkdownPage::getSourceDirectory ());
73
+ $ this ->assertEquals ('_posts ' , MarkdownPost::getSourceDirectory ());
74
+ $ this ->assertEquals ('_docs ' , DocumentationPage::getSourceDirectory ());
75
+ }
76
+
77
+ public function test_provider_registers_output_directories ()
78
+ {
79
+ BladePage::$ outputDirectory = 'foo ' ;
80
+ MarkdownPage::$ outputDirectory = 'foo ' ;
81
+ MarkdownPost::$ outputDirectory = 'foo ' ;
82
+ DocumentationPage::$ outputDirectory = 'foo ' ;
83
+
84
+ $ this ->assertEquals ('foo ' , BladePage::getOutputDirectory ());
85
+ $ this ->assertEquals ('foo ' , MarkdownPage::getOutputDirectory ());
86
+ $ this ->assertEquals ('foo ' , MarkdownPost::getOutputDirectory ());
87
+ $ this ->assertEquals ('foo ' , DocumentationPage::getOutputDirectory ());
88
+
89
+ $ this ->provider ->register ();
90
+
91
+ $ this ->assertEquals ('' , BladePage::getOutputDirectory ());
92
+ $ this ->assertEquals ('' , MarkdownPage::getOutputDirectory ());
93
+ $ this ->assertEquals ('posts ' , MarkdownPost::getOutputDirectory ());
94
+ $ this ->assertEquals ('docs ' , DocumentationPage::getOutputDirectory ());
95
+ }
96
+
97
+ public function test_provider_registers_configured_documentation_output_directory ()
98
+ {
99
+ $ this ->assertEquals ('docs ' , DocumentationPage::getOutputDirectory ());
100
+
101
+ config (['docs.output_directory ' => 'foo ' ]);
102
+
103
+ $ this ->provider ->register ();
104
+
105
+ $ this ->assertEquals ('foo ' , DocumentationPage::getOutputDirectory ());
106
+ }
107
+
108
+ public function test_provider_registers_site_output_directory ()
109
+ {
110
+ $ this ->assertEquals (Hyde::path ('_site ' ), StaticPageBuilder::$ outputPath );
111
+
112
+ config (['hyde.output_directory ' => 'foo ' ]);
113
+
114
+ $ this ->provider ->register ();
115
+
116
+ $ this ->assertEquals (Hyde::path ('foo ' ), StaticPageBuilder::$ outputPath );
117
+ }
118
+
119
+ public function test_provider_registers_blade_view_discovery_location_for_configured_blade_view_path ()
120
+ {
121
+ config (['view.paths ' => []]);
122
+ $ this ->assertEquals ([], config ('view.paths ' ));
123
+
124
+ $ this ->provider ->register ();
125
+
126
+ $ this ->assertEquals ([Hyde::path ('_pages ' )], config ('view.paths ' ));
127
+ }
128
+
129
+ public function test_blade_view_locations_are_only_registered_once_per_key ()
130
+ {
131
+ config (['view.paths ' => []]);
132
+ $ this ->assertEquals ([], config ('view.paths ' ));
133
+
134
+ $ this ->provider ->register ();
135
+ $ this ->provider ->register ();
136
+
137
+ $ this ->assertEquals ([Hyde::path ('_pages ' )], config ('view.paths ' ));
138
+ }
139
+
140
+ public function test_provider_registers_console_commands ()
141
+ {
142
+ $ commands = array_map (function ($ command ) {
143
+ return get_class ($ command );
144
+ }, Artisan::all ());
145
+
146
+ foreach (glob (Hyde::vendorPath ('src/Commands/*.php ' )) as $ file ) {
147
+ $ class = 'Hyde\Framework\Commands \\' .basename ($ file , '.php ' );
148
+
149
+ $ this ->assertContains ($ class , $ commands );
150
+ }
151
+ }
152
+
153
+ public function test_provider_registers_additional_module_service_providers ()
154
+ {
155
+ $ this ->provider ->register ();
156
+
157
+ $ this ->assertArrayHasKey (DataCollectionServiceProvider::class, $ this ->app ->getLoadedProviders ());
158
+ }
33
159
}
0 commit comments