Files
mautic-marketing-program-bu…/Tests/Unit/Entity/SmartLinkTest.php
T
Alexandre Gain dce849610c 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.
2026-11-16 13:48:13 +01:00

83 lines
3.0 KiB
PHP

<?php
declare(strict_types=1);
namespace MauticPlugin\MT3SMarketingProgramBundle\Tests\Unit\Entity;
use MauticPlugin\MT3SMarketingProgramBundle\Catalog\SmartLinkRedirectCode;
use MauticPlugin\MT3SMarketingProgramBundle\Catalog\SmartLinkRedirectType;
use MauticPlugin\MT3SMarketingProgramBundle\Entity\SmartLink;
use PHPUnit\Framework\TestCase;
final class SmartLinkTest extends TestCase
{
public function testSlugIsImmutableOnceSaved(): void
{
$link = new SmartLink();
$link->setSlug('abc');
// Not saved yet: the slug can still be set.
$link->setSlug('xyz');
$this->assertSame('xyz', $link->getSlug());
$reflection = new \ReflectionClass(SmartLink::class);
$property = $reflection->getProperty('id');
$property->setValue($link, 1);
// Saved: the same slug is accepted (no-op), a different one is refused.
$link->setSlug('xyz');
$this->assertSame('xyz', $link->getSlug());
$this->expectException(\LogicException::class);
$link->setSlug('other');
}
public function testMauticRedirectHasNoDestination(): void
{
$link = new SmartLink();
$link->setRedirectType(SmartLinkRedirectType::External);
$link->setDestinationUrl('https://www.example.com');
$this->assertSame('https://www.example.com', $link->getDestinationUrl());
$link->setRedirectType(SmartLinkRedirectType::Mautic);
$this->assertNull($link->getDestinationUrl());
}
public function testBlankDestinationIsNormalizedToNull(): void
{
$link = new SmartLink();
$link->setDestinationUrl(' ');
$this->assertNull($link->getDestinationUrl());
}
public function testUtmParametersAreStoredAsGiven(): void
{
// The model (normalizeUtmValues) cleans the values before they reach the entity.
$link = new SmartLink();
$link->setUtmParameters(['utm_source' => 'newsletter']);
$this->assertSame(['utm_source' => 'newsletter'], $link->getUtmParameters());
$link->setUtmParameters(null);
$this->assertSame([], $link->getUtmParameters());
}
public function testShortLinkIsBuiltFromDomainAndSlug(): void
{
$link = new SmartLink();
$link->setSlug('ab3x');
$this->assertSame('https://lnk.example.com/l/ab3x', $link->getShortLink('lnk.example.com'));
$this->assertSame('https://lnk.example.com/l/ab3x', $link->getShortLink('lnk.example.com/'));
$this->assertSame('', $link->getShortLink(''));
}
public function testRedirectEnums(): void
{
$this->assertTrue(SmartLinkRedirectType::External->isExternal());
$this->assertTrue(SmartLinkRedirectType::Mautic->isMautic());
$this->assertSame(SmartLinkRedirectCode::MovedPermanently, SmartLinkRedirectCode::tryFrom(301));
$this->assertSame(SmartLinkRedirectCode::PermanentRedirect, SmartLinkRedirectCode::tryFrom(308));
$this->assertNull(SmartLinkRedirectCode::tryFrom(418));
}
}