str.test.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. class StrTest extends PHPUnit_Framework_TestCase {
  3. /**
  4. * Test the Str::encoding method.
  5. *
  6. * @group laravel
  7. */
  8. public function testEncodingShouldReturnApplicationEncoding()
  9. {
  10. $this->assertEquals('UTF-8', Config::get('application.encoding'));
  11. Config::set('application.encoding', 'foo');
  12. $this->assertEquals('foo', Config::get('application.encoding'));
  13. Config::set('application.encoding', 'UTF-8');
  14. }
  15. /**
  16. * Test the Str::length method.
  17. *
  18. * @group laravel
  19. */
  20. public function testStringLengthIsCorrect()
  21. {
  22. $this->assertEquals(6, Str::length('Taylor'));
  23. $this->assertEquals(5, Str::length('ラドクリフ'));
  24. }
  25. /**
  26. * Test the Str::lower method.
  27. *
  28. * @group laravel
  29. */
  30. public function testStringCanBeConvertedToLowercase()
  31. {
  32. $this->assertEquals('taylor', Str::lower('TAYLOR'));
  33. $this->assertEquals('άχιστη', Str::lower('ΆΧΙΣΤΗ'));
  34. }
  35. /**
  36. * Test the Str::upper method.
  37. *
  38. * @group laravel
  39. */
  40. public function testStringCanBeConvertedToUppercase()
  41. {
  42. $this->assertEquals('TAYLOR', Str::upper('taylor'));
  43. $this->assertEquals('ΆΧΙΣΤΗ', Str::upper('άχιστη'));
  44. }
  45. /**
  46. * Test the Str::title method.
  47. *
  48. * @group laravel
  49. */
  50. public function testStringCanBeConvertedToTitleCase()
  51. {
  52. $this->assertEquals('Taylor', Str::title('taylor'));
  53. $this->assertEquals('Άχιστη', Str::title('άχιστη'));
  54. }
  55. /**
  56. * Test the Str::limit method.
  57. *
  58. * @group laravel
  59. */
  60. public function testStringCanBeLimitedByCharacters()
  61. {
  62. $this->assertEquals('Tay...', Str::limit('Taylor', 3));
  63. $this->assertEquals('Taylor', Str::limit('Taylor', 6));
  64. $this->assertEquals('Tay___', Str::limit('Taylor', 3, '___'));
  65. }
  66. /**
  67. * Test the Str::words method.
  68. *
  69. * @group laravel
  70. */
  71. public function testStringCanBeLimitedByWords()
  72. {
  73. $this->assertEquals('Taylor...', Str::words('Taylor Otwell', 1));
  74. $this->assertEquals('Taylor___', Str::words('Taylor Otwell', 1, '___'));
  75. $this->assertEquals('Taylor Otwell', Str::words('Taylor Otwell', 3));
  76. }
  77. /**
  78. * Test the Str::plural and Str::singular methods.
  79. *
  80. * @group laravel
  81. */
  82. public function testStringsCanBeSingularOrPlural()
  83. {
  84. $this->assertEquals('user', Str::singular('users'));
  85. $this->assertEquals('users', Str::plural('user'));
  86. $this->assertEquals('User', Str::singular('Users'));
  87. $this->assertEquals('Users', Str::plural('User'));
  88. $this->assertEquals('user', Str::plural('user', 1));
  89. $this->assertEquals('users', Str::plural('user', 2));
  90. }
  91. /**
  92. * Test the Str::slug method.
  93. *
  94. * @group laravel
  95. */
  96. public function testStringsCanBeSlugged()
  97. {
  98. $this->assertEquals('my-new-post', Str::slug('My nEw post!!!'));
  99. $this->assertEquals('my_new_post', Str::slug('My nEw post!!!', '_'));
  100. }
  101. /**
  102. * Test the Str::classify method.
  103. *
  104. * @group laravel
  105. */
  106. public function testStringsCanBeClassified()
  107. {
  108. $this->assertEquals('Something_Else', Str::classify('something.else'));
  109. $this->assertEquals('Something_Else', Str::classify('something_else'));
  110. }
  111. /**
  112. * Test the Str::random method.
  113. *
  114. * @group laravel
  115. */
  116. public function testRandomStringsCanBeGenerated()
  117. {
  118. $this->assertEquals(40, strlen(Str::random(40)));
  119. }
  120. }