protected function initTreeWithScope() { \Map\NestedSetTable10TableMap::doDeleteAll(); $ret = array(); $fixtures = array('t1' => array(1, 14, 0, 1), 't2' => array(2, 3, 1, 1), 't3' => array(4, 13, 1, 1), 't4' => array(5, 6, 2, 1), 't5' => array(7, 12, 2, 1), 't6' => array(8, 9, 3, 1), 't7' => array(10, 11, 3, 1), 't8' => array(1, 6, 0, 2), 't9' => array(2, 3, 1, 2), 't10' => array(4, 5, 1, 2)); foreach ($fixtures as $key => $data) { $t = new Fixtures\PublicTable10(); $t->setTitle($key); $t->setLeftValue($data[0]); $t->setRightValue($data[1]); $t->setLevel($data[2]); $t->setScopeValue($data[3]); $t->save(); $ret[] = $t; } return $ret; }
public function testInsertAsNextSiblingOf() { $this->assertTrue(method_exists('NestedSetTable10', 'insertAsNextSiblingOf'), 'nested_set adds a insertAsNextSiblingOf() method'); $fixtures = $this->initTreeWithScope(); /* Tree used for tests Scope 1 t1 | \ t2 t3 | \ t4 t5 | \ t6 t7 Scope 2 t8 | \ t9 t10 */ $t11 = new Fixtures\PublicTable10(); $t11->setTitle('t11'); $t11->insertAsNextSiblingOf($fixtures[2]); // next sibling of t3 $this->assertEquals(1, $t11->getScopeValue(), 'insertAsNextSiblingOf() sets the scope value correctly'); $t11->save(); $expected = ['t1' => [1, 16, 0], 't2' => [2, 3, 1], 't3' => [4, 13, 1], 't4' => [5, 6, 2], 't5' => [7, 12, 2], 't6' => [8, 9, 3], 't7' => [10, 11, 3], 't11' => [14, 15, 1]]; $this->assertEquals($expected, $this->dumpTreeWithScope(1), 'insertAsNextSiblingOf() shifts the other nodes correctly'); $expected = ['t8' => [1, 6, 0], 't9' => [2, 3, 1], 't10' => [4, 5, 1]]; $this->assertEquals($expected, $this->dumpTreeWithScope(2), 'insertAsNextSiblingOf() does not shift anything out of the scope'); }