Skip to content

Commit

Permalink
Merge pull request #160 from dealroom/feature/DEV/fix-match
Browse files Browse the repository at this point in the history
DEV: Fix TwitterNormalizer matching
  • Loading branch information
pfuhrmann authored Jul 5, 2024
2 parents 8cefeb9 + 10ffde2 commit b2bff72
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Normalizers/TwitterNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Normalizers/YoutubeNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ public static function getPlatform(): string

protected array|int $idPosition = 1;

protected array $cleanUrlSettings = [ 'forceLowerCase' => false ];
protected array $cleanUrlSettings = ['forceLowerCase' => false];
}
28 changes: 28 additions & 0 deletions tests/NormalizersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];

Expand All @@ -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());
Expand Down

0 comments on commit b2bff72

Please sign in to comment.