$a5 = new SortableArticleUniqueBy(); $a5->name = 'Fifth Article'; $a5->Category = $categories[1]; $a5->save(); $t->info('Assert articles have the correct position'); $t->is($a1['position'], 1, 'First item saved has position of 1 (first in category 1)'); $t->is($a2['position'], 2, 'Second item saved has position of 2 (second in category 1)'); $t->is($a3['position'], 1, 'Third item saved has position of 1 (first in category 2)'); $t->is($a4['position'], 2, 'Fourth item saved has position of 2 (second in category 2)'); $t->is($a5['position'], 3, 'Fifth item saved has position of 3 (third in category 2)'); $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->is($a5['position'], 3, 'Fifth item still has a position of 3'); $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];
$a4->save(); $t->info('Assert articles have the correct position'); $t->is($a1['position'], 1, 'First item saved has position of 1 (first in category 1)'); $t->is($a2['position'], 2, 'Second item saved has position of 2 (second in category 1)'); $t->is($a3['position'], 1, 'Third item saved has position of 1 (first in category 2)'); $t->is($a4['position'], 2, 'Third item saved has position of 2 (second in category 2)'); $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';