Doctrine_Core::createTablesFromArray(array('Tester', 'rtIndex')); $tester = new Tester(); $tester['title'] = 'Hello, this is a test object, a balloon is great!'; $tester['content'] = 'Balloons really are great. Infact, ninety-nine of them make a wonderful song.'; $tester->save(); $table = Doctrine::getTable('rtIndex'); $t->is($table->getSearchResultsAsArray('19283hd'), false, '->getSearchResultsAsArray() returns false for a search on something which isn\'t in the index.'); $r = $table->getSearchResultsAsArray('balloon'); $t->is(is_array($r), true, '->getSearchResultsAsArray() returns an array for a valid search.'); $t->is(count($r), 1, '->getSearchResultsAsArray() returns correct no. of rows.'); $row_comparison = array('id' => '4', 'model' => 'Tester', 'model_id' => '1', 'lang' => 'en', 'relevance' => '2'); $t->is($r[0], $row_comparison, '->getSearchResultsAsArray() rows are the correct structure.'); $tester2 = new Tester(); $tester2['title'] = 'Colours'; $tester2['content'] = 'Red, green, blue and yellow are just a few of the colours.'; $tester2->save(); $tester3 = new Tester(); $tester3['title'] = 'Party'; $tester3['content'] = 'Ribbons, balloons, wine, some good food. Got it!'; $tester3->save(); $r = $table->getSearchResultsAsArray('balloon, object'); $t->is(count($r), 2, '->getSearchResultsAsArray() returns correct no. of rows... after new items added.'); $r = $table->getSearchResults('balloon, object'); $t->is(count($r), 2, '->getSearchResults() returns correct no. of rows... after new items added.'); $t->isa_ok($r, Doctrine_Collection, '->getSearchResults() returns a Doctrine_Collection object.'); $t->diag('Test some rtIndex object usage.'); $t->isa_ok($r[0]->getObject(), Tester, '->getObject() returns a Tester object.'); $r = $table->getSearchResults('balloon, object'); $r = $table->hydrateResults($r); $t->is(count($r), 2, '->hydrateResults() returns correct no. of rows... after new items added.'); $t->isa_ok($r, Doctrine_Collection, '->hydrateResults() returns a Doctrine_Collection object.');
$i18n_tester->Translation['en']->content = $content; $t->is($i18n_tester->Translation['en']->getSearchBlob(), $title . ' ' . $content, '->getSearchBlob() returns a combined string'); $t->is($i18n_tester->Translation['en']->getLang(), 'en', '->getLang() returns the correct value for en Translation'); $title = 'Bon jour, ca va?'; $content = "Les mots vides (ou stop words, en anglais) sont des mots qui sont tellement communs qu'il est inutile de les indexer ou de les utiliser dans une recherche."; $i18n_tester->Translation['fr']->title = $title; $i18n_tester->Translation['fr']->content = $content; $t->is($i18n_tester->Translation['fr']->getSearchBlob(), $title . ' ' . $content, '->getSearchBlob() returns a combined string'); $t->is($i18n_tester->Translation['fr']->getLang(), 'fr', '->getLang() returns the correct value for fr Translation'); $i18n_tester->save(); $i18n_tester_id = $i18n_tester->Translation['fr']->id; $i18n_tester_class = get_class($i18n_tester->Translation['fr']); $index_items = Doctrine::getTable('rtIndex')->getQueryObject()->from('rtIndex i')->andWhere('i.model_id = ?', $i18n_tester_id)->andWhere('i.model = ?', $i18n_tester_class)->execute(); $total_expected = count($i18n_tester->Translation['en']->getSearchIndexArray()) + count($i18n_tester->Translation['fr']->getSearchIndexArray()); $t->is(count($index_items), $total_expected, 'A count of index items from that object returns the correct number.'); $tester->save(); $t->is(count($index_items), $total_expected, 'Correct index count after other object is saved.'); $index_items = Doctrine::getTable('rtIndex')->getQueryObject()->from('rtIndex i')->andWhere('i.model_id = ?', $tester->id)->andWhere('i.model = ?', get_class($tester))->execute(); $t->is(count($index_items), count($tester->getSearchIndexArray()), 'Correct index count for original test object.'); $i18n_tester->Translation['en']->title = 'Second title: has the word horse in it.'; $i18n_tester->save(); //$i18n_tester->Translation['en']->delete(); //$i18n_tester->Translation['fr']->delete(); $i18n_tester->delete(); $index_items = Doctrine::getTable('rtIndex')->getQueryObject()->from('rtIndex i')->andWhere('i.model_id = ?', $tester->id)->andWhere('i.model = ?', get_class($tester))->execute(); $t->is(count($index_items), count($tester->getSearchIndexArray()), 'Correct index count for original test object after deletion of other object has taken place.'); $index_items = Doctrine::getTable('rtIndex')->getQueryObject()->from('rtIndex i')->andWhere('i.model_id = ?', $i18n_tester_id)->andWhere('i.model = ?', $i18n_tester_class)->execute(); $t->is(count($index_items), 0, 'The deletion correctly removed all index items.'); $tester->delete(); $index_items = Doctrine::getTable('rtIndex')->getQueryObject()->from('rtIndex i')->andWhere('i.model_id = ?', $tester->id)->andWhere('i.model = ?', get_class($tester))->execute(); $t->is(count($index_items), 0, 'Index items removed for simple object after its been deleted.');