Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

sortable behavior: tests for FK scope column

  • Loading branch information...
commit 21a1e03e0f16177bc7ac3a33429d35e216183b93 1 parent f860b20
@rozwell authored
View
15 test/fixtures/bookstore/behavior-sortable-schema.xml
@@ -18,4 +18,19 @@
</behavior>
</table>
+ <table name="fk_scope_table">
+ <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
+ <column name="title" type="VARCHAR" size="100" primaryString="true" />
+ <column name="scope_id" type="INTEGER" />
+ <foreign-key foreignTable="table11" onDelete="setnull">
+ <reference local="scope_id" foreign="id" />
+ </foreign-key>
+ <column name="position" type="INTEGER" />
+ <behavior name="sortable">
+ <parameter name="rank_column" value="position" />
+ <parameter name="use_scope" value="true" />
+ <parameter name="scope_column" value="scope_id" />
+ </behavior>
+ </table>
+
</database>
View
16 test/testsuite/generator/behavior/sortable/SortableBehaviorObjectBuilderModifierWithScopeTest.php
@@ -56,6 +56,22 @@ public function testPreDelete()
$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');
+ $expected = array(1 => 'row7', 2 => 'row8', 3 => 'row9', 4 => 'row10');
+ $this->assertEquals($expected, $this->getFixturesArrayWithScope(), 'delete() leaves other suites unchanged');
+ }
+
+ public function testPreDeleteFkScope()
+ {
+ $this->populateFkScopeTable();
+
+ $t = Table11Peer::retrieveByRank(2);
+ $t->delete();
+ $expected = array(1 => 'row7', 2 => 'row8', 3 => 'row9', 4 => 'row4', 5 => 'row5', 6 => 'row6');
+ $this->assertEquals($expected, $this->getFixturesArrayWithFkScope(), 'delete() moves related objects to the end of null scope');
+
+ $s = Table11Peer::retrieveByRank(1);
+ $expected = array(1 => 'row1', 2 => 'row2', 3 => 'row3');
+ $this->assertEquals($expected, $this->getFixturesArrayWithFkScope($s->getId()), 'delete() leaves other suites unchanged');
}
public function testIsFirst()
View
72 test/tools/helpers/bookstore/behavior/BookstoreSortableTestBase.php
@@ -91,6 +91,64 @@ protected function populateTable12()
$t10->save();
}
+ protected function populateFkScopeTable()
+ {
+ /* List used for tests
+ scope=1 scope=2 scope=null
+ row1 row4 row7
+ row2 row5 row8
+ row3 row6 row9
+ */
+ $this->populateTable11();
+
+ $s1 = Table11Peer::retrieveByRank(1)->getId();
+ $s2 = Table11Peer::retrieveByRank(2)->getId();
+
+ FkScopeTablePeer::doDeleteAll();
+ $t1 = new FkScopeTable();
+ $t1->setRank(1);
+ $t1->setScopeValue($s1);
+ $t1->setTitle('row1');
+ $t1->save();
+ $t2 = new FkScopeTable();
+ $t2->setRank(2);
+ $t2->setScopeValue($s1);
+ $t2->setTitle('row2');
+ $t2->save();
+ $t3 = new FkScopeTable();
+ $t3->setRank(3);
+ $t3->setScopeValue($s1);
+ $t3->setTitle('row3');
+ $t3->save();
+ $t4 = new FkScopeTable();
+ $t4->setRank(1);
+ $t4->setScopeValue($s2);
+ $t4->setTitle('row4');
+ $t4->save();
+ $t5 = new FkScopeTable();
+ $t5->setRank(2);
+ $t5->setScopeValue($s2);
+ $t5->setTitle('row5');
+ $t5->save();
+ $t6 = new FkScopeTable();
+ $t6->setRank(3);
+ $t6->setScopeValue($s2);
+ $t6->setTitle('row6');
+ $t6->save();
+ $t7 = new FkScopeTable();
+ $t7->setRank(1);
+ $t7->setTitle('row7');
+ $t7->save();
+ $t8 = new FkScopeTable();
+ $t8->setRank(2);
+ $t8->setTitle('row8');
+ $t8->save();
+ $t9 = new FkScopeTable();
+ $t9->setRank(3);
+ $t9->setTitle('row9');
+ $t9->save();
+ }
+
protected function getFixturesArray()
{
$c = new Criteria();
@@ -117,4 +175,18 @@ protected function getFixturesArrayWithScope($scope = null)
return $ret;
}
+
+ protected function getFixturesArrayWithFkScope($scope = null)
+ {
+ $c = new Criteria();
+ $c->add(FkScopeTablePeer::SCOPE_COL, $scope);
+ $c->addAscendingOrderByColumn(FkScopeTablePeer::RANK_COL);
+ $ts = FkScopeTablePeer::doSelect($c);
+ $ret = array();
+ foreach ($ts as $t) {
+ $ret[$t->getRank()] = $t->getTitle();
+ }
+
+ return $ret;
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.