BootstrapTest.php 2.9 KB

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