public function testTextManager() { $texts = json_decode('[ { "text": { "text": "foo", "pre": "pret" } }, { "match": { "text": "bar", "pre": "prem" } }, { "text": { "text": "baz" } }, { "match": { "text": "bat" } } ]'); $mgr = new AfsSpellcheckTextManager($texts); $visitor = new SpellcheckVisitor(); $text = $mgr->visit_text($visitor); $this->assertEquals('<s>pretfoo</s>prem<b>bar</b><s>baz</s><b>bat</b>', $text->formatted); $this->assertEquals('pretfooprembarbazbat', $text->raw); }
private function add_one_spellcheck($reply) { $feed = empty($reply->uri) ? AFS_DEFAULT_SPELLCHECK : $reply->uri; $text_mgr = new AfsSpellcheckTextManager($reply->suggestion[0]->items); $raw_and_formatted = $text_mgr->visit_text($this->config->get_spellcheck_text_visitor()); if (!array_key_exists($feed, $this->spellchecks)) { $this->spellchecks[$feed] = array(); } $spellcheck_query = $this->query->set_query($raw_and_formatted->raw)->set_from(AfsOrigin::SPELLCHECK); $link = null; if ($this->config->has_query_coder()) { $link = $this->config->get_query_coder()->generate_link($spellcheck_query); } $this->spellchecks[$feed][] = new AfsSpellcheckHelper($raw_and_formatted, $spellcheck_query, $link); }