From b15194edcf08a02268314857d7169dff29815ed1 Mon Sep 17 00:00:00 2001 From: Jisse Reitsma Date: Thu, 3 Oct 2024 20:07:50 +0200 Subject: [PATCH] Rename module from Yireo_HyvaCheckoutUtils to Yireo_HyvaThemeAutoRegistration --- .module.ini | 6 +- Observer/RegisterModuleForHyvaConfig.php | 28 ++------ README.md | 9 +-- Test/Integration/ModuleTest.php | 26 ++++++++ .../RegisterModuleForHyvaConfigTest.php | 64 +++++++++++++++++++ .../_files/Foo_Bar1/etc/module.xml | 5 ++ .../_files/Foo_Bar1/registration.php | 6 ++ .../view/frontend/tailwind/tailwind.config.js | 1 + .../_files/Yireo_Foobar1/etc/module.xml | 5 ++ .../_files/Yireo_Foobar1/registration.php | 6 ++ .../view/frontend/tailwind/tailwind.config.js | 1 + Utils/HyvaFiles.php | 26 +++++++- Utils/RegisterHyvaModule.php | 15 ----- composer.json | 6 +- etc/frontend/events.xml | 2 +- etc/module.xml | 2 +- registration.php | 3 +- 17 files changed, 157 insertions(+), 54 deletions(-) create mode 100644 Test/Integration/ModuleTest.php create mode 100644 Test/Integration/Observer/RegisterModuleForHyvaConfigTest.php create mode 100644 Test/Integration/_files/Foo_Bar1/etc/module.xml create mode 100644 Test/Integration/_files/Foo_Bar1/registration.php create mode 100644 Test/Integration/_files/Foo_Bar1/view/frontend/tailwind/tailwind.config.js create mode 100644 Test/Integration/_files/Yireo_Foobar1/etc/module.xml create mode 100644 Test/Integration/_files/Yireo_Foobar1/registration.php create mode 100644 Test/Integration/_files/Yireo_Foobar1/view/frontend/tailwind/tailwind.config.js delete mode 100644 Utils/RegisterHyvaModule.php diff --git a/.module.ini b/.module.ini index 4e98c92..729f359 100644 --- a/.module.ini +++ b/.module.ini @@ -1,4 +1,4 @@ EXTENSION_VENDOR="Yireo" -EXTENSION_NAME="Yireo_HyvaCheckoutUtils" -COMPOSER_NAME="yireo/magento2-hyva-checkout-utils" -PHP_VERSIONS=("8.1", "8.2") +EXTENSION_NAME="Yireo_HyvaThemeAutoRegistration" +COMPOSER_NAME="yireo/magento2-hyva-theme-auto-registration" +PHP_VERSIONS=("8.1", "8.2", "8.3") diff --git a/Observer/RegisterModuleForHyvaConfig.php b/Observer/RegisterModuleForHyvaConfig.php index 911ea06..6d22f44 100644 --- a/Observer/RegisterModuleForHyvaConfig.php +++ b/Observer/RegisterModuleForHyvaConfig.php @@ -1,15 +1,14 @@ getEvent(); $config = $event->getData('config'); $extensions = $config->hasData('extensions') ? $config->getData('extensions') : []; @@ -47,7 +46,7 @@ public function execute(Observer $event) continue; } - if (false === $this->hasHyvaFiles($moduleName)) { + if (false === $this->hyvaFiles->hasHyvaFiles($moduleName)) { continue; } @@ -62,21 +61,4 @@ private function allowModuleName(string $moduleName): bool { return (bool) preg_match('/^(Yireo|YireoTraining)_/', $moduleName); } - - /** - * @param string $moduleName - * @return bool - * @throws FileSystemException - */ - private function hasHyvaFiles(string $moduleName): bool - { - $path = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName); - foreach ($this->hyvaFiles->getFiles() as $file) { - if ($this->fileDriver->isExists($path . '/' . $file)) { - return true; - } - } - - return false; - } } diff --git a/README.md b/README.md index 54d86f4..0c72c25 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Yireo HyvaCheckoutUtils +# Yireo HyvaThemeAutoRegistration **Magento 2 module to make it easier to register a custom `tailwind.config.js` file of your own module in the global Hyvä Themes Tailwind configuration** ### Background @@ -14,15 +14,12 @@ Next, add the following DI configuration to your module its `etc/di.xml` file (a - + - Foo_Bar + Foo_Bar ``` - -### Todo -Rename this module from `Yireo_HyvaCheckoutUtils` to something like `Yireo_HyvaThemesAutoRegistration` because this has zero to do with the checkout. diff --git a/Test/Integration/ModuleTest.php b/Test/Integration/ModuleTest.php new file mode 100644 index 0000000..19c3604 --- /dev/null +++ b/Test/Integration/ModuleTest.php @@ -0,0 +1,26 @@ +assertModuleIsRegistered($moduleName); + $this->assertModuleIsRegisteredForReal($moduleName); + $this->assertModuleIsEnabled($moduleName); + } +} \ No newline at end of file diff --git a/Test/Integration/Observer/RegisterModuleForHyvaConfigTest.php b/Test/Integration/Observer/RegisterModuleForHyvaConfigTest.php new file mode 100644 index 0000000..1428e6c --- /dev/null +++ b/Test/Integration/Observer/RegisterModuleForHyvaConfigTest.php @@ -0,0 +1,64 @@ +get(EventManagerConfig::class); + $observers = $eventManagerConfig->getObservers('hyva_config_generate_before'); + + $foundObserver = false; + $debugInfo = []; + foreach($observers as $observer) { + $debugInfo[] = $observer; + if ($observer['instance'] === RegisterModuleForHyvaConfig::class) { + $foundObserver = true; + } + } + + $this->assertTrue($foundObserver, var_export($debugInfo, true)); + } + + #[ComponentsDir('./_files')] + public function testIfObserverExecutionIncludesConstructorBasedModules() + { + // @todo: Enable the relevant module + + $observer = $this->getObserver(); + $target = ObjectManager::getInstance()->get(RegisterModuleForHyvaConfig::class); + $target->execute($observer); + + $this->assertNotEmpty($observer->getEvent()->getConfig()['extensions']); + $this->assertObserverEventContainsModule($observer, 'Yireo_Foobar1'); + } + + private function getObserver(): Observer + { + $config = new DataObject(['extensions' => []]); + $event = new DataObject(['config' => $config]); + $observer = ObjectManager::getInstance()->create(Observer::class); + $observer->setEvent($event); + return $observer; + } + + private function assertObserverEventContainsModule(Observer $observer, string $moduleName) + { + $extensions = $observer->getEvent()->getConfig()['extensions']; + $this->assertContains($moduleName, $extensions); + } +} \ No newline at end of file diff --git a/Test/Integration/_files/Foo_Bar1/etc/module.xml b/Test/Integration/_files/Foo_Bar1/etc/module.xml new file mode 100644 index 0000000..0e24685 --- /dev/null +++ b/Test/Integration/_files/Foo_Bar1/etc/module.xml @@ -0,0 +1,5 @@ + + + + diff --git a/Test/Integration/_files/Foo_Bar1/registration.php b/Test/Integration/_files/Foo_Bar1/registration.php new file mode 100644 index 0000000..575168d --- /dev/null +++ b/Test/Integration/_files/Foo_Bar1/registration.php @@ -0,0 +1,6 @@ + + + + diff --git a/Test/Integration/_files/Yireo_Foobar1/registration.php b/Test/Integration/_files/Yireo_Foobar1/registration.php new file mode 100644 index 0000000..8618285 --- /dev/null +++ b/Test/Integration/_files/Yireo_Foobar1/registration.php @@ -0,0 +1,6 @@ +componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName); + foreach ($this->getFiles() as $file) { + if ($this->fileDriver->isExists($path . '/' . $file)) { + return true; + } + } + + return false; + } } diff --git a/Utils/RegisterHyvaModule.php b/Utils/RegisterHyvaModule.php deleted file mode 100644 index fb1903a..0000000 --- a/Utils/RegisterHyvaModule.php +++ /dev/null @@ -1,15 +0,0 @@ - - + diff --git a/etc/module.xml b/etc/module.xml index e2949cf..4c5fd93 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,5 +1,5 @@ - + diff --git a/registration.php b/registration.php index e640c74..0431866 100644 --- a/registration.php +++ b/registration.php @@ -1,5 +1,6 @@