TextTest.php 1.9 KB

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