TextLibTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. App::uses('TextLib', 'Tools.Utility');
  3. /**
  4. * 2010-07-14 ms
  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. }