[ Index ] |
|
Code source de SPIP Agora 1.4 |
1 <?php 2 /** 3 * UnitTest 4 * Creation method tests 5 * 6 * @author Daniel Khan <dk@webcluster.at> 7 * @package DB_NestedSetTest 8 * @version $Revision: 1.5 $ 9 * @access public 10 */ 11 12 13 class tests_NestedSet_creation extends DB_NestedSetTest { 14 15 16 // +----------------------------------------------+ 17 // | Testing creation methods | 18 // |----------------------------------------------+ 19 // | [PUBLIC] | 20 // +----------------------------------------------+ 21 22 /** 23 * tests_NestedSet_common::test_createRootNode() 24 * 25 * Simply create some rootnodes and see if this works 26 * 27 * @access public 28 * @see _createRootNodes() 29 * @return array Array of created rootnodes 30 */ 31 function test_createRootNode($dist = false) { 32 33 return $this->_createRootNodes(15); 34 } 35 36 /** 37 * tests_NestedSet_common::test_createRootNode__mixup() 38 * 39 * Create some rootnodes and create another rootnodes inbetween the others to look 40 * if the ordering is right afterwards 41 * 42 * @access public 43 * @see _createRootNodes() 44 * @return array Array of created rootnodes 45 */ 46 function test_createRootNode__mixup() { 47 return $this->_createRootNodes(15, true); 48 } 49 50 51 52 /** 53 * tests_NestedSet_common::test_createSubNode() 54 * 55 * Recursively create a tree using createSubNode and verify the results 56 * 57 * @access public 58 * @see _createSubNode() 59 * @return array Parent/Child relationship tree 60 */ 61 function test_createSubNode() { 62 63 $rnc = 3; 64 $depth = 3; 65 $npl = 3; 66 return $this->_createSubNode($rnc, $depth, $npl); 67 } 68 69 /** 70 * tests_NestedSet_common::test_createRightNode() 71 * 72 * Create some right nodes and query some meta informations 73 * 74 * @access public 75 * @see _createSubNode() 76 * @return bool True on completion 77 */ 78 function test_createRightNode() { 79 $rnc = 6; 80 $rootnodes = $this->_createRootNodes($rnc); 81 $x = 0; 82 foreach($rootnodes AS $rid=>$rootnode) { 83 $values['STRNA'] = 'R'.$x; 84 $rn1 = $this->_NeSe->createRightNode($rid, $values, true); 85 $values['STRNA'] = 'RS'.$x; 86 $sid = $this->_NeSe->createSubNode($rn1, $values); 87 $values['STRNA'] = 'RSR'.$x; 88 89 // Test quoting of reserved words 90 $values['key'] = 'SELECT'; 91 92 // Try to overwrite the ROOTID which should be set inside the method 93 // $values['ROOTID'] = -100; 94 $rn2 = $this->_NeSe->createRightNode($sid, $values, true); 95 $x++; 96 97 $right1 = $this->_NeSe->pickNode($rn1, true); 98 $right2 = $this->_NeSe->pickNode($rn2, true); 99 100 101 // Root ID has to equal ID 102 $this->assertEquals($right1['rootid'], $right1['id'], "Right node has wrong root id."); 103 104 // Order 105 $upd_rootnode = $this->_NeSe->pickNode($rid, true); 106 107 $this->assertEquals($upd_rootnode['norder']+1, $right1['norder'], "Right node has wrong order."); 108 109 // Level 110 $this->assertEquals(1, $right1['level'], "Right node has wrong level."); 111 112 // Children 113 $exp_cct = floor(($right1['r'] - $right1['l'])/2); 114 $allchildren = $this->_NeSe->getSubBranch($rn1, true); 115 116 // This is also a good test if l/r values are ok 117 $this->assertEquals($exp_cct, count($allchildren), "Right node has wrong child count."); 118 119 // Order 120 $upd_subnode = $this->_NeSe->pickNode($sid, true); 121 $this->assertEquals($upd_subnode['norder']+1, $right2['norder'], "Right node has wrong order."); 122 123 // Level 124 $this->assertEquals(2, $right2['level'], "Right node has wrong level."); 125 126 // Test root id 127 $this->assertEquals($right1['rootid'], $right2['rootid'], "Right node has wrong root id."); 128 } 129 $allnodes = $this->_NeSe->getAllNodes(true); 130 $this->assertEquals($rnc*4, count($allnodes), "Wrong node count after right insertion"); 131 return true; 132 } 133 134 /** 135 * tests_NestedSet_common::test_createLeftNode() 136 * 137 * Create some left nodes and query some meta informations 138 * 139 * @access public 140 * @see _createSubNode() 141 * @return bool True on completion 142 */ 143 function test_createLeftNode() { 144 $rnc = 6; 145 $rootnodes = $this->_createRootNodes($rnc); 146 $x = 0; 147 foreach($rootnodes AS $rid=>$rootnode) { 148 149 $values['STRNA'] = 'R'.$x; 150 $rn1 = $this->_NeSe->createLeftNode($rid, $values); 151 $values['STRNA'] = 'RS'.$x; 152 $sid = $this->_NeSe->createSubNode($rn1, $values); 153 $values['STRNA'] = 'RSR'.$x; 154 // Test quoting of reserved words 155 $values['key'] = 'SELECT'; 156 157 // Try to overwrite the ROOTID which should be set inside the method 158 // $values['ROOTID'] = -100; 159 $rn2 = $this->_NeSe->createLeftNode($sid, $values); 160 $x++; 161 162 $left1 = $this->_NeSe->pickNode($rn1, true); 163 $left2 = $this->_NeSe->pickNode($rn2, true); 164 165 166 167 // Root ID has to equal ID 168 $this->assertEquals($left1['rootid'], $left1['id'], "Left node has wrong root id."); 169 170 // Order 171 $upd_rootnode = $this->_NeSe->pickNode($rid, true); 172 $this->assertEquals($upd_rootnode['norder']-1, $left1['norder'], "Left node 1 has wrong order."); 173 174 // Level 175 $this->assertEquals(1, $left1['level'], "Left node has wrong level."); 176 177 // Children 178 $exp_cct = floor(($left1['r'] - $left1['l'])/2); 179 $allchildren = $this->_NeSe->getSubBranch($rn1, true); 180 181 // This is also a good test if l/r values are ok 182 $this->assertEquals($exp_cct, count($allchildren), "Left node has wrong child count."); 183 184 // Order 185 $upd_subnode = $this->_NeSe->pickNode($sid, true); 186 $this->assertEquals($upd_subnode['norder']-1, $left2['norder'], "Left node 2 has wrong order."); 187 188 // Level 189 $this->assertEquals(2, $left2['level'], "Left node has wrong level."); 190 191 // Test root id 192 $this->assertEquals($left1['rootid'], $left2['rootid'], "Left node has wrong root id."); 193 } 194 $allnodes = $this->_NeSe->getAllNodes(true); 195 $this->assertEquals($rnc*4, count($allnodes), "Wrong node count after right insertion"); 196 return true; 197 } 198 199 /** 200 * tests_NestedSet_common::createSubNode__random() 201 * 202 * Create some rootnodes and randomly call createSubNode() or createRightNode() 203 * on the growing tree. This creates a very random structure which 204 * is intended to be a real life simulation to catch bugs not beeing 205 * catched by the other tests. 206 * Some basic regression tests including _traverseChildren() with a relation tree 207 * are made. 208 * 209 * @access public 210 * @see _createRandomNodes() 211 * @return bool True on completion 212 */ 213 function test_createNodes__random() { 214 215 $this->_createRandomNodes(3, 150); 216 return true; 217 } 218 } 219 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 14:40:03 2007 | par Balluche grâce à PHPXref 0.7 |