public function testPreDelete()
 {
     $max = SortableTable12Query::create()->getMaxRank(1);
     $t3 = SortableTable12Query::retrieveByRank(3, 1);
     $t3->delete();
     $this->assertEquals($max - 1, SortableTable12Query::create()->getMaxRank(1), 'Sortable rearrange subsequent rows on delete');
     $t4 = SortableTable12Query::create()->filterByTitle('row4')->findOne();
     $this->assertEquals(3, $t4->getRank(), 'Sortable rearrange subsequent rows on delete');
     $expected = array(1 => 'row5', 2 => 'row6');
     $this->assertEquals($expected, $this->getFixturesArrayWithScope(2), 'delete() leaves other suites unchanged');
 }
 public function testReorder()
 {
     $objects = SortableTable12Query::create()->findList(1);
     $ids = [];
     foreach ($objects as $object) {
         $ids[] = $object->getPrimaryKey();
     }
     $ranks = [4, 3, 2, 1];
     $order = array_combine($ids, $ranks);
     SortableTable12Query::create()->reorder($order);
     $expected = [1 => 'row4', 2 => 'row3', 3 => 'row2', 4 => 'row1'];
     $this->assertEquals($expected, $this->getFixturesArrayWithScope(1), 'reorder() reorders the suite');
     $expected = [1 => 'row5', 2 => 'row6'];
     $this->assertEquals($expected, $this->getFixturesArrayWithScope(2), 'reorder() leaves other suites unchanged');
 }
 public function testDeleteList()
 {
     $this->assertEquals(4, SortableTable12Query::deleteList(null), 'deleteList() returns the list of deleted objects in the scope');
     $this->assertEquals(6, SortableTable12Query::create()->count(), 'deleteList() deletes the objects in the scope');
     $this->assertEquals(4, SortableTable12Query::deleteList(1), 'deleteList() returns the list of deleted objects in the scope');
     $this->assertEquals(2, SortableTable12Query::create()->count(), 'deleteList() deletes the objects in the scope');
     $this->assertEquals(2, SortableTable12Query::deleteList(2), 'deleteList() returns the list of deleted objects in the scope');
     $this->assertEquals(0, SortableTable12Query::create()->count(), 'deleteList() deletes the objects in the scope');
 }
Exemple #4
0
 protected function getFixturesArrayWithScope($scope = null)
 {
     $c = new Criteria();
     $c->add(SortableTable12TableMap::SCOPE_COL, $scope);
     $ts = SortableTable12Query::create(null, $c)->orderByPosition()->find();
     $ret = [];
     foreach ($ts as $t) {
         $ret[$t->getRank()] = $t->getTitle();
     }
     return $ret;
 }