BootstrapTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. namespace Tools\Test\TestCase;
  3. use DateTime;
  4. use Shim\TestSuite\TestCase;
  5. class BootstrapTest extends TestCase {
  6. /**
  7. * @return void
  8. */
  9. public function testIsEmpty() {
  10. $result = isEmpty(new DateTime(date(FORMAT_DB_DATE)));
  11. $this->assertFalse($result);
  12. }
  13. /**
  14. * @return void
  15. */
  16. public function testStartsWith() {
  17. $strings = [
  18. [
  19. 'auto',
  20. 'au',
  21. true,
  22. ],
  23. [
  24. 'auto',
  25. 'ut',
  26. false,
  27. ],
  28. [
  29. 'Auto',
  30. 'au',
  31. true,
  32. ],
  33. [
  34. 'auto',
  35. 'Ut',
  36. false,
  37. ],
  38. ];
  39. foreach ($strings as $string) {
  40. $is = startsWith($string[0], $string[1]);
  41. $this->assertEquals($string[2], $is);
  42. }
  43. $is = startsWith('Auto', 'aut', true);
  44. $this->assertEquals(false, $is);
  45. }
  46. /**
  47. * @return void
  48. */
  49. public function testEndsWith() {
  50. $strings = [
  51. [
  52. 'auto',
  53. 'to',
  54. true,
  55. ],
  56. [
  57. 'auto',
  58. 'ut',
  59. false,
  60. ],
  61. [
  62. 'auto',
  63. 'To',
  64. true,
  65. ],
  66. [
  67. 'auto',
  68. 'Ut',
  69. false,
  70. ],
  71. ];
  72. foreach ($strings as $string) {
  73. $is = endsWith($string[0], $string[1]);
  74. $this->assertEquals($string[2], $is);
  75. }
  76. $is = endsWith('Auto', 'To', true);
  77. $this->assertEquals(false, $is);
  78. }
  79. /**
  80. * @return void
  81. */
  82. public function testContains() {
  83. $strings = [
  84. [
  85. 'auto',
  86. 'to',
  87. true,
  88. ],
  89. [
  90. 'auto',
  91. 'ut',
  92. true,
  93. ],
  94. [
  95. 'auto',
  96. 'To',
  97. true,
  98. ],
  99. [
  100. 'auto',
  101. 'ot',
  102. false,
  103. ],
  104. ];
  105. foreach ($strings as $string) {
  106. $is = contains($string[0], $string[1]);
  107. $this->assertEquals($string[2], $is);
  108. }
  109. $is = contains('Auto', 'To', true);
  110. $this->assertEquals(false, $is);
  111. }
  112. /**
  113. * @return void
  114. */
  115. public function testEnt() {
  116. $result = ent('<>');
  117. $expected = '&lt;&gt;';
  118. $this->assertSame($expected, $result);
  119. }
  120. /**
  121. * @return void
  122. */
  123. public function testEntDec() {
  124. $result = entDec('&lt;&gt;');
  125. $expected = '<>';
  126. $this->assertSame($expected, $result);
  127. }
  128. /**
  129. * @return void
  130. */
  131. public function testReturns() {
  132. $result = returns([]);
  133. $expected = '(array)';
  134. $this->assertTextContains($expected, $result);
  135. $foo = 1;
  136. $is = returns($foo);
  137. $this->assertSame('(int)1', $is);
  138. }
  139. /**
  140. * @return void
  141. */
  142. public function testExtractPathInfo() {
  143. $result = extractPathInfo('somefile.jpg', 'ext');
  144. $this->assertEquals('jpg', $result);
  145. $result = extractPathInfo('somefile.jpg', 'base');
  146. $this->assertEquals('somefile.jpg', $result);
  147. $result = extractPathInfo('somefile.jpg', 'file');
  148. $this->assertEquals('somefile', $result);
  149. $result = extractPathInfo('somefile.jpg?foo=bar#something', 'ext', true);
  150. $this->assertEquals('jpg', $result);
  151. }
  152. /**
  153. * @return void
  154. */
  155. public function testExtractFileInfo() {
  156. $result = extractFileInfo('/some/path/to/filename.ext', 'file');
  157. $this->assertEquals('filename', $result);
  158. $result = extractFileInfo('/some/path/to/filename.x.y.z.ext', 'file');
  159. $this->assertEquals('filename.x.y.z', $result);
  160. }
  161. }