+ *
+ * @experimental in 5.0
+ */
+interface SluggerInterface
+{
+ /**
+ * Creates a slug for the given string and locale, using appropriate transliteration when needed.
+ */
+ public function slug(string $string, string $separator = '-', string $locale = null): AbstractUnicodeString;
+}
diff --git a/src/Symfony/Component/String/Tests/SluggerTest.php b/src/Symfony/Component/String/Tests/SluggerTest.php
new file mode 100644
index 000000000000..d796dde11b72
--- /dev/null
+++ b/src/Symfony/Component/String/Tests/SluggerTest.php
@@ -0,0 +1,49 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\String\Tests;
+
+use PHPUnit\Framework\TestCase;
+use Symfony\Component\String\Slugger\AsciiSlugger;
+
+class SluggerTest extends TestCase
+{
+ /**
+ * @requires extension intl
+ * @dataProvider provideSlug
+ */
+ public function testSlug(string $string, string $locale, string $expectedSlug)
+ {
+ $slugger = new AsciiSlugger($locale);
+
+ $this->assertSame($expectedSlug, (string) $slugger->slug($string));
+ }
+
+ public static function provideSlug(): array
+ {
+ return [
+ ['Стойността трябва да бъде лъжа', 'bg', 'Stoinostta-tryabva-da-bude-luzha'],
+ ['Dieser Wert sollte größer oder gleich', 'de', 'Dieser-Wert-sollte-groesser-oder-gleich'],
+ ['Dieser Wert sollte größer oder gleich', 'de_AT', 'Dieser-Wert-sollte-groesser-oder-gleich'],
+ ['Αυτή η τιμή πρέπει να είναι ψευδής', 'el', 'Avti-i-timi-prepi-na-inai-psevdhis'],
+ ['该变量的值应为', 'zh', 'gai-bian-liang-de-zhi-ying-wei'],
+ ['該變數的值應為', 'zh_TW', 'gai-bian-shu-de-zhi-ying-wei'],
+ ];
+ }
+
+ public function testSeparatorWithoutLocale()
+ {
+ $slugger = new AsciiSlugger();
+
+ $this->assertSame('hello-world', (string) $slugger->slug('hello world'));
+ $this->assertSame('hello_world', (string) $slugger->slug('hello world', '_'));
+ }
+}
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy