InflectorTest.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. use Codeception\Util\Fixtures;
  3. use Grav\Common\Grav;
  4. use Grav\Common\Inflector;
  5. use Grav\Common\Utils;
  6. /**
  7. * Class InflectorTest
  8. */
  9. class InflectorTest extends \Codeception\TestCase\Test
  10. {
  11. /** @var Grav $grav */
  12. protected $grav;
  13. /** @var Inflector $uri */
  14. protected $inflector;
  15. protected function _before(): void
  16. {
  17. $grav = Fixtures::get('grav');
  18. $this->grav = $grav();
  19. $this->inflector = $this->grav['inflector'];
  20. }
  21. protected function _after(): void
  22. {
  23. }
  24. public function testPluralize(): void
  25. {
  26. self::assertSame('words', $this->inflector->pluralize('word'));
  27. self::assertSame('kisses', $this->inflector->pluralize('kiss'));
  28. self::assertSame('volcanoes', $this->inflector->pluralize('volcanoe'));
  29. self::assertSame('cherries', $this->inflector->pluralize('cherry'));
  30. self::assertSame('days', $this->inflector->pluralize('day'));
  31. self::assertSame('knives', $this->inflector->pluralize('knife'));
  32. }
  33. public function testSingularize(): void
  34. {
  35. self::assertSame('word', $this->inflector->singularize('words'));
  36. self::assertSame('kiss', $this->inflector->singularize('kisses'));
  37. self::assertSame('volcanoe', $this->inflector->singularize('volcanoe'));
  38. self::assertSame('cherry', $this->inflector->singularize('cherries'));
  39. self::assertSame('day', $this->inflector->singularize('days'));
  40. self::assertSame('knife', $this->inflector->singularize('knives'));
  41. }
  42. public function testTitleize(): void
  43. {
  44. self::assertSame('This String Is Titleized', $this->inflector->titleize('ThisStringIsTitleized'));
  45. self::assertSame('This String Is Titleized', $this->inflector->titleize('this string is titleized'));
  46. self::assertSame('This String Is Titleized', $this->inflector->titleize('this_string_is_titleized'));
  47. self::assertSame('This String Is Titleized', $this->inflector->titleize('this-string-is-titleized'));
  48. self::assertSame('This string is titleized', $this->inflector->titleize('ThisStringIsTitleized', 'first'));
  49. self::assertSame('This string is titleized', $this->inflector->titleize('this string is titleized', 'first'));
  50. self::assertSame('This string is titleized', $this->inflector->titleize('this_string_is_titleized', 'first'));
  51. self::assertSame('This string is titleized', $this->inflector->titleize('this-string-is-titleized', 'first'));
  52. }
  53. public function testCamelize(): void
  54. {
  55. self::assertSame('ThisStringIsCamelized', $this->inflector->camelize('This String Is Camelized'));
  56. self::assertSame('ThisStringIsCamelized', $this->inflector->camelize('thisStringIsCamelized'));
  57. self::assertSame('ThisStringIsCamelized', $this->inflector->camelize('This_String_Is_Camelized'));
  58. self::assertSame('ThisStringIsCamelized', $this->inflector->camelize('this string is camelized'));
  59. self::assertSame('GravSPrettyCoolMy1', $this->inflector->camelize("Grav's Pretty Cool. My #1!"));
  60. }
  61. public function testUnderscorize(): void
  62. {
  63. self::assertSame('this_string_is_underscorized', $this->inflector->underscorize('This String Is Underscorized'));
  64. self::assertSame('this_string_is_underscorized', $this->inflector->underscorize('ThisStringIsUnderscorized'));
  65. self::assertSame('this_string_is_underscorized', $this->inflector->underscorize('This_String_Is_Underscorized'));
  66. self::assertSame('this_string_is_underscorized', $this->inflector->underscorize('This-String-Is-Underscorized'));
  67. }
  68. public function testHyphenize(): void
  69. {
  70. self::assertSame('this-string-is-hyphenized', $this->inflector->hyphenize('This String Is Hyphenized'));
  71. self::assertSame('this-string-is-hyphenized', $this->inflector->hyphenize('ThisStringIsHyphenized'));
  72. self::assertSame('this-string-is-hyphenized', $this->inflector->hyphenize('This-String-Is-Hyphenized'));
  73. self::assertSame('this-string-is-hyphenized', $this->inflector->hyphenize('This_String_Is_Hyphenized'));
  74. }
  75. public function testHumanize(): void
  76. {
  77. //self::assertSame('This string is humanized', $this->inflector->humanize('ThisStringIsHumanized'));
  78. self::assertSame('This string is humanized', $this->inflector->humanize('this_string_is_humanized'));
  79. //self::assertSame('This string is humanized', $this->inflector->humanize('this-string-is-humanized'));
  80. self::assertSame('This String Is Humanized', $this->inflector->humanize('this_string_is_humanized', 'all'));
  81. //self::assertSame('This String Is Humanized', $this->inflector->humanize('this-string-is-humanized'), 'all');
  82. }
  83. public function testVariablize(): void
  84. {
  85. self::assertSame('thisStringIsVariablized', $this->inflector->variablize('This String Is Variablized'));
  86. self::assertSame('thisStringIsVariablized', $this->inflector->variablize('ThisStringIsVariablized'));
  87. self::assertSame('thisStringIsVariablized', $this->inflector->variablize('This_String_Is_Variablized'));
  88. self::assertSame('thisStringIsVariablized', $this->inflector->variablize('this string is variablized'));
  89. self::assertSame('gravSPrettyCoolMy1', $this->inflector->variablize("Grav's Pretty Cool. My #1!"));
  90. }
  91. public function testTableize(): void
  92. {
  93. self::assertSame('people', $this->inflector->tableize('Person'));
  94. self::assertSame('pages', $this->inflector->tableize('Page'));
  95. self::assertSame('blog_pages', $this->inflector->tableize('BlogPage'));
  96. self::assertSame('admin_dependencies', $this->inflector->tableize('adminDependency'));
  97. self::assertSame('admin_dependencies', $this->inflector->tableize('admin-dependency'));
  98. self::assertSame('admin_dependencies', $this->inflector->tableize('admin_dependency'));
  99. }
  100. public function testClassify(): void
  101. {
  102. self::assertSame('Person', $this->inflector->classify('people'));
  103. self::assertSame('Page', $this->inflector->classify('pages'));
  104. self::assertSame('BlogPage', $this->inflector->classify('blog_pages'));
  105. self::assertSame('AdminDependency', $this->inflector->classify('admin_dependencies'));
  106. }
  107. public function testOrdinalize(): void
  108. {
  109. self::assertSame('1st', $this->inflector->ordinalize(1));
  110. self::assertSame('2nd', $this->inflector->ordinalize(2));
  111. self::assertSame('3rd', $this->inflector->ordinalize(3));
  112. self::assertSame('4th', $this->inflector->ordinalize(4));
  113. self::assertSame('5th', $this->inflector->ordinalize(5));
  114. self::assertSame('16th', $this->inflector->ordinalize(16));
  115. self::assertSame('51st', $this->inflector->ordinalize(51));
  116. self::assertSame('111th', $this->inflector->ordinalize(111));
  117. self::assertSame('123rd', $this->inflector->ordinalize(123));
  118. }
  119. public function testMonthize(): void
  120. {
  121. self::assertSame(0, $this->inflector->monthize(10));
  122. self::assertSame(1, $this->inflector->monthize(33));
  123. self::assertSame(1, $this->inflector->monthize(41));
  124. self::assertSame(11, $this->inflector->monthize(364));
  125. }
  126. }