From 0ad91b88f885241a6de2d22e72e323a889047ca6 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Fri, 21 Jan 2022 20:41:13 +0200 Subject: [PATCH] Fix publish views location (#19) * Fix publish views location * Add tests --- phpunit.xml | 7 ++- .../lang/en/env-editor.php | 0 .../views/components/_backup.blade.php | 0 .../views/components/_configActions.blade.php | 0 .../views/components/_currentEnv.blade.php | 0 .../views/components/_itemModal.blade.php | 0 .../views/components/_upload.blade.php | 0 .../views/index.blade.php | 0 .../views/layout.blade.php | 0 src/ServiceProvider.php | 8 +-- tests/Feature/UiTest.php | 54 +++++++++++++++++++ tests/TestCase.php | 35 ++++++------ tests/{ => Unit}/FilesManagerTest.php | 3 +- tests/fixtures/.env.example | 16 ++++++ 14 files changed, 101 insertions(+), 22 deletions(-) rename {src/resources => resources}/lang/en/env-editor.php (100%) rename {src/resources => resources}/views/components/_backup.blade.php (100%) rename {src/resources => resources}/views/components/_configActions.blade.php (100%) rename {src/resources => resources}/views/components/_currentEnv.blade.php (100%) rename {src/resources => resources}/views/components/_itemModal.blade.php (100%) rename {src/resources => resources}/views/components/_upload.blade.php (100%) rename {src/resources => resources}/views/index.blade.php (100%) rename {src/resources => resources}/views/layout.blade.php (100%) create mode 100644 tests/Feature/UiTest.php rename tests/{ => Unit}/FilesManagerTest.php (98%) create mode 100644 tests/fixtures/.env.example diff --git a/phpunit.xml b/phpunit.xml index 02c1e78..f9e2343 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -10,8 +10,11 @@ processIsolation="false" stopOnFailure="true"> - - ./tests/ + + ./tests/Unit + + + ./tests/Feature diff --git a/src/resources/lang/en/env-editor.php b/resources/lang/en/env-editor.php similarity index 100% rename from src/resources/lang/en/env-editor.php rename to resources/lang/en/env-editor.php diff --git a/src/resources/views/components/_backup.blade.php b/resources/views/components/_backup.blade.php similarity index 100% rename from src/resources/views/components/_backup.blade.php rename to resources/views/components/_backup.blade.php diff --git a/src/resources/views/components/_configActions.blade.php b/resources/views/components/_configActions.blade.php similarity index 100% rename from src/resources/views/components/_configActions.blade.php rename to resources/views/components/_configActions.blade.php diff --git a/src/resources/views/components/_currentEnv.blade.php b/resources/views/components/_currentEnv.blade.php similarity index 100% rename from src/resources/views/components/_currentEnv.blade.php rename to resources/views/components/_currentEnv.blade.php diff --git a/src/resources/views/components/_itemModal.blade.php b/resources/views/components/_itemModal.blade.php similarity index 100% rename from src/resources/views/components/_itemModal.blade.php rename to resources/views/components/_itemModal.blade.php diff --git a/src/resources/views/components/_upload.blade.php b/resources/views/components/_upload.blade.php similarity index 100% rename from src/resources/views/components/_upload.blade.php rename to resources/views/components/_upload.blade.php diff --git a/src/resources/views/index.blade.php b/resources/views/index.blade.php similarity index 100% rename from src/resources/views/index.blade.php rename to resources/views/index.blade.php diff --git a/src/resources/views/layout.blade.php b/resources/views/layout.blade.php similarity index 100% rename from src/resources/views/layout.blade.php rename to resources/views/layout.blade.php diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 0a1f831..d89c987 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -62,8 +62,8 @@ public function register() private function loadResources(): void { $this->loadRoutesFrom(__DIR__.'/routes.php'); - $this->loadViewsFrom(__DIR__.'/resources/views', $this->package); - $this->loadTranslationsFrom(__DIR__.'/resources/lang', $this->package); + $this->loadViewsFrom(__DIR__.'/../resources/views', $this->package); + $this->loadTranslationsFrom(__DIR__.'/../resources/lang', $this->package); } private function publishResources(): void @@ -73,11 +73,11 @@ private function publishResources(): void ], 'config'); $this->publishes([ - __DIR__.'/resources/views/' => resource_path("views/vendor/{$this->vendor}/{$this->package}"), + __DIR__.'/../resources/views' => resource_path("/views/vendor/{$this->package}"), ], 'views'); $this->publishes([ - __DIR__.'/resources/lang/' => resource_path("lang/vendor/{$this->vendor}"), + __DIR__.'/../resources/lang/' => resource_path("lang/vendor/{$this->package}"), ], 'translations'); } } diff --git a/tests/Feature/UiTest.php b/tests/Feature/UiTest.php new file mode 100644 index 0000000..961631a --- /dev/null +++ b/tests/Feature/UiTest.php @@ -0,0 +1,54 @@ +get($this->makeRoute('index')); + $response->assertStatus(200) + ->assertSee(trans('env-editor::env-editor.menuTitle')); + } + + /** + * @test + */ + public function can_see_backups(): void + { + $response = $this->get($this->makeRoute('getBackups')); + $response->assertStatus(200) + ->assertSee(trans('env-editor::env-editor.views.backup.title')); + } + + /** + * @test + */ + public function can_download(): void + { + EnvEditor::shouldReceive('getFilePath')->once()->with('fooBar')->andReturns(self::getTestFile(true)); + $response = $this->get($this->makeRoute('download', ['filename' => 'fooBar'])); + $response->assertStatus(200); + $response->assertDownload(self::getTestFile()); + } + + + /** + * @param string $route + * @param array $parameters + * @return string + */ + protected function makeRoute(string $route, array $parameters = []): string + { + return route(config('env-editor.route.name').'.'.$route, $parameters); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 66e66e4..0c34d0d 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -4,29 +4,23 @@ use GeoSot\EnvEditor\Facades\EnvEditor; use GeoSot\EnvEditor\ServiceProvider; +use Illuminate\Encryption\Encrypter; use Orchestra\Testbench\TestCase as OrchestraTestCase; -/** - * Class TestCase. - */ -class TestCase extends OrchestraTestCase + +abstract class TestCase extends OrchestraTestCase { - private $tempDir; - /** - * @inheritdoc - */ protected function getEnvironmentSetUp($app) { - // set up database configuration - $app['config']->set('database.default', 'testbench'); - $app['config']->set('database.connections.testbench', [ - 'driver' => 'sqlite', - 'database' => ':memory:', - 'prefix' => '', - ]); + $key = 'base64:'.base64_encode( + Encrypter::generateKey('AES-256-CBC') + ); + + $app['config']->set('app.key', $key); } + /** * @inheritdoc */ @@ -46,4 +40,15 @@ protected function getPackageAliases($app) 'env-editor' => EnvEditor::class, ]; } + + protected static function getTestPath(): string + { + return realpath(__DIR__.'/fixtures'); + } + + protected static function getTestFile(bool $fullPath = false): string + { + $file = '.env.example'; + return $fullPath ? static::getTestPath().DIRECTORY_SEPARATOR.$file : $file; + } } diff --git a/tests/FilesManagerTest.php b/tests/Unit/FilesManagerTest.php similarity index 98% rename from tests/FilesManagerTest.php rename to tests/Unit/FilesManagerTest.php index a856e81..f0e57d2 100644 --- a/tests/FilesManagerTest.php +++ b/tests/Unit/FilesManagerTest.php @@ -1,9 +1,10 @@