table = TableRegistry::get('NumberTrees'); $this->table->addBehavior('Tree'); } public function tearDown() { parent::tearDown(); TableRegistry::clear(); } /** * Tests the find('path') method * * @return void */ public function testFindPath() { $nodes = $this->table->find('path', ['for' => 9]); $this->assertEquals([1, 6, 9], $nodes->extract('id')->toArray()); $nodes = $this->table->find('path', ['for' => 10]); $this->assertEquals([1, 6, 10], $nodes->extract('id')->toArray()); $nodes = $this->table->find('path', ['for' => 5]); $this->assertEquals([1, 2, 5], $nodes->extract('id')->toArray()); $nodes = $this->table->find('path', ['for' => 1]); $this->assertEquals([1], $nodes->extract('id')->toArray()); $nodes = $this->table->find('path', ['for' => 11]); $this->assertEquals([11], $nodes->extract('id')->toArray()); } /** * Tests the childCount() * * @return void */ public function testChildCount() { // direct childs for the root node $countDirect = $this->table->childCount(1, true); $this->assertEquals($countDirect, 2); // counts all the childs of root $count = $this->table->childCount(1, false); $this->assertEquals($count, 9); // counts direct childs $count = $this->table->childCount(2, false); $this->assertEquals($count, 3); // count childs for a middle-node $count = $this->table->childCount(6, false); $this->assertEquals($count, 4); // count leaf childs $count = $this->table->childCount(10, false); $this->assertEquals($count, 0); } }