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)); } }