TextTest.php 1.8 KB

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