StrTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * Draft 0.2 for PHP argument order fix
  4. * 2012-04-14 ms
  5. */
  6. App::uses('Str', 'Tools.Utility');
  7. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  8. /**
  9. * @see https://bugs.php.net/bug.php?id=44794
  10. * 2012-04-14 ms
  11. */
  12. class StrTest extends MyCakeTestCase {
  13. /**
  14. * fixed
  15. * - documented return type (mixed)
  16. * - argument order
  17. * - missing underscore
  18. */
  19. public function testStrStr() {
  20. $res = Str::str('some', 'more some text');
  21. $expected = 'some text';
  22. $this->assertSame($expected, $res);
  23. $res = Str::str('some', 'more som text');
  24. $expected = false;
  25. $this->assertSame($expected, $res);
  26. }
  27. /**
  28. * No changes
  29. *
  30. * @return void
  31. */
  32. public function testStrReplace() {
  33. $res = Str::replace('some', 'more', 'in some text');
  34. $expected = 'in more text';
  35. $this->assertSame($expected, $res);
  36. $count = 0;
  37. $res = Str::replace('some', 'more', 'in some text', $count);
  38. $this->assertSame($expected, $res);
  39. $this->assertSame(1, $count);
  40. }
  41. /**
  42. * No changes
  43. *
  44. * @return void
  45. */
  46. public function testSubstrReplace() {
  47. $res = Str::substrReplace('some', 'more', 0, 0);
  48. $expected = 'moresome';
  49. $this->assertSame($expected, $res);
  50. $res = Str::substrReplace('some', 'more', 1, 0);
  51. $expected = 'smoreome';
  52. $this->assertSame($expected, $res);
  53. }
  54. /**
  55. * No changes
  56. *
  57. * @return void
  58. */
  59. public function testCount() {
  60. $res = Str::count('more', 'some more and more text');
  61. $this->assertSame(2, $res);
  62. $res = Str::count('more', 'some text');
  63. $this->assertSame(0, $res);
  64. $res = Str::count('more', 'some more and more text and even more text', 10, 20);
  65. $this->assertSame(1, $res);
  66. }
  67. /**
  68. * Very strange method
  69. *
  70. * fixed
  71. * - documented return type (mixed)
  72. * - argument order
  73. * - missing underscore
  74. * - naming scheme
  75. *
  76. * @return void
  77. */
  78. public function testStrLastChr() {
  79. $res = Str::lastChr('some', 'more some text');
  80. $expected = 'some text';
  81. $this->assertSame($expected, $res);
  82. # WTF?
  83. $res = Str::lastChr('some', 'more som text');
  84. $expected = 'som text';
  85. $this->assertSame($expected, $res);
  86. $res = Str::lastChr('xome', 'more som text');
  87. $expected = 'xt';
  88. $this->assertSame($expected, $res);
  89. $res = Str::lastChr('abc', 'more som text');
  90. $expected = false;
  91. $this->assertSame($expected, $res);
  92. $res = Str::lastChr(120, 'more som text');
  93. $expected = 'xt';
  94. $this->assertSame($expected, $res);
  95. }
  96. }