SpellLibTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. App::uses('SpellLib', 'Tools.Lib');
  3. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  4. class SpellLibTest extends MyCakeTestCase {
  5. public $SpellLib;
  6. public function setUp() {
  7. parent::setUp();
  8. $this->SpellLib = new SpellLib();
  9. }
  10. public function tearDown() {
  11. parent::tearDown();
  12. unset($this->SpellLib);
  13. }
  14. public function testObject() {
  15. $this->assertTrue(is_a($this->SpellLib, 'SpellLib'));
  16. }
  17. public function testList() {
  18. $res = $this->SpellLib->listBrokers();
  19. debug($res);
  20. $this->assertTrue(is_array($res) && count($res) > 1);
  21. $this->assertTrue(in_array($res[0]['name'], array('ispell', 'myspell')));
  22. $res = $this->SpellLib->listDictionaries();
  23. debug($res);
  24. $this->assertTrue(is_array($res) && count($res) > 1);
  25. $this->assertTrue(in_array($res[0]['lang_tag'], array('de_DE', 'en_GB')));
  26. }
  27. public function testDefaults() {
  28. $word = 'house';
  29. $res = $this->SpellLib->check($word);
  30. $this->assertTrue($res);
  31. $word = 'soong';
  32. $res = $this->SpellLib->check($word);
  33. $this->assertFalse($res);
  34. $suggestions = $this->SpellLib->suggestions($word);
  35. debug($suggestions);
  36. $this->assertTrue(is_array($suggestions) && count($suggestions) > 1);
  37. $this->assertTrue(in_array('song', $suggestions));
  38. $word = 'bird';
  39. $res = $this->SpellLib->check($word);
  40. $this->assertTrue($res);
  41. ob_flush();
  42. }
  43. public function testGerman() {
  44. $this->SpellLib = new SpellLib(array('lang'=>'de_DE'));
  45. $word = 'Wand';
  46. $res = $this->SpellLib->check($word);
  47. $this->assertTrue($res);
  48. $word = 'Hauz';
  49. $res = $this->SpellLib->check($word);
  50. $this->assertFalse($res);
  51. $suggestions = $this->SpellLib->suggestions($word);
  52. debug($suggestions);
  53. $this->assertTrue(is_array($suggestions) && count($suggestions) > 1);
  54. $this->assertTrue(in_array('Haus', $suggestions));
  55. $word = 'Mäuse';
  56. $res = $this->SpellLib->check($word);
  57. $this->assertTrue($res);
  58. ob_flush();
  59. }
  60. public function testConfigureConfiguration() {
  61. Configure::write('Spell.lang', 'de_DE');
  62. $this->SpellLib = new SpellLib();
  63. $word = 'Mäuse';
  64. $res = $this->SpellLib->check($word);
  65. $this->assertTrue($res);
  66. Configure::write('Spell.lang', 'en_GB');
  67. $this->SpellLib = new SpellLib();
  68. $word = 'Mäuse';
  69. $res = $this->SpellLib->check($word);
  70. $this->assertFalse($res);
  71. $suggestions = $this->SpellLib->suggestions($word);
  72. $this->assertTrue(is_array($suggestions) && count($suggestions) > 0);
  73. $this->assertTrue(in_array('Mouse', $suggestions));
  74. }
  75. }