diff --git a/Config/config.php b/Config/config.php index e67c03c..2bb6e56 100644 --- a/Config/config.php +++ b/Config/config.php @@ -29,7 +29,7 @@ "router", "translator", "monolog.logger.mautic", - "mautic.helper.encryption", + "mautic.multicaptcha.helper.encryption", "mautic.lead.model.lead", "mautic.lead.model.company", "mautic.helper.paths", @@ -50,7 +50,7 @@ "router", "translator", "monolog.logger.mautic", - "mautic.helper.encryption", + "mautic.multicaptcha.helper.encryption", "mautic.lead.model.lead", "mautic.lead.model.company", "mautic.helper.paths", diff --git a/Config/services.php b/Config/services.php index 3d10d55..547b43a 100644 --- a/Config/services.php +++ b/Config/services.php @@ -3,6 +3,7 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Mautic\CoreBundle\DependencyInjection\MauticCoreExtension; +use Mautic\CoreBundle\Helper\EncryptionHelper; return static function(ContainerConfigurator $configurator): void { $services = $configurator->services() @@ -11,6 +12,9 @@ ->autoconfigure() ->public(); + // Legacy config.php treats FQCN arguments as strings, so use a local service alias. + $services->alias("mautic.multicaptcha.helper.encryption", EncryptionHelper::class); + $services->load("MauticPlugin\\MauticMultiCaptchaBundle\\", "../") ->exclude(sprintf("../{%s}", implode(",", MauticCoreExtension::DEFAULT_EXCLUDES))); }; diff --git a/README.md b/README.md index 074ae45..ca26433 100644 --- a/README.md +++ b/README.md @@ -76,3 +76,17 @@ Add the "Cloudflare Turnstile" field to the form and save changes. | Explicit consent mode: | Implicit consent mode: | |----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------| | ![Cloudflare Turnstile](.github/doc/turnstile_preview.png "Mautic Form with Cloudflare Turnstile") | ![Cloudflare Turnstile implied consent](.github/doc/turnstile_preview_implicit.png "Mautic Form with Cloudflare Turnstile (implied consent)") | + +## Integration service regression test + +With this plugin installed in a Mautic checkout, run the following as the Mautic +filesystem user (use the project root containing `vendor/autoload.php`): + +```sh +MAUTIC_ROOT=/path/to/mautic php -d memory_limit=1G plugins/MauticMultiCaptchaBundle/Tests/integration-services.php +``` + +For a Composer installation, the script is under `docroot/plugins/` instead. +The test compiles a fresh container in a temporary cache directory, instantiates +all three CAPTCHA integrations, and removes its cache afterward. It does not +change integration settings or validate challenges with external providers. diff --git a/Tests/integration-services.php b/Tests/integration-services.php new file mode 100644 index 0000000..5d5eb37 --- /dev/null +++ b/Tests/integration-services.php @@ -0,0 +1,59 @@ +testRoot; + } + + public function getCacheDir(): string + { + return $this->testCache; + } +} + +$cache = sys_get_temp_dir() . '/multicaptcha-services-' . bin2hex(random_bytes(8)); +$kernel = new MultiCaptchaTestKernel($root, $cache); +$status = 0; +try { + // A fresh container is essential: an existing prod cache can hide broken wiring. + $kernel->boot(); + $container = $kernel->getContainer(); + foreach (['hcaptcha' => 'Hcaptcha', 'recaptcha' => 'Recaptcha', 'turnstile' => 'Turnstile'] as $id => $name) { + $expected = 'MauticPlugin\\MauticMultiCaptchaBundle\\Integration\\' . $name . 'Integration'; + // Boot alone misses a literal class-name string injected instead of the helper. + $integration = $container->get('mautic.integration.' . $id); + if (!$integration instanceof $expected) { + throw new RuntimeException('Unexpected integration class for ' . $id); + } + echo 'PASS ' . $id . PHP_EOL; + } + echo 'PASS Mautic ' . $kernel->getVersion() . PHP_EOL; +} catch (Throwable $exception) { + fwrite(STDERR, get_class($exception) . ': ' . $exception->getMessage() . PHP_EOL); + $status = 1; +} finally { + $kernel->shutdown(); + (new Symfony\Component\Filesystem\Filesystem())->remove($cache); +} +exit($status);