$articles = $table->findAllSorted();
$t->is($articles->count(), 3, 'Three articles returned for "findAllSorted()" method');
$t->is($articles[0]['id'], $a1['id'], 'First item is now first');
$t->is($articles[1]['id'], $a2['id'], 'Second item is now second');
$t->is($articles[2]['id'], $a3['id'], 'Third item is last');
$t->comment('Sort to previous position (after promote/demote)');
$sort = array($a2['id'], $a3['id'], $a1['id']);
$table->sort($sort);
$articles = $table->findAllSorted();
$t->is($articles->count(), 3, 'Three articles returned for "findAllSorted()" method');
$t->is($articles[0]['id'], $a2['id'], 'Second item first (same as position)');
$t->is($articles[1]['id'], $a3['id'], 'Third item second (same as position)');
$t->is($articles[2]['id'], $a1['id'], 'First item last (same as position)');
$t->info('Test Removing an item - items after it should be promoted');
$t->is($a2->getFinalPosition(), 3, '"Final Position" is "3" before the item is deleted');
$a3->delete();
doctrine_refresh($a1);
$t->is($a1['position'], 2, '"First item" has been promoted to "2" from "3"');
$t->is($a2['position'], 1, '"Second item" stays at position "1"');
$t->is($a2->getFinalPosition(), 2, '"Final Position" is now "2"');
$t->info('Test "moveToPosition" method');
$a4 = new SortableArticle();
$a4->name = 'Fourth Article';
$a4->save();
$t->is($a4['position'], 3, 'The new article is placed at the end');
$a4->moveToPosition(1);
doctrine_refresh($a1);
$t->is($a1['position'], 3, 'The 2nd-positioned item has been bumped up');
$t->info('Test deleting a collection of sortable items');
$d1 = new SortableArticle();
$d1->name = 'Article To Delete 1';
    $t->is($articles[1]['id'], $a2['id'], 'Second item is now second');
    $t->is($articles[2]['id'], $a3['id'], 'Third item is last');

    $t->comment('Sort to previous position (after promote/demote)');
    $sort = array($a2['id'], $a3['id'], $a1['id']);
    $table->sort($sort);
    $articles = $table->findAllSorted();
    $t->is($articles->count(), 3, 'Three articles returned for "findAllSorted()" method');
    $t->is($articles[0]['id'], $a2['id'], 'Second item first (same as position)');
    $t->is($articles[1]['id'], $a3['id'], 'Third item second (same as position)');
    $t->is($articles[2]['id'], $a1['id'], 'First item last (same as position)');
    
$t->info('Test Removing an item - items after it should be promoted');

    $t->is($a2->getFinalPosition(), 3, '"Final Position" is "3" before the item is deleted');
    $a3->delete(); doctrine_refresh($a1);
    $t->is($a1['position'], 2, '"First item" has been promoted to "2" from "3"');
    $t->is($a2['position'], 1, '"Second item" stays at position "1"');
    $t->is($a2->getFinalPosition(), 2, '"Final Position" is now "2"');

$t->info('Test "moveToPosition" method');

    $a4 = new SortableArticle();
    $a4->name = 'Fourth Article';
    $a4->save();

    $t->is($a4['position'], 3, 'The new article is placed at the end');
    $a4->moveToPosition(1); doctrine_refresh($a1);
    $t->is($a1['position'], 3, 'The 2nd-positioned item has been bumped up');

$t->info('Test deleting a collection of sortable items');