1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00
Files
parsedown/tests/src/Configurables/HeaderSlugTest.php
2020-05-10 14:32:01 +01:00

61 lines
1.7 KiB
PHP

<?php
namespace Erusev\Parsedown\Tests\Configurables;
use Erusev\Parsedown\Configurables\HeaderSlug;
use Erusev\Parsedown\Configurables\SlugRegister;
use Erusev\Parsedown\State;
use PHPUnit\Framework\TestCase;
final class HeaderSlugTest extends TestCase
{
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testNamedConstructor()
{
$State = new State([HeaderSlug::enabled()]);
$this->assertSame(true, $State->get(HeaderSlug::class)->isEnabled());
}
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testCustomCallback()
{
$HeaderSlug = HeaderSlug::withCallback(function (string $t): string {
return \preg_replace('/[^A-Za-z0-9]++/', '_', $t);
});
$this->assertSame(
'foo_bar',
$HeaderSlug->transform(SlugRegister::initial(), 'foo bar')
);
}
/**
* @return void
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testCustomDuplicationCallback()
{
$HeaderSlug = HeaderSlug::withDuplicationCallback(function (string $t, int $n): string {
return $t . '_' . \strval($n-1);
});
$SlugRegister = new SlugRegister;
$HeaderSlug->transform($SlugRegister, 'foo bar');
$this->assertSame(
'foo-bar_1',
$HeaderSlug->transform($SlugRegister, 'foo bar')
);
}
}