TextTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace Tools\Test\TestCase\Utility;
  3. use Tools\TestSuite\TestCase;
  4. use Tools\Utility\Text;
  5. /**
  6. */
  7. class TextTest extends TestCase {
  8. /**
  9. * @var \Tools\Utility\Text;
  10. */
  11. public $Text;
  12. /**
  13. * @return void
  14. */
  15. public function setUp() {
  16. parent::setUp();
  17. $this->Text = new Text();
  18. }
  19. /**
  20. * @return void
  21. */
  22. public function testReadTab() {
  23. $data = <<<TXT
  24. some tabbed data
  25. and another line
  26. TXT;
  27. $result = $this->Text->readTab($data);
  28. $this->assertSame(2, count($result));
  29. $this->assertSame(['and', 'another', 'line'], $result[1]);
  30. }
  31. /**
  32. * @return void
  33. */
  34. public function testReadWithPattern() {
  35. $data = <<<TXT
  36. some random data
  37. and another line
  38. and a third
  39. TXT;
  40. $result = $this->Text->readWithPattern($data, '%s %s %s');
  41. $this->assertSame(3, count($result));
  42. $this->assertSame(['and', 'a', 'third'], $result[2]);
  43. }
  44. /**
  45. * @return void
  46. */
  47. public function testConvertToOrd() {
  48. $is = $this->Text->convertToOrd('h H');
  49. //pr($is);
  50. $this->assertEquals($is, '0-104-32-72-0');
  51. $is = $this->Text->convertToOrd('x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . "\t" . 'x');
  52. //pr($is);
  53. }
  54. /**
  55. * @return void
  56. */
  57. public function testConvertToOrdTable() {
  58. $is = $this->Text->convertToOrdTable('x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . "\t" . 'x');
  59. //pr($is);
  60. }
  61. /**
  62. * @return void
  63. */
  64. public function testMaxWords() {
  65. $this->assertEquals('Taylor...', Text::maxWords('Taylor Otwell', 1));
  66. $this->assertEquals('Taylor___', Text::maxWords('Taylor Otwell', 1, ['ellipsis' => '___']));
  67. $this->assertEquals('Taylor Otwell', Text::maxWords('Taylor Otwell', 3));
  68. }
  69. /**
  70. * @return void
  71. */
  72. public function testWords() {
  73. $is = $this->Text->words('Hochhaus, Unter dem Bau von ae Äußeren Einflüssen - und von Autos.', ['min_char' => 3]);
  74. $this->assertTrue(!empty($is) && is_array($is) && count($is) === 9);
  75. }
  76. }