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('mautic.smartlinks.config.parameter.'.$key.'.label', $definition->getLabelKey()); $this->assertSame('mautic.smartlinks.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('mautic.smartlinks.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 */ 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 */ 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]; } }