/** * Take an array of strings, pick one at random and substitute each token with a value. * Text is processed with InsightTerms::getProcessedText() * The normal usage would be to pass a list of string choices for an Insight field, such as text, headline, etc. * * @param array $copy_array Array of possible strings * @param array $substitutions Text replacement token/value pairs passed to getProccessedText(), in the form of * '%token'=>'value'. See also: InsightTerms::getProcessedText * @return str The chosen and processed array */ public function getVariableCopy($copy_array, $substitutions = array()) { $substitutions['username'] = $this->username; $choice = $copy_array[TimeHelper::getTime() % count($copy_array)]; return $this->terms->getProcessedText($choice, $substitutions); }
public function testGetProcessedText() { $twitter_terms = new InsightTerms('twitter'); $result = $twitter_terms->getProcessedText('%posts %posted %post %likes %liked %like %reply %replies'); $this->assertEqual('tweets tweeted tweet likes liked like reply replies', $result); $result = $twitter_terms->getProcessedText('%retweets %retweet %followers %follower %shared'); $this->assertEqual('retweets retweet followers follower retweeted', $result); $fb_terms = new InsightTerms('facebook'); $result = $fb_terms->getProcessedText('%posts %posted %post %likes %liked %like %reply %replies'); $this->assertEqual('status updates posted status update likes liked like comment comments', $result); $result = $fb_terms->getProcessedText('%retweets %retweet %followers %follower %shared'); $this->assertEqual('reshares reshare friends friend reshared', $result); $result = $twitter_terms->getProcessedText('%animal %posted %thing', array('animal' => 'fox', 'thing' => 'video')); $this->assertEqual('fox tweeted video', $result); $result = $twitter_terms->getProcessedText('%animal %posted %thing'); $this->assertEqual('%animal tweeted %thing', $result); }