Exemple #1
0
 /**
  * Tests the update_dependency_id() function.
  */
 public function test_update_dependency_id()
 {
     // Create tree with structure of 3 mocks.
     $structure = tree::get_root_json(array(tree::get_nested_json(array(self::mock(array('table' => 'frogs', 'id' => 9)), self::mock(array('table' => 'zombies', 'id' => 9)))), self::mock(array('table' => 'frogs', 'id' => 9))));
     // Get 'before' value.
     $tree = new tree($structure);
     $before = $tree->save();
     // Try replacing a table or id that isn't used.
     $this->assertFalse($tree->update_dependency_id('toads', 9, 13));
     $this->assertFalse($tree->update_dependency_id('frogs', 7, 8));
     $this->assertEquals($before, $tree->save());
     // Replace the zombies one.
     $this->assertTrue($tree->update_dependency_id('zombies', 9, 666));
     $after = $tree->save();
     $this->assertEquals(666, $after->c[0]->c[1]->id);
     // And the frogs one.
     $this->assertTrue($tree->update_dependency_id('frogs', 9, 3));
     $after = $tree->save();
     $this->assertEquals(3, $after->c[0]->c[0]->id);
     $this->assertEquals(3, $after->c[1]->id);
 }