TextTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. public $Text;
  10. /**
  11. * @return void
  12. */
  13. public function setUp() {
  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. $this->assertEquals($is, '0-104-32-72-0');
  48. $is = $this->Text->convertToOrd('x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . "\t" . 'x');
  49. $this->assertNotEmpty($is);
  50. }
  51. /**
  52. * @return void
  53. */
  54. public function testConvertToOrdTable() {
  55. $is = $this->Text->convertToOrdTable('x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . "\t" . 'x');
  56. $this->assertNotEmpty($is);
  57. }
  58. /**
  59. * @return void
  60. */
  61. public function testMaxWords() {
  62. $this->assertEquals('Taylor...', Text::maxWords('Taylor Otwell', 1));
  63. $this->assertEquals('Taylor___', Text::maxWords('Taylor Otwell', 1, ['ellipsis' => '___']));
  64. $this->assertEquals('Taylor Otwell', Text::maxWords('Taylor Otwell', 3));
  65. }
  66. /**
  67. * @return void
  68. */
  69. public function testWords() {
  70. $is = $this->Text->words('Hochhaus, Unter dem Bau von ae Äußeren Einflüssen - und von Autos.', ['min_char' => 3]);
  71. $this->assertTrue(!empty($is) && is_array($is) && count($is) === 9);
  72. }
  73. }