SpellLibTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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'), __d('tools', '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->assertInstanceOf('SpellLib', $this->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'], ['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'], ['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. }
  43. public function testGerman() {
  44. $this->SpellLib = new SpellLib(['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. }
  59. public function testConfigureConfiguration() {
  60. Configure::write('Spell.lang', 'de_DE');
  61. $this->SpellLib = new SpellLib();
  62. $word = 'Mäuse';
  63. $res = $this->SpellLib->check($word);
  64. $this->assertTrue($res);
  65. Configure::write('Spell.lang', 'en_GB');
  66. $this->SpellLib = new SpellLib();
  67. $word = 'Mäuse';
  68. $res = $this->SpellLib->check($word);
  69. $this->assertFalse($res);
  70. $suggestions = $this->SpellLib->suggestions($word);
  71. $this->assertTrue(is_array($suggestions) && count($suggestions) > 0);
  72. $this->assertTrue(in_array('Mouse', $suggestions));
  73. }
  74. }