$t->info('Test Demote and Promote'); $a1->demote(); doctrine_refresh($a2); $t->is($a1['position'], 2, 'First item now has position of 2'); $t->is($a2['position'], 1, 'Second item now has position of 1'); $a3->demote(); doctrine_refresh($a4); $t->is($a3['position'], 2, 'Third item now has position of 2'); $t->is($a4['position'], 1, 'Fourth item now has position of 1'); $t->info('Test Removing an item - items after it should be promoted'); $a2->delete(); doctrine_refresh($a1); $t->is($a1['position'], 1, '"First item" has been promoted to "1" from "2"'); $a4->delete(); doctrine_refresh($a3); $t->is($a3['position'], 1, '"Third item" has been promoted to "1" from "2"'); $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();
$t->info('Test Removing an item - items after it should be promoted'); $a2->delete(); doctrine_refresh($a1); $t->is($a1['position'], 1, '"First item" has been promoted to "1" from "2"'); $a4->delete(); doctrine_refresh($a3, $a5); $t->is($a3['position'], 1, '"Third item" has been promoted to "1" from "2"'); $t->is($a5['position'], 2, '"Fifth item" has been promoted to "2" from "3"'); $t->info('Test Moving an item to a different category with an item already at the same rank'); try { $a1->Category = $categories[1]; $a1->save(); } 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();
$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'; $d1->save(); $d2 = new SortableArticle(); $d2->name = 'Article To Delete 2'; $d2->save(); $d3 = new SortableArticle(); $d3->name = 'Article To Delete 3'; $d3->save();