} catch (Doctrine_Connection_Sqlite_Exception $e) { $t->info('WARNING: Doctrine_Connection_Sqlite_Exception caught.'); } doctrine_refresh($a1); $t->is($a1['category_id'], $categories[1]['id'], sprintf('"First item" has been moved to %s', $a3['Category']['name'])); $t->is($a1['position'], 3, '"First item" has been moved to "3" from "1"'); $t->info('Test deleting a collection of sortable items'); $d1 = new SortableArticleUniqueBy(); $d1->name = 'ArticleUniqueBy To Delete 1'; $d1->Category = $categories[2]; $d1->save(); $d2 = new SortableArticleUniqueBy(); $d2->name = 'ArticleUniqueBy To Delete 2'; $d2->Category = $categories[2]; $d2->save(); $d3 = new SortableArticleUniqueBy(); $d3->name = 'ArticleUniqueBy To Delete 3'; $d3->Category = $categories[2]; $d3->save(); $d4 = new SortableArticleUniqueBy(); $d4->name = 'ArticleUniqueBy To Delete 4'; $d4->Category = $categories[2]; $d4->save(); $collection = Doctrine::getTable('SortableArticleUniqueBy')->createQuery()->where('category_id = ?', $categories[2]['id'])->execute(); $t->is($collection->count(), 4, 'Three items exist in the Doctrine Collection to be deleted'); $collection->delete(); $t->is($collection->count(), 0, 'No items in collection - they have been deleted'); $t->ok(!$d1->exists(), '"ArticleUniqueBy To Delete 1" has been removed'); $t->ok(!$d2->exists(), '"ArticleUniqueBy To Delete 2" has been removed'); $t->ok(!$d3->exists(), '"ArticleUniqueBy To Delete 3" has been removed'); $t->ok(!$d4->exists(), '"ArticleUniqueBy To Delete 4" has been removed');
Doctrine::getTable('SortableArticle')->createQuery()->delete()->execute(); $a1 = new SortableArticleUniqueBy(); $a1->name = 'First Article'; $a1->Category = $categories[0]; $a1->save(); $a2 = new SortableArticleUniqueBy(); $a2->name = 'Second Article'; $a2->Category = $categories[0]; $a2->save(); $a3 = new SortableArticleUniqueBy(); $a3->name = 'Third Article'; $a3->Category = $categories[0]; $a3->save(); $a4 = new SortableArticleUniqueBy(); $a4->name = 'Fourth Article'; $a4->Category = $categories[0]; $a4->save(); $a5 = new SortableArticleUniqueBy(); $a5->name = 'Fifth Article'; $a5->Category = $categories[0]; $a5->save(); $t->info('Fetch articles and delete them like in batchDelete'); $articles = Doctrine::getTable('SortableArticleUniqueBy')->createQuery()->execute(); try { foreach ($articles as $article) { $article->delete(); $t->pass(sprintf('Successfully deleted article %s', $article['id'])); } } catch (Exception $e) { $t->fail('Failure while batch-deleting ' . $e->getMessage()); }