TextTest.php 1.8 KB

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