Merge the Smartlinks plugin (SmartlinksBundle 0.6.0) into the bundle as the Smart Links domain (0.18.0)

Two domains, one MT3S bundle: Marketing Programs (unchanged) and the
imported Smart Links (smart links + UTM taxonomies), each keeping its
own menu, tables, routes and translations.

- Code moved from MauticPlugin\SmartlinksBundle\ to
  MauticPlugin\MT3SMarketingProgramBundle\; template namespace
  @Smartlinks/ -> @MT3SMarketingProgram/; smartlinks.js ->
  Assets/js/mt3s-mp-smartlinks.js; icon -> Assets/img/smartlinks-icon.svg.
- Incoming migrations renamed Version_0_X_0_SmartLinks.php to avoid
  the class-name collision; schema untouched, data intact.
- Permissions folded into MT3SMarketingProgramPermissions:
  smart_links + taxonomies under the mt3smarketingprogram: base
  (roles that had the old smartlinks: grants must be re-granted).
- config.php: Smart Links routes + menu group, public /l/{slug},
  SmartlinksIntegration services, smartlinks_* parameters (legacy
  utm_manager_* keys still readable), version 0.18.0. The 0.17.0
  placeholder /s/marketing-program-utm-taxonomies is replaced by the
  real /s/utm-taxonomies.
- Translations merged (en_US) and added (fr_FR); Tests/ + phpunit moved
  in; readme documents both domains and the 0.18.0 merge history.

Verified live: menus, both config tabs, both lists + forms, program
pages, public redirect with taxonomy UTM values, host + unknown-slug
404s, 90/90 unit tests, full php -l, all ini catalogs parse.
This commit is contained in:
Alexandre Gain committed 2026-11-16 13:48:13 +01:00
1 parent debce4ba4a
commit dce849610c
69 files changed
+8225 -43

No files matched your search

@@ -0,0 +1,155 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\MT3SMarketingProgramBundle\Tests\Unit\Form\Validator;
use Mautic\CoreBundle\Helper\CoreParametersHelper;
use MauticPlugin\MT3SMarketingProgramBundle\Catalog\UtmParameterCatalog;
use MauticPlugin\MT3SMarketingProgramBundle\Entity\UtmTaxonomy;
use MauticPlugin\MT3SMarketingProgramBundle\Form\Validator\SmartLinkValidator;
use MauticPlugin\MT3SMarketingProgramBundle\Model\SmartLinkModel;
use MauticPlugin\MT3SMarketingProgramBundle\Service\UtmConfigurationNormalizer;
use MauticPlugin\MT3SMarketingProgramBundle\Service\UtmConfigurationProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Contracts\Translation\TranslatorInterface;
final class SmartLinkValidatorTest extends TestCase
{
/**
* The stored configuration of a link that has no taxonomy: a dropdown utm_source
* (newsletter, linkedin) and a free utm_campaign.
*/
private const RAW_CONFIG = [
'enforce_lowercase' => '1',
'separator_replacement' => '-',
'parameters' => [
'utm_source' => [
'enabled' => '1', 'label' => 'Source', 'mode' => 'dropdown',
'values' => [
['value' => 'newsletter', 'label' => 'Newsletter'],
['value' => 'linkedin', 'label' => 'LinkedIn'],
],
],
'utm_campaign' => ['enabled' => '1', 'label' => 'Campaign', 'mode' => 'free'],
],
];
private function createValidator(array $raw = self::RAW_CONFIG): SmartLinkValidator
{
$parameters = $this->createMock(CoreParametersHelper::class);
$parameters->method('get')->willReturnMap([
[UtmConfigurationProvider::CONFIG_PARAMETER, [], $raw],
]);
$translator = $this->createMock(TranslatorInterface::class);
$translator->method('trans')->willReturnCallback(fn (string $id): string => $id);
$provider = new UtmConfigurationProvider(
$parameters,
new UtmConfigurationNormalizer(new UtmParameterCatalog()),
new UtmParameterCatalog(),
$translator
);
return new SmartLinkValidator($this->createMock(SmartLinkModel::class), $provider);
}
private function createTaxonomy(array $parameters): UtmTaxonomy
{
$taxonomy = new UtmTaxonomy();
$taxonomy->setName('Spring campaigns');
$taxonomy->setParameters($parameters);
return $taxonomy;
}
public function testTaxonomyValuesAreAccepted(): void
{
$taxonomy = $this->createTaxonomy([
'utm_source' => [['value' => 'newsletter', 'label' => 'Newsletter']],
'utm_campaign' => [['value' => 'spring', 'label' => 'Spring']],
]);
$this->assertSame([], $this->createValidator()->validateUtmParameters([
'utm_source' => 'newsletter',
'utm_campaign' => 'spring',
], $taxonomy));
}
public function testValuesOutsideTheTaxonomyAreRejected(): void
{
$taxonomy = $this->createTaxonomy([
'utm_source' => [['value' => 'newsletter', 'label' => 'Newsletter']],
]);
$errors = $this->createValidator()->validateUtmParameters([
'utm_source' => 'linkedin',
], $taxonomy);
$this->assertSame([[SmartLinkValidator::ERROR_UTM_VALUE_NOT_ALLOWED, ['%key%' => 'utm_source', '%value%' => 'linkedin']]], $errors);
}
public function testAStoredValueSurvivesAPlainReSave(): void
{
$taxonomy = $this->createTaxonomy([
'utm_source' => [['value' => 'newsletter', 'label' => 'Newsletter']],
]);
$this->assertSame([], $this->createValidator()->validateUtmParameters(
['utm_source' => 'legacy_banner'],
$taxonomy,
['utm_source' => 'legacy_banner']
));
}
public function testFreeParametersTakeTheirValuesFromTheTaxonomyList(): void
{
// The admin left utm_campaign free, but the taxonomy carries its own value list: the
// link picks a value from it, nothing is free-typed.
$taxonomy = $this->createTaxonomy([
'utm_campaign' => [
['value' => 'spring', 'label' => 'Spring'],
['value' => 'summer', 'label' => 'Summer'],
],
]);
$this->assertSame([], $this->createValidator()->validateUtmParameters([
'utm_campaign' => 'spring',
], $taxonomy));
$this->assertSame(
[[SmartLinkValidator::ERROR_UTM_VALUE_NOT_ALLOWED, ['%key%' => 'utm_campaign', '%value%' => 'autumn']]],
$this->createValidator()->validateUtmParameters(['utm_campaign' => 'autumn'], $taxonomy)
);
}
public function testParametersTheTaxonomyDoesntDefineAreRejected(): void
{
// The taxonomy defines neither the configured dropdown utm_source nor the free
// utm_campaign: both are unknown to it.
$taxonomy = $this->createTaxonomy([]);
$this->assertSame(
[[SmartLinkValidator::ERROR_TAXONOMY_PARAMETER_UNKNOWN, ['%key%' => 'utm_source', '%name%' => 'Spring campaigns']]],
$this->createValidator()->validateUtmParameters(['utm_source' => 'newsletter'], $taxonomy)
);
$this->assertSame(
[[SmartLinkValidator::ERROR_TAXONOMY_PARAMETER_UNKNOWN, ['%key%' => 'utm_campaign', '%name%' => 'Spring campaigns']]],
$this->createValidator()->validateUtmParameters(['utm_campaign' => 'spring'], $taxonomy)
);
}
public function testWithoutATaxonomyTheGlobalConfigurationApplies(): void
{
$validator = $this->createValidator();
// Free parameter: any well-formed value; dropdown: only the configured list.
$this->assertSame([], $validator->validateUtmParameters(['utm_campaign' => 'spring', 'utm_source' => 'newsletter']));
$this->assertSame([], $validator->validateUtmParameters(['utm_campaign' => 'spring'], null, ['utm_campaign' => 'spring']));
$this->assertSame(
[[SmartLinkValidator::ERROR_UTM_VALUE_NOT_ALLOWED, ['%key%' => 'utm_source', '%value%' => 'facebook']]],
$validator->validateUtmParameters(['utm_source' => 'facebook'])
);
}
}