Tree = new TreeHelper(new View(null)); $this->Model = ClassRegistry::init('AfterTree'); $this->Model->Behaviors->attach('Tree'); $this->Model->truncate(); $data = array( array('name' => 'One'), array('name' => 'Two'), array('name' => 'Three'), array('name' => 'Four'), array('name' => 'One-SubA', 'parent_id' => 1), array('name' => 'Two-SubA', 'parent_id' => 2), array('name' => 'Four-SubA', 'parent_id' => 4), array('name' => 'Two-SubA-1', 'parent_id' => 6), array('name' => 'Two-SubA-1-1', 'parent_id' => 8), ); foreach ($data as $row) { $this->Model->create(); $this->Model->save($row); } } public function tearDown() { parent::tearDown(); } public function testObject() { $this->assertTrue(is_a($this->Tree, 'TreeHelper')); } public function testGenerate() { $tree = $this->Model->find('threaded'); $output = $this->Tree->generate($tree); $expected = <<
  • One
  • Two
  • Three
  • Four
  • TEXT; $this->assertTextEquals($expected, $output); $this->assertTrue(substr_count($output, '')); $this->assertTrue(substr_count($output, '
  • ') === substr_count($output, '
  • ')); } //TODO: fixme: 8,9 is "Two-SubA-1-1" and so this entry should also be active public function testGenerateWithAutoPath() { $tree = $this->Model->find('threaded'); debug($tree); $output = $this->Tree->generate($tree, array('autoPath' => array(8, 9))); debug($output); $expected = <<
  • One
    • One-SubA
  • Two
    • Two-SubA
      • Two-SubA-1
        • Two-SubA-1-1
  • Three
  • Four
    • Four-SubA
  • TEXT; $this->assertTextEquals($expected, $output); } }