TextLibTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. App::uses('TextLib', 'Tools.Utility');
  3. /**
  4. * 2010-07-14 ms
  5. */
  6. class TextLibTest extends CakeTestCase {
  7. public function startTest() {
  8. $this->TextLib = new TextLib(null);
  9. }
  10. public function testScreamFont() {
  11. $strings = array(
  12. 'Some Äext' => false,
  13. 'SOME ÄEXT' => true,
  14. 'ST' => true,
  15. 'SOme TExt' => true,
  16. 'SOme Text' => false,
  17. );
  18. foreach ($strings as $string => $expected) {
  19. $this->TextLib = new TextLib($string);
  20. $is = $this->TextLib->isScreamFont();
  21. //pr($is);
  22. $this->assertSame($expected, $is);
  23. }
  24. }
  25. public function testConvertToOrd() {
  26. $this->TextLib = new TextLib('h H');
  27. $is = $this->TextLib->convertToOrd();
  28. pr($is);
  29. $this->assertEquals($is, '0-104-32-72-0');
  30. $is = $this->TextLib->convertToOrd('x'.NL.'x'.LF.'x'.PHP_EOL.'x'.CR.'x'.TB.'x');
  31. pr($is);
  32. }
  33. public function testConvertToOrdTable() {
  34. $is = $this->TextLib->convertToOrdTable('x'.NL.'x'.LF.'x'.PHP_EOL.'x'.CR.'x'.TB.'x');
  35. pr($is);
  36. }
  37. public function testWords() {
  38. $this->TextLib = new TextLib('Hochhaus, Unter dem Bau von ae Äußeren Einflüssen - und von Autos.');
  39. $is = $this->TextLib->words(array('min_char'=>3));
  40. pr($is);
  41. $this->assertTrue(!empty($is) && is_array($is) && count($is) === 9);
  42. }
  43. public function testWordCount() {
  44. $this->TextLib = new TextLib('Hochhaus, Unter dem Bau von ae Äußeren Einflüssen - und von Autos.');
  45. $is = $this->TextLib->wordCount(array('min_char'=>3));
  46. pr($is);
  47. $this->assertTrue(!empty($is) && is_array($is) && count($is) === 9);
  48. $this->TextLib = new TextLib('Hochhaus, Unter dem Bau von ae Äußeren Einflüssen - und von Autos.');
  49. $is = $this->TextLib->wordCount(array('min_char'=>3, 'sort'=>'DESC', 'limit'=>5));
  50. pr($is);
  51. $this->assertTrue(!empty($is) && is_array($is) && count($is) === 5);
  52. }
  53. /** Start **/
  54. public function testOccurances() {
  55. $this->TextLib = new TextLib('Hochhaus');
  56. $is = $this->TextLib->occurrences();
  57. pr($is);
  58. $this->assertTrue(!empty($is) && is_array($is) && count($is) === 6);
  59. $is = $this->TextLib->occurrences(null, true);
  60. pr($is);
  61. $this->assertTrue(!empty($is) && is_array($is) && count($is) === 7);
  62. $is = $this->TextLib->occurrences('h');
  63. pr($is);
  64. $expected = 3;
  65. $this->assertEquals($is, $expected);
  66. $is = $this->TextLib->occurrences('h', true);
  67. pr($is);
  68. $expected = 2;
  69. $this->assertEquals($is, $expected);
  70. }
  71. public function testMaxOccurances() {
  72. $is = $this->TextLib->maxOccurrences();
  73. pr($is);
  74. $this->assertTrue(!empty($is) && is_array($is) && count($is) === 1);
  75. $this->TextLib = new TextLib('Radfahren');
  76. $is = $this->TextLib->maxOccurrences();
  77. pr($is);
  78. $this->assertTrue(!empty($is) && is_array($is) && count($is) === 2);
  79. }
  80. //TODO: rest of the test functions
  81. /*
  82. //give it the text
  83. $text = new TextParse(
  84. "PHP:Hypertext Preprocessor is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages... .. .. For this purpose,PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document.
  85. As a general-purpose programming language, PHP code(PHP CODE)is processed by an interpreter application in command-line mode performing desired operating system operations and producing program output on its standard output channel.It may also function as a graphical application...... PHP is available as a processor for most modern web servers and as standalone interpreter on most operating systems and computing platforms."
  86. );
  87. echo "Lenght:". $text->getLenght() ."\n"; //the Lenght
  88. echo "Character:". $text->getCharacter() ."\n"; //Character count
  89. echo "Letter:". $text->getLetter() ."\n"; //Letter count
  90. echo "Space:". $text->getSpace() ."\n"; //Space count
  91. echo "Symbol:". $text->getSymbol() ."\n"; //Symbol count(non letter / space / \n / \r)
  92. echo "Word:". $text->getWord() ."\n"; //Word count
  93. echo "The Words:";
  94. print_r($text->getWord(1)); //the Words
  95. echo "\n";
  96. echo "Sentence:". $text->getSentence() ."\n"; //Sentence count
  97. echo "The Sentences:";
  98. print_r($text->getSentence(1)); //the Sentences
  99. echo "\n";
  100. echo "Paragraph:". $text->getParagraph() ."\n"; //Paragraph count
  101. echo "The Paragraphs:";
  102. print_r($text->getParagraph(1)); //the Paragraphs
  103. echo "\n";
  104. echo "Beautified Text:\n". $text->beautify(80); //beautify the text, wordwrap=80
  105. */
  106. }