SpellLibTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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->skipIf(!function_exists('enchant_broker_init'), __('Module %s not installed', 'Enchant'));
  9. $this->SpellLib = new SpellLib();
  10. }
  11. public function tearDown() {
  12. parent::tearDown();
  13. unset($this->SpellLib);
  14. }
  15. public function testObject() {
  16. $this->assertTrue(is_a($this->SpellLib, 'SpellLib'));
  17. }
  18. public function testList() {
  19. $res = $this->SpellLib->listBrokers();
  20. debug($res);
  21. $this->assertTrue(is_array($res) && count($res) > 1);
  22. $this->assertTrue(in_array($res[0]['name'], array('ispell', 'myspell')));
  23. $res = $this->SpellLib->listDictionaries();
  24. debug($res);
  25. $this->assertTrue(is_array($res) && count($res) > 1);
  26. $this->assertTrue(in_array($res[0]['lang_tag'], array('de_DE', 'en_GB')));
  27. }
  28. public function testDefaults() {
  29. $word = 'house';
  30. $res = $this->SpellLib->check($word);
  31. $this->assertTrue($res);
  32. $word = 'soong';
  33. $res = $this->SpellLib->check($word);
  34. $this->assertFalse($res);
  35. $suggestions = $this->SpellLib->suggestions($word);
  36. debug($suggestions);
  37. $this->assertTrue(is_array($suggestions) && count($suggestions) > 1);
  38. $this->assertTrue(in_array('song', $suggestions));
  39. $word = 'bird';
  40. $res = $this->SpellLib->check($word);
  41. $this->assertTrue($res);
  42. ob_flush();
  43. }
  44. public function testGerman() {
  45. $this->SpellLib = new SpellLib(array('lang'=>'de_DE'));
  46. $word = 'Wand';
  47. $res = $this->SpellLib->check($word);
  48. $this->assertTrue($res);
  49. $word = 'Hauz';
  50. $res = $this->SpellLib->check($word);
  51. $this->assertFalse($res);
  52. $suggestions = $this->SpellLib->suggestions($word);
  53. debug($suggestions);
  54. $this->assertTrue(is_array($suggestions) && count($suggestions) > 1);
  55. $this->assertTrue(in_array('Haus', $suggestions));
  56. $word = 'Mäuse';
  57. $res = $this->SpellLib->check($word);
  58. $this->assertTrue($res);
  59. ob_flush();
  60. }
  61. public function testConfigureConfiguration() {
  62. Configure::write('Spell.lang', 'de_DE');
  63. $this->SpellLib = new SpellLib();
  64. $word = 'Mäuse';
  65. $res = $this->SpellLib->check($word);
  66. $this->assertTrue($res);
  67. Configure::write('Spell.lang', 'en_GB');
  68. $this->SpellLib = new SpellLib();
  69. $word = 'Mäuse';
  70. $res = $this->SpellLib->check($word);
  71. $this->assertFalse($res);
  72. $suggestions = $this->SpellLib->suggestions($word);
  73. $this->assertTrue(is_array($suggestions) && count($suggestions) > 0);
  74. $this->assertTrue(in_array('Mouse', $suggestions));
  75. }
  76. }