|
|
@@ -32,4 +32,57 @@ class StringsUtilsTest extends TestCase
|
|
|
{
|
|
|
$this->assertEquals('Test contenu', (new StringsUtils())->convertHtmlToText('<table><tr><td>Test</td></tr></table> <br /><p>contenu</p>'));
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see StringsUtils::elide()
|
|
|
+ */
|
|
|
+ public function testElide(): void
|
|
|
+ {
|
|
|
+ // Test normal truncation case - string longer than length
|
|
|
+ $this->assertEquals('Hello...', StringsUtils::elide('Hello World!', 8));
|
|
|
+
|
|
|
+ // Test case where string is shorter than length - no truncation
|
|
|
+ $this->assertEquals('Hello', StringsUtils::elide('Hello', 10));
|
|
|
+
|
|
|
+ // Test edge case with exact length
|
|
|
+ $this->assertEquals('Hello', StringsUtils::elide('Hello', 6));
|
|
|
+
|
|
|
+ // Test with empty string
|
|
|
+ $this->assertEquals('', StringsUtils::elide('', 10));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see StringsUtils::elide()
|
|
|
+ */
|
|
|
+ public function testElideWithMultibyteCharacters(): void
|
|
|
+ {
|
|
|
+ // Test with UTF-8 multibyte characters
|
|
|
+ $this->assertEquals('Héllo...', StringsUtils::elide('Héllo Wörld!', 8));
|
|
|
+ $this->assertEquals('测试中...', StringsUtils::elide('测试中文字符串', 6));
|
|
|
+ $this->assertEquals('🎉🎊🎈🎆🎇', StringsUtils::elide('🎉🎊🎈🎆🎇', 6));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see StringsUtils::elide()
|
|
|
+ */
|
|
|
+ public function testElideWithInvalidLength(): void
|
|
|
+ {
|
|
|
+ $this->expectException(\InvalidArgumentException::class);
|
|
|
+ $this->expectExceptionMessage('Length must be greater than 5');
|
|
|
+
|
|
|
+ StringsUtils::elide('Hello World!', 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see StringsUtils::elide()
|
|
|
+ */
|
|
|
+ public function testElideWithLongString(): void
|
|
|
+ {
|
|
|
+ $longString = str_repeat('A', 1000);
|
|
|
+ $result = StringsUtils::elide($longString, 50);
|
|
|
+
|
|
|
+ $this->assertEquals(50, mb_strlen($result)); // 47 + 3 dots
|
|
|
+ $this->assertTrue(str_ends_with($result, '...'));
|
|
|
+ $this->assertEquals(str_repeat('A', 47) . '...', $result);
|
|
|
+ }
|
|
|
}
|