public function testParsingDicFilesWorks() { Dictionary::setFileLocation(__DIR__ . '/share/'); @unlink(__DIR__ . '/share/de_TE.ini'); $dict = Dictionary::parseFile('de_TE'); $this->assertTrue(file_Exists($dict)); $this->assertTrue('UTF-8' == mb_detect_encoding(file_get_contents($dict))); $this->assertEquals(file_get_contents(__DIR__ . '/share/de_TE.default.ini'), file_get_contents($dict)); try { $dict = Dictionary::parseFile('foobar'); $this->fail('This should have raised an exception!'); } catch (\Org\Heigl\Hyphenator\Exception\PathNotFoundException $exception) { $this->assertTrue(true); } }
public function testGettingDictionaryById() { $registry = new DictionaryRegistry(); $dictionary1 = new d\Dictionary(); $dictionary1->addPattern('test', 'test1'); $registry->add($dictionary1); $dictionary2 = new d\Dictionary(); $dictionary2->addPattern('test1', 'test12'); $registry->add($dictionary2); $this->assertEquals($dictionary2, $registry->getDictionaryWithKey(1)); $this->assertEquals($dictionary1, $registry->getDictionaryWithKey(0)); $this->assertEquals(null, $registry->getDictionaryWithKey(2)); }
public function testHyphenatorInvocationWithoutFactory() { $o = new \Org\Heigl\Hyphenator\Options(); $o->setHyphen('-')->setDefaultLocale('de_DE')->setRightMin(2)->setLeftMin(2)->setWordMin(5)->setFilters('Simple')->setTokenizers('Whitespace', 'Punctuation'); \Org\Heigl\Hyphenator\Dictionary\Dictionary::setFileLocation(__DIR__ . '/share/test3/files/dictionaries/'); $h = new \Org\Heigl\Hyphenator\Hyphenator(); $h->setOptions($o); $this->assertEquals('We have some re-al-ly long words in ger-man like sau-er-stoff-feld-fla-sche.', $h->hyphenate('We have some really long words in german like sauerstofffeldflasche.')); }
/** * Add a Dictionary to the Hyphenator * * @param \Org\Heigl\Hyphenator\Dictionary\Dictionary $dictionary The * Dictionary wit hyphenation-Patterns to add to this Hyphenator * * @return Org\Heigl\Hyphenator\Hyphenator */ public function addDictionary($dictionary) { if (!$dictionary instanceof \Org\Heigl\Hyphenator\Dictionary\Dictionary) { \Org\Heigl\Hyphenator\Dictionary\Dictionary::setFileLocation($this->getHomePath() . '/files/dictionaries'); $dictionary = \Org\Heigl\Hyphenator\Dictionary\Dictionary::factory($dictionary); } $this->_dicts->add($dictionary); return $this; }