InflectorTest.php 7.4 KB

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