Example #1
0
    }
    //for lucene index
    public function getContributor()
    {
        return $this->getUserId() ? $this->getSfGuardUser()->getUsername() : $this->getName();
    }
    public function save($con = null)
    {
        $highlighted = myUtils::highlight($this->getRawBody());
        $this->setBody($highlighted['body']);
        foreach ($this->getSnippetLanguages() as $language) {
            $language->delete();
        }
        foreach ($highlighted['langs'] as $lang => $count) {
            $sl = new SnippetLanguage();
            $sl->setName($lang);
            $sl->setSnippet($this);
            $this->addSnippetLanguage($sl);
        }
        $summarizer = new Summarizer(400);
        $this->setSummary($summarizer->summarize($this->getBody()));
        parent::save();
    }
    public function isIndexable()
    {
        return !$this->getDraft();
    }
}
sfLucenePropelBehavior::getInitializer()->setupModel('Snippet');
sfPropelBehavior::add('Snippet', array('sfPropelActAsRatableBehavior' => array('rating_field' => 'AverageRating')));
sfPropelBehavior::add('Snippet', array('sfPropelFriendlyUrlBehavior' => array('source_column' => 'title', 'target_column' => 'stripped_title')));
class FakeForum extends BaseFakeForum
{
    public $shouldIndex = true;
    public function isIndexable()
    {
        return $this->shouldIndex;
    }
    public function getNonScalar()
    {
        return range(1, 100);
    }
    public function getStringableObject()
    {
        return new Stringable();
    }
    public function getZendDocument()
    {
        $doc = new Zend_Search_Lucene_Document();
        $doc->addField(Zend_Search_Lucene_Field::Keyword('callback', 'foo'));
        return $doc;
    }
}
class Stringable
{
    public function __toString()
    {
        return 'Strings!';
    }
}
sfLucenePropelBehavior::getInitializer()->setup('FakeForum');
    public function _getDeleteQueue()
    {
        return $this->deleteQueue;
    }
    public function _getSearchInstances($node)
    {
        return $this->getSearchInstances($node);
    }
    public function clear()
    {
        $this->saveQueue = array();
        $this->deleteQueue = array();
    }
}
$t->diag('testing ::getInitializer()');
$t->isa_ok(sfLucenePropelBehavior::getInitializer(), 'sfLucenePropelInitializer', '::getInitializer() returns an instance of sfLucenePropelInitializer');
$t->diag('testing ->getSearchInstances()');
$behavior = new MockBehavior();
try {
    $behavior->_getSearchInstances(new Foo());
    $t->fail('->getSearchInstances() fails if node cannot be found');
} catch (Exception $e) {
    $t->pass('->getSearchInstances() fails if node cannot be found');
}
$instances = $behavior->_getSearchInstances($m1);
$t->ok($instances === array(sfLucene::getInstance('testLucene', 'en'), sfLucene::getInstance('testLucene', 'fr')), '->getSearchInstances() returns all search instances for a Propel model');
$t->is($behavior->_getSearchInstances($m2), $instances, '->getSearchInstances() returns same instances for the same model');
$t->diag('testing ->preSave()');
$behavior->preSave($m1);
$q = $behavior->_getSaveQueue();
$t->is($q[0], $m1, '->preSave() adds model to queue if it does not already exist');