Strings.webalize().phpt 731 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. * Test: Nette\Utils\Strings::webalize()
  4. */
  5. declare(strict_types=1);
  6. use Nette\Utils\Strings;
  7. use Tester\Assert;
  8. require __DIR__ . '/../bootstrap.php';
  9. Assert::same(
  10. 'zlutoucky-kun-oeooo',
  11. Strings::webalize('&ŽLUŤOUČKÝ KŮŇ öőôo!'),
  12. );
  13. Assert::same(
  14. 'ZLUTOUCKY-KUN-oeooo',
  15. Strings::webalize('&ŽLUŤOUČKÝ KŮŇ öőôo!', lower: false),
  16. );
  17. if (class_exists('Transliterator') && Transliterator::create('Any-Latin; Latin-ASCII')) {
  18. Assert::same('1-4-!', Strings::webalize("\u{BC} !", '!'));
  19. }
  20. Assert::same('a-b', Strings::webalize("a\u{A0}b")); // non-breaking space
  21. Assert::exception(
  22. fn() => Strings::toAscii("0123456789\xFF"),
  23. Nette\Utils\RegexpException::class,
  24. null,
  25. PREG_BAD_UTF8_ERROR,
  26. );