BootstrapTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. //pr(returns($is). ' - expected '.returns($string[2]));
  78. $this->assertEquals($string[2], $is);
  79. }
  80. $is = endsWith('Auto', 'To', true);
  81. $this->assertEquals(false, $is);
  82. }
  83. /**
  84. * @return void
  85. */
  86. public function testContains() {
  87. $strings = [
  88. [
  89. 'auto',
  90. 'to',
  91. true
  92. ],
  93. [
  94. 'auto',
  95. 'ut',
  96. true
  97. ],
  98. [
  99. 'auto',
  100. 'To',
  101. true
  102. ],
  103. [
  104. 'auto',
  105. 'ot',
  106. false
  107. ],
  108. ];
  109. foreach ($strings as $string) {
  110. $is = contains($string[0], $string[1]);
  111. //pr(returns($is). ' - expected '.returns($string[2]));
  112. $this->assertEquals($string[2], $is);
  113. }
  114. $is = contains('Auto', 'To', true);
  115. $this->assertEquals(false, $is);
  116. }
  117. /**
  118. * @return void
  119. */
  120. public function testEnt() {
  121. $result = ent('<>');
  122. $expected = '&lt;&gt;';
  123. $this->assertSame($expected, $result);
  124. }
  125. /**
  126. * @return void
  127. */
  128. public function testEntDec() {
  129. $result = entDec('&lt;&gt;');
  130. $expected = '<>';
  131. $this->assertSame($expected, $result);
  132. }
  133. /**
  134. * @return void
  135. */
  136. public function testReturns() {
  137. $result = returns([]);
  138. $expected = '(array)';
  139. $this->assertTextContains($expected, $result);
  140. }
  141. /**
  142. * @return void
  143. */
  144. public function testExtractPathInfo() {
  145. $result = extractPathInfo('somefile.jpg', 'ext');
  146. $this->assertEquals('jpg', $result);
  147. $result = extractPathInfo('somefile.jpg', 'base');
  148. $this->assertEquals('somefile.jpg', $result);
  149. $result = extractPathInfo('somefile.jpg', 'file');
  150. $this->assertEquals('somefile', $result);
  151. $result = extractPathInfo('somefile.jpg?foo=bar#something', 'ext', true);
  152. $this->assertEquals('jpg', $result);
  153. }
  154. /**
  155. * @return void
  156. */
  157. public function testExtractFileInfo() {
  158. $result = extractFileInfo('/some/path/to/filename.ext', 'file');
  159. $this->assertEquals('filename', $result);
  160. $result = extractFileInfo('/some/path/to/filename.x.y.z.ext', 'file');
  161. $this->assertEquals('filename.x.y.z', $result);
  162. }
  163. }