diff --git a/src/Normalizers/TwitterNormalizer.php b/src/Normalizers/TwitterNormalizer.php index 2551952..312a0b6 100644 --- a/src/Normalizers/TwitterNormalizer.php +++ b/src/Normalizers/TwitterNormalizer.php @@ -37,7 +37,7 @@ protected function match(string $url): array if (strlen($matches[1]) > 15) { throw new NormalizeException( - sprintf('%s name can not be longer than 15 chars: %s', static::getPlatform(), $matches[4]) + sprintf('%s name can not be longer than 15 chars: %s', static::getPlatform(), $matches[1]) ); } diff --git a/src/Normalizers/YoutubeNormalizer.php b/src/Normalizers/YoutubeNormalizer.php index f1c426d..30b5685 100644 --- a/src/Normalizers/YoutubeNormalizer.php +++ b/src/Normalizers/YoutubeNormalizer.php @@ -19,5 +19,5 @@ public static function getPlatform(): string protected array|int $idPosition = 1; - protected array $cleanUrlSettings = [ 'forceLowerCase' => false ]; + protected array $cleanUrlSettings = ['forceLowerCase' => false]; } diff --git a/tests/NormalizersTest.php b/tests/NormalizersTest.php index 389a01e..d2137ff 100644 --- a/tests/NormalizersTest.php +++ b/tests/NormalizersTest.php @@ -40,6 +40,7 @@ public function testTwitterNormalizer(): void 'https://twitter.com/code-school' => 'https://twitter.com/code', 'https://twitter.com/code_school' => 'https://twitter.com/code_school', 'https://twitter.com/greentextbooks#' => 'https://twitter.com/greentextbooks', + 'https://twitter.com/grEEntextbooks' => 'https://twitter.com/greentextbooks', 'https://twitter.com/shopbop#cs=ov=73421773243,os=1,link=footerconnecttwitterlink\',' => 'https://twitter.com/shopbop', ]; @@ -51,6 +52,33 @@ public function testTwitterNormalizer(): void $twitterNormalizer->normalize('https://twitter.com/share'); } + public function testTwitterUrlPatternMismatchThrowsNormalizeException(): void + { + $twitterNormalizer = Factory::getForPlatform(TwitterNormalizer::getPlatform()); + + $this->expectException(NormalizeException::class); + $this->expectExceptionMessage("twitter pattern didn't match for https://invalidtwitter.com"); + $twitterNormalizer->normalize('https://invalidtwitter.com'); + } + + public function testTwitterNameEqualToShareThrowsNormalizeException(): void + { + $twitterNormalizer = Factory::getForPlatform(TwitterNormalizer::getPlatform()); + + $this->expectException(NormalizeException::class); + $this->expectExceptionMessage("twitter name can not be equal to share"); + $twitterNormalizer->normalize('https://twitter.com/share'); + } + + public function testTwitterNameLongerThan15CharsThrowsNormalizeException(): void + { + $twitterNormalizer = Factory::getForPlatform(TwitterNormalizer::getPlatform()); + + $this->expectException(NormalizeException::class); + $this->expectExceptionMessage("twitter name can not be longer than 15 chars: thisiswaytoolongusername"); + $twitterNormalizer->normalize('https://twitter.com/thisiswaytoolongusername'); + } + public function testXNormalizer(): void { $twitterNormalizer = Factory::getForPlatform(XNormalizer::getPlatform());