public function testDoSelectOrderByRank()
 {
     $objects = SortableTable11Query::doSelectOrderByRank()->getArrayCopy();
     $oldRank = 0;
     while ($object = array_shift($objects)) {
         $this->assertTrue($object->getRank() > $oldRank);
         $oldRank = $object->getRank();
     }
     $objects = SortableTable11Query::doSelectOrderByRank(null, Criteria::DESC)->getArrayCopy();
     $oldRank = 10;
     while ($object = array_shift($objects)) {
         $this->assertTrue($object->getRank() < $oldRank);
         $oldRank = $object->getRank();
     }
 }
 public function testReorder()
 {
     $objects = SortableTable11Query::create()->find();
     $ids = [];
     foreach ($objects as $object) {
         $ids[] = $object->getPrimaryKey();
     }
     $ranks = [4, 3, 2, 1];
     $order = array_combine($ids, $ranks);
     SortableTable11Query::create()->reorder($order);
     $expected = [1 => 'row3', 2 => 'row2', 3 => 'row4', 4 => 'row1'];
     $this->assertEquals($expected, $this->getFixturesArray(), 'reorder() reorders the suite');
 }
Example #3
0
 protected function getFixturesArray()
 {
     $ts = SortableTable11Query::create()->orderByRank()->find();
     $ret = [];
     foreach ($ts as $t) {
         $ret[$t->getRank()] = $t->getTitle();
     }
     return $ret;
 }
 public function testRemoveFromList()
 {
     $t2 = SortableTable11Query::retrieveByRank(2);
     $res = $t2->removeFromList();
     $this->assertTrue($res instanceof Table11, 'removeFromList() returns the current object');
     $this->assertNull($res->getRank(), 'removeFromList() resets the object\'s rank');
     SortableTable11TableMap::clearInstancePool();
     $expected = array(1 => 'row1', 2 => 'row2', 3 => 'row3', 4 => 'row4');
     $this->assertEquals($expected, $this->getFixturesArray(), 'removeFromList() does not change the list until the object is saved');
     $t2->save();
     SortableTable11TableMap::clearInstancePool();
     $expected = array(null => 'row2', 1 => 'row1', 2 => 'row3', 3 => 'row4');
     $this->assertEquals($expected, $this->getFixturesArray(), 'removeFromList() changes the list once the object is saved');
 }