Skip to content

Commit

Permalink
[String] Add tests for AsciiSlugger
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrixx committed Aug 12, 2022
1 parent e4d0e8e commit 69084de
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions Tests/Slugger/AsciiSluggerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\String;

use PHPUnit\Framework\TestCase;
use Symfony\Component\String\Slugger\AsciiSlugger;

class AsciiSluggerTest extends TestCase
{
public function provideSlugTests(): iterable
{
yield ['', ''];
yield ['foo', ' foo '];
yield ['foo-bar', 'foo bar'];

yield ['foo-bar', 'foo@bar', '-'];
yield ['foo-at-bar', 'foo@bar', '-', 'en'];

yield ['e-a', 'é$!à'];
yield ['e_a', 'é$!à', '_'];

yield ['a', 'ä'];
yield ['a', 'ä', '-', 'fr'];
yield ['ae', 'ä', '-', 'de'];
yield ['ae', 'ä', '-', 'de_fr']; // Ensure we get the parent locale
yield ['g', 'ғ', '-'];
yield ['gh', 'ғ', '-', 'uz'];
yield ['gh', 'ғ', '-', 'uz_fr']; // Ensure we get the parent locale
}

/** @dataProvider provideSlugTests */
public function testSlug(string $expected, string $string, string $separator = '-', string $locale = null)
{
$slugger = new AsciiSlugger();

$this->assertSame($expected, (string) $slugger->slug($string, $separator, $locale));
}
}

0 comments on commit 69084de

Please sign in to comment.