Files
Alexandre Gain 9d81d6c815 refactor(naming): normalise the Smart Links domain to the bundle's canonical names (0.18.1)
One bundle, two domains (Marketing Programs and Smart Links), one naming scheme.\nNothing in the database changed (no tables, columns, URLs or stored data);\nthe runtime was rebuilt and verified live.\n\n- Route names mautic_smartlinks_* -> mt3s_smartlinks_* (paths unchanged);\n  the menu ids follow\n- Model service aliases collapsed to one canonical alias per model:\n  mautic.mt3smarketingprogram.model.<entity> (core's mautic.<x>.model.<x>\n  pattern), so getModel('mt3smarketingprogram.smart_link'); the dead\n  mt3s.* and mautic.mt3smp.*-era aliases are gone\n- Translation keys mautic.smartlinks.* -> mt3s.smart_links.*\n  (mautic.config.tab.smartlinksconfig stays: core derives it)\n- Settings parameters smartlinks_utm_config/smartlinks_config ->\n  mt3s_smart_links_utm_config/mt3s_smart_links_config, with both legacy\n  keys (smartlinks_* of the standalone bundle, utm_manager_* of the\n  UtmManagerBundle era) still readable until the settings are saved again\n- JS loader prefixes smartlinksSmartLink/smartlinksUtmTaxonomy ->\n  mt3sMpSmartLink/mt3sMpUtmTaxonomy (the mt3sMp* family of the program\n  domain)\n- Integration/Support/ConfigSupport -> SmartlinksConfigSupport; integration\n  display names aligned ('MT3S Marketing Program' / 'Smart Links'); the\n  dead mautic.plugin.smartlinks.name catalog keys removed\n- phpunit suite renamed UtmManagerBundle -> MT3SMarketingProgramBundle;\n  version 0.18.1\n\nVerified: full php -l, 90/90 unit tests (phpunit 11.5 phar), cache clear +\nwarm + assets regenerate + plugins reload (as www-data), live: both lists\nand forms (mauticContent mt3sMpSmartLink/mt3sMpUtmTaxonomy), both config\ntabs, the menu labels, the program pages (regression), the public /l/y32b\nredirect through the legacy utm_manager_* settings (302 with the taxonomy's\nUTM values, wrong host and unknown slug 404), all ini catalogs parse, zero\nnew log errors.
2026-11-16 15:47:30 +01:00

148 lines
6.2 KiB
PHP

<?php
declare(strict_types=1);
namespace MauticPlugin\MT3SMarketingProgramBundle\Tests\Unit\Catalog;
use MauticPlugin\MT3SMarketingProgramBundle\Catalog\UtmParameterCatalog;
use MauticPlugin\MT3SMarketingProgramBundle\Catalog\UtmParameterDefinition;
use MauticPlugin\MT3SMarketingProgramBundle\Catalog\UtmParameterMode;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
final class UtmParameterCatalogTest extends TestCase
{
private const STANDARD_MODES = [
'utm_source' => UtmParameterMode::DROPDOWN,
'utm_medium' => UtmParameterMode::DROPDOWN,
'utm_campaign' => UtmParameterMode::FREE,
'utm_term' => UtmParameterMode::FREE,
'utm_content' => UtmParameterMode::FREE,
'utm_id' => UtmParameterMode::FREE,
'utm_source_platform' => UtmParameterMode::DROPDOWN,
'utm_creative_format' => UtmParameterMode::DROPDOWN,
'utm_marketing_tactic' => UtmParameterMode::DROPDOWN,
];
private const PLATFORM_KEYS = ['gclid', 'gbraid', 'wbraid', 'dclid', 'fbclid', 'msclkid', 'ttclid', 'li_fat_id', 'twclid', 'epik'];
private UtmParameterCatalog $catalog;
protected function setUp(): void
{
$this->catalog = new UtmParameterCatalog();
}
public function testCatalogContainsExactlyTheExpectedKeysInOrder(): void
{
$this->assertSame(
array_merge(array_keys(self::STANDARD_MODES), self::PLATFORM_KEYS),
array_keys($this->catalog->all())
);
}
public function testStandardParameters(): void
{
$standard = $this->catalog->getByGroup(UtmParameterCatalog::GROUP_STANDARD);
$this->assertSame(array_keys(self::STANDARD_MODES), array_keys($standard));
foreach (self::STANDARD_MODES as $key => $mode) {
$definition = $standard[$key];
$this->assertSame($mode, $definition->defaultMode, $key);
$this->assertFalse($definition->autoGenerated, $key);
$this->assertSame(UtmParameterMode::ALL, $definition->getAllowedModes(), $key);
$this->assertSame('mt3s.smart_links.config.parameter.'.$key.'.label', $definition->getLabelKey());
$this->assertSame('mt3s.smart_links.config.parameter.'.$key.'.description', $definition->getDescriptionKey());
}
}
public function testPlatformParametersAreAutoGeneratedDisabledAndCannotBeDropdowns(): void
{
$platform = $this->catalog->getByGroup(UtmParameterCatalog::GROUP_PLATFORM);
$this->assertSame(self::PLATFORM_KEYS, array_keys($platform));
foreach ($platform as $key => $definition) {
$this->assertTrue($definition->autoGenerated, $key);
$this->assertSame(UtmParameterMode::DISABLED, $definition->defaultMode, $key);
$this->assertSame([UtmParameterMode::FREE, UtmParameterMode::DISABLED], $definition->getAllowedModes(), $key);
$this->assertFalse($definition->isModeAllowed(UtmParameterMode::DROPDOWN), $key);
$this->assertSame([], $definition->suggestions, $key);
}
}
public function testSuggestionsOnlyForDropdownParameters(): void
{
$this->assertSame(
['newsletter', 'linkedin', 'facebook', 'instagram', 'google', 'youtube', 'x', 'tiktok', 'partner', 'direct'],
$this->catalog->get('utm_source')?->suggestions
);
$this->assertSame(
['email', 'cpc', 'social', 'social_paid', 'display', 'affiliate', 'referral', 'qr', 'sms', 'print', 'event'],
$this->catalog->get('utm_medium')?->suggestions
);
$this->assertSame(['google_ads', 'meta_ads', 'linkedin_ads', 'microsoft_ads', 'tiktok_ads'], $this->catalog->get('utm_source_platform')?->suggestions);
$this->assertSame(['banner', 'video', 'carousel', 'text', 'native'], $this->catalog->get('utm_creative_format')?->suggestions);
$this->assertSame(['prospecting', 'remarketing', 'retargeting', 'brand', 'nurturing'], $this->catalog->get('utm_marketing_tactic')?->suggestions);
foreach ($this->catalog->all() as $key => $definition) {
if (UtmParameterMode::DROPDOWN !== $definition->defaultMode) {
$this->assertSame([], $definition->suggestions, $key);
}
}
$this->assertSame('mt3s.smart_links.config.suggestion.google_ads', UtmParameterDefinition::getSuggestionLabelKey('google_ads'));
}
public function testGetAndHas(): void
{
$this->assertTrue($this->catalog->has('utm_source'));
$this->assertInstanceOf(UtmParameterDefinition::class, $this->catalog->get('gclid'));
$this->assertFalse($this->catalog->has('my_param'));
$this->assertNull($this->catalog->get('my_param'));
}
#[DataProvider('reservedKeys')]
public function testReservedKeys(string $key): void
{
$this->assertTrue($this->catalog->isReservedKey($key));
$this->assertFalse($this->catalog->isValidCustomKey($key));
}
/**
* @return iterable<string, array{string}>
*/
public static function reservedKeys(): iterable
{
yield 'catalog key' => ['utm_source'];
yield 'click id' => ['gclid'];
yield 'mautic click tracking' => ['ct'];
yield 'utm prefix' => ['utm_custom'];
yield 'utm prefix without underscore' => ['utmx'];
yield 'mtc prefix' => ['mtc_id'];
}
#[DataProvider('customKeys')]
public function testCustomKeyFormat(string $key, bool $valid): void
{
$this->assertSame($valid, $this->catalog->isValidCustomKey($key));
}
/**
* @return iterable<string, array{string, bool}>
*/
public static function customKeys(): iterable
{
yield 'simple' => ['ref', true];
yield 'with digits and underscore' => ['partner_id2', true];
yield 'two characters' => ['ab', true];
yield 'max 41 characters' => ['a'.str_repeat('b', 40), true];
yield 'one character' => ['a', false];
yield 'too long' => ['a'.str_repeat('b', 41), false];
yield 'starts with digit' => ['1abc', false];
yield 'starts with underscore' => ['_abc', false];
yield 'uppercase' => ['Abc', false];
yield 'hyphen' => ['my-param', false];
yield 'empty' => ['', false];
}
}