Commit fe46225f authored by Julien Tant's avatar Julien Tant Committed by Nicolas Widart

Fix broken workshop when module name contains dash (#351)

parent 536535e4
...@@ -5,6 +5,7 @@ namespace Modules\Workshop\Scaffold\Module\Generators; ...@@ -5,6 +5,7 @@ namespace Modules\Workshop\Scaffold\Module\Generators;
use Illuminate\Contracts\Config\Repository; use Illuminate\Contracts\Config\Repository;
use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Filesystem\Filesystem; use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
abstract class Generator abstract class Generator
{ {
...@@ -45,7 +46,7 @@ abstract class Generator ...@@ -45,7 +46,7 @@ abstract class Generator
*/ */
public function forModule($moduleName) public function forModule($moduleName)
{ {
$this->name = $moduleName; $this->name = Str::studly($moduleName);
return $this; return $this;
} }
......
...@@ -23,11 +23,16 @@ class ModuleScaffoldTest extends BaseTestCase ...@@ -23,11 +23,16 @@ class ModuleScaffoldTest extends BaseTestCase
* @var string The name of the module under test * @var string The name of the module under test
*/ */
protected $testModuleName; protected $testModuleName;
/**
* @var string The sanitized name of the module under test
*/
protected $testModuleSanitizedName;
public function setUp() public function setUp()
{ {
$this->testModuleName = 'TestingTestModule'; $this->testModuleName = 'Testing_The-TestModule';
$this->testModulePath = __DIR__ . "/../Modules/{$this->testModuleName}"; $this->testModuleSanitizedName = 'TestingTheTestModule';
$this->testModulePath = __DIR__ . "/../Modules/{$this->testModuleSanitizedName}";
$this->cleanUp(); $this->cleanUp();
parent::setUp(); parent::setUp();
...@@ -256,7 +261,7 @@ class ModuleScaffoldTest extends BaseTestCase ...@@ -256,7 +261,7 @@ class ModuleScaffoldTest extends BaseTestCase
$this->scaffoldModuleWithEloquent(); $this->scaffoldModuleWithEloquent();
$file1 = $this->finder->isFile($this->testModulePath . '/Providers/RouteServiceProvider.php'); $file1 = $this->finder->isFile($this->testModulePath . '/Providers/RouteServiceProvider.php');
$file2 = $this->finder->isFile($this->testModulePath . "/Providers/{$this->testModuleName}ServiceProvider.php"); $file2 = $this->finder->isFile($this->testModulePath . "/Providers/{$this->testModuleSanitizedName}ServiceProvider.php");
$this->assertTrue($file1); $this->assertTrue($file1);
$this->assertTrue($file2); $this->assertTrue($file2);
...@@ -269,9 +274,9 @@ class ModuleScaffoldTest extends BaseTestCase ...@@ -269,9 +274,9 @@ class ModuleScaffoldTest extends BaseTestCase
{ {
$this->scaffoldModuleWithEloquent(); $this->scaffoldModuleWithEloquent();
$file = $this->finder->get($this->testModulePath . "/Providers/{$this->testModuleName}ServiceProvider.php"); $file = $this->finder->get($this->testModulePath . "/Providers/{$this->testModuleSanitizedName}ServiceProvider.php");
$sidebarEventListenerName = "Register{$this->testModuleName}Sidebar"; $sidebarEventListenerName = "Register{$this->testModuleSanitizedName}Sidebar";
$this->assertTrue(str_contains( $this->assertTrue(str_contains(
$file, $file,
'$this->loadMigrationsFrom(__DIR__ . \'/../Database/Migrations\');' '$this->loadMigrationsFrom(__DIR__ . \'/../Database/Migrations\');'
...@@ -330,7 +335,7 @@ class ModuleScaffoldTest extends BaseTestCase ...@@ -330,7 +335,7 @@ class ModuleScaffoldTest extends BaseTestCase
{ {
$this->scaffoldModuleWithEloquent(); $this->scaffoldModuleWithEloquent();
$file = $this->finder->isFile($this->testModulePath . '/Events/Handlers/RegisterTestingTestModuleSidebar.php'); $file = $this->finder->isFile($this->testModulePath . "/Events/Handlers/Register{$this->testModuleSanitizedName}Sidebar.php");
$this->assertTrue($file); $this->assertTrue($file);
...@@ -342,10 +347,10 @@ class ModuleScaffoldTest extends BaseTestCase ...@@ -342,10 +347,10 @@ class ModuleScaffoldTest extends BaseTestCase
{ {
$this->scaffoldModuleWithEloquent(); $this->scaffoldModuleWithEloquent();
$file = $this->finder->get($this->testModulePath . '/Events/Handlers/RegisterTestingTestModuleSidebar.php'); $file = $this->finder->get($this->testModulePath . "/Events/Handlers/Register{$this->testModuleSanitizedName}Sidebar.php");
$this->assertTrue(str_contains($file, '$menu->group')); $this->assertTrue(str_contains($file, '$menu->group'));
$this->assertTrue(str_contains($file, 'class RegisterTestingTestModuleSidebar')); $this->assertTrue(str_contains($file, "class Register{$this->testModuleSanitizedName}Sidebar"));
$this->cleanUp(); $this->cleanUp();
} }
...@@ -355,7 +360,7 @@ class ModuleScaffoldTest extends BaseTestCase ...@@ -355,7 +360,7 @@ class ModuleScaffoldTest extends BaseTestCase
{ {
$this->scaffoldModule('Eloquent', [], []); $this->scaffoldModule('Eloquent', [], []);
$file = $this->finder->get($this->testModulePath . '/Events/Handlers/RegisterTestingTestModuleSidebar.php'); $file = $this->finder->get($this->testModulePath . "/Events/Handlers/Register{$this->testModuleSanitizedName}Sidebar.php");
$this->assertFalse(str_contains($file, '$menu->group')); $this->assertFalse(str_contains($file, '$menu->group'));
$this->assertTrue(str_contains($file, 'return $menu')); $this->assertTrue(str_contains($file, 'return $menu'));
...@@ -427,7 +432,7 @@ class ModuleScaffoldTest extends BaseTestCase ...@@ -427,7 +432,7 @@ class ModuleScaffoldTest extends BaseTestCase
$composerJson = $this->getComposerFile(); $composerJson = $this->getComposerFile();
$this->assertEquals('asgardcms/testingtestmodule', $composerJson->name); $this->assertEquals('asgardcms/testingthetestmodule', $composerJson->name);
} }
/** @test */ /** @test */
...@@ -513,7 +518,7 @@ class ModuleScaffoldTest extends BaseTestCase ...@@ -513,7 +518,7 @@ class ModuleScaffoldTest extends BaseTestCase
$this->scaffoldModuleWithEloquent(['Post']); $this->scaffoldModuleWithEloquent(['Post']);
$controllerContents = $this->getAdminControllerFile('Post'); $controllerContents = $this->getAdminControllerFile('Post');
$lowercaseModuleName = strtolower($this->testModuleName); $lowercaseModuleName = strtolower($this->testModuleSanitizedName);
$matches = [ $matches = [
"withSuccess(trans('core::core.messages.resource created', ['name' => trans('{$lowercaseModuleName}::posts.title.posts')]));", "withSuccess(trans('core::core.messages.resource created', ['name' => trans('{$lowercaseModuleName}::posts.title.posts')]));",
...@@ -578,4 +583,4 @@ class ModuleScaffoldTest extends BaseTestCase ...@@ -578,4 +583,4 @@ class ModuleScaffoldTest extends BaseTestCase
return $controllerFile; return $controllerFile;
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment