TextTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. public function setUp() {
  13. parent::setUp();
  14. $this->Text = new Text();
  15. }
  16. public function testReadTab() {
  17. $data = <<<TXT
  18. some tabbed data
  19. and another line
  20. TXT;
  21. $result = $this->Text->readTab($data);
  22. $this->assertSame(2, count($result));
  23. $this->assertSame(['and', 'another', 'line'], $result[1]);
  24. }
  25. /**
  26. * @return void
  27. */
  28. public function testReadWithPattern() {
  29. $data = <<<TXT
  30. some random data
  31. and another line
  32. and a third
  33. TXT;
  34. $result = $this->Text->readWithPattern($data, '%s %s %s');
  35. $this->assertSame(3, count($result));
  36. $this->assertSame(['and', 'a', 'third'], $result[2]);
  37. }
  38. public function testConvertToOrd() {
  39. $is = $this->Text->convertToOrd('h H');
  40. //pr($is);
  41. $this->assertEquals($is, '0-104-32-72-0');
  42. $is = $this->Text->convertToOrd('x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . "\t" . 'x');
  43. //pr($is);
  44. }
  45. public function testConvertToOrdTable() {
  46. $is = $this->Text->convertToOrdTable('x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . "\t" . 'x');
  47. //pr($is);
  48. }
  49. public function testMaxWords() {
  50. $this->assertEquals('Taylor...', Text::maxWords('Taylor Otwell', 1));
  51. $this->assertEquals('Taylor___', Text::maxWords('Taylor Otwell', 1, ['ellipsis' => '___']));
  52. $this->assertEquals('Taylor Otwell', Text::maxWords('Taylor Otwell', 3));
  53. }
  54. public function testWords() {
  55. $is = $this->Text->words('Hochhaus, Unter dem Bau von ae Äußeren Einflüssen - und von Autos.', ['min_char' => 3]);
  56. $this->assertTrue(!empty($is) && is_array($is) && count($is) === 9);
  57. }
  58. }