Changeset 407
- Timestamp:
- 10/16/07 16:51:35 (1 year ago)
- Files:
-
- branches/kaste/framework/lib/AkActiveRecord/AkAssociation.php (modified) (1 diff)
- branches/kaste/framework/lib/AkActiveRecord/AkBelongsTo.php (modified) (1 diff)
- branches/kaste/framework/lib/AkActiveRecord/AkHasAndBelongsToMany.php (modified) (6 diffs)
- branches/kaste/framework/lib/AkActiveRecord/AkHasMany.php (modified) (4 diffs)
- branches/kaste/framework/lib/AkActiveRecord/AkHasOne.php (modified) (2 diffs)
- branches/kaste/framework/lib/AkActiveRecord/AkObserver.php (modified) (1 diff)
- branches/kaste/framework/lib/AkInstaller.php (modified) (2 diffs)
- branches/kaste/framework/test/fixtures/app/models/ak_test_member.php (added)
- branches/kaste/framework/test/fixtures/app/models/ak_test_user.php (added)
- branches/kaste/framework/test/fixtures/app/models/article.php (deleted)
- branches/kaste/framework/test/fixtures/app/models/category.php (added)
- branches/kaste/framework/test/fixtures/app/models/dependent_category.php (added)
- branches/kaste/framework/test/fixtures/app/models/nested_category.php (added)
- branches/kaste/framework/test/fixtures/app/models/observed_person_observer.php (added)
- branches/kaste/framework/test/fixtures/app/models/test_auditor.php (added)
- branches/kaste/framework/test/fixtures/app/models/test_person.php (added)
- branches/kaste/framework/test/fixtures/app/models/todo_item.php (added)
- branches/kaste/framework/test/unit/lib/AkActiveRecord/AkActsAsList.php (modified) (49 diffs)
- branches/kaste/framework/test/unit/lib/AkActiveRecord/AkActsAsNestedSet.php (modified) (10 diffs)
- branches/kaste/framework/test/unit/lib/AkActiveRecord/AkActsAsTree.php (modified) (12 diffs)
- branches/kaste/framework/test/unit/lib/AkActiveRecord/AkBelongsTo.php (modified) (2 diffs)
- branches/kaste/framework/test/unit/lib/AkActiveRecord/AkHasAndBelongsToMany.php (modified) (4 diffs)
- branches/kaste/framework/test/unit/lib/AkActiveRecord/AkHasMany.php (modified) (4 diffs)
- branches/kaste/framework/test/unit/lib/AkActiveRecord/AkObserver.php (modified) (5 diffs)
- branches/kaste/framework/test/unit/lib/AkActiveRecord/AkValidation.php (modified) (36 diffs)
- branches/kaste/framework/test/unit/lib/AkActiveRecord/_AkActiveRecord_1.php (modified) (2 diffs)
- branches/kaste/framework/test/unit/lib/AkActiveRecord/_AkActiveRecord_2.php (modified) (3 diffs)
- branches/kaste/framework/test/unit/lib/AkActiveRecord/_AkActiveRecord_3.php (modified) (3 diffs)
- branches/kaste/framework/test/unit/lib/AkActiveRecord/_AkActiveRecord_findOrCreateBy.php (modified) (1 diff)
- branches/kaste/framework/test/unit/lib/AkActiveRecord/_AkActiveRecord_i18n.php (modified) (1 diff)
- branches/kaste/framework/test/unit/lib/AkInstaller.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/kaste/framework/lib/AkActiveRecord/AkAssociation.php
r285 r407 128 128 { 129 129 $this->Owner->_associationIds[$association_id] = $associated_id; 130 $this->ass sociated_ids[$association_id] = $associated_id;130 $this->associated_ids[$association_id] = $associated_id; 131 131 } 132 132 branches/kaste/framework/lib/AkActiveRecord/AkBelongsTo.php
r329 r407 57 57 class AkBelongsTo extends AkAssociation 58 58 { 59 var $ass sociated_ids = array();59 var $associated_ids = array(); 60 60 61 61 function &addAssociated($association_id, $options = array()) branches/kaste/framework/lib/AkActiveRecord/AkHasAndBelongsToMany.php
r396 r407 111 111 */ 112 112 var $JoinObject; 113 var $ass sociated_ids = array();113 var $associated_ids = array(); 114 114 var $association_id; 115 115 var $_automatically_create_join_model_files = AK_HAS_AND_BELONGS_TO_MANY_CREATE_JOIN_MODEL_CLASSES; … … 501 501 } 502 502 } 503 unset($this->ass sociated_ids[$record_id]);503 unset($this->associated_ids[$record_id]); 504 504 $this->_unsetAssociatedMemberId($records[$k]); 505 505 if(!empty($options['after_remove']) && method_exists($this->Owner, $options['after_remove'])){ … … 521 521 $object_id = $Member->getId(); 522 522 if(!empty($object_id)){ 523 $this->ass sociated_ids[$object_id] = $Member->__hasAndBelongsToManyMemberId;523 $this->associated_ids[$object_id] = $Member->__hasAndBelongsToManyMemberId; 524 524 } 525 525 } … … 528 528 { 529 529 $id = $this->_getAssociatedMemberId($Member); 530 unset($this->ass sociated_ids[$id]);530 unset($this->associated_ids[$id]); 531 531 unset($Member->__hasAndBelongsToManyMemberId); 532 532 } … … 535 535 { 536 536 if(!empty($Member->__hasAndBelongsToManyMemberId)) { 537 return array_search($Member->__hasAndBelongsToManyMemberId, $this->ass sociated_ids);537 return array_search($Member->__hasAndBelongsToManyMemberId, $this->associated_ids); 538 538 } 539 539 return false; … … 543 543 { 544 544 $options = $this->getOptions($this->association_id); 545 if($options['unique'] && !$Member->isNewRecord() && isset($this->ass sociated_ids[$Member->getId()])){545 if($options['unique'] && !$Member->isNewRecord() && isset($this->associated_ids[$Member->getId()])){ 546 546 return true; 547 547 } branches/kaste/framework/lib/AkActiveRecord/AkHasMany.php
r328 r407 80 80 class AkHasMany extends AkAssociation 81 81 { 82 var $ass sociated_ids = array();82 var $associated_ids = array(); 83 83 var $association_id; 84 84 … … 406 406 $object_id = method_exists($Member,'getId') ? $Member->getId() : null; 407 407 if(!empty($object_id)){ 408 $this->ass sociated_ids[$object_id] = $Member->__hasManyMemberId;408 $this->associated_ids[$object_id] = $Member->__hasManyMemberId; 409 409 } 410 410 } … … 413 413 { 414 414 $id = $this->_getAssociatedMemberId($Member); 415 unset($this->ass sociated_ids[$id]);415 unset($this->associated_ids[$id]); 416 416 unset($Member->__hasManyMemberId); 417 417 } … … 420 420 { 421 421 if(!empty($Member->__hasManyMemberId)) { 422 return array_search($Member->__hasManyMemberId, $this->ass sociated_ids);422 return array_search($Member->__hasManyMemberId, $this->associated_ids); 423 423 } 424 424 return false; branches/kaste/framework/lib/AkActiveRecord/AkHasOne.php
r285 r407 55 55 class AkHasOne extends AkAssociation 56 56 { 57 var $ass sociated_ids = array();57 var $associated_ids = array(); 58 58 59 59 function &addAssociated($association_id, $options = array()) … … 112 112 function getAssociatedId($association_id) 113 113 { 114 return isset($this->ass sociated_ids[$association_id]) ? $this->asssociated_ids[$association_id] : false;114 return isset($this->associated_ids[$association_id]) ? $this->associated_ids[$association_id] : false; 115 115 } 116 116 branches/kaste/framework/lib/AkActiveRecord/AkObserver.php
r366 r407 132 132 { 133 133 $class_name = AkInflector::camelize($class_name); 134 include_once(AkInflector::toModelFilename($class_name)); 135 eval("\$model =& new $class_name();"); 134 if (!class_exists($class_name)) require_once(AkInflector::toModelFilename($class_name)); 135 $model =& new $class_name(); 136 //eval("\$model =& new $class_name();"); 136 137 $this->observe(&$model); 137 138 } branches/kaste/framework/lib/AkInstaller.php
r396 r407 277 277 ); 278 278 $table_options = array_merge($default_table_options, $table_options); 279 279 280 280 $column_string = $this->_getColumnsAsAdodbDataDictionaryString($column_options['columns']); 281 282 281 $result = $this->data_dictionary->ExecuteSQLArray($this->data_dictionary->ChangeTableSQL($table_name, str_replace(array(' UNIQUE', ' INDEX', ' FULLTEXT', ' HASH'), '', $column_string), $table_options)); 283 282 … … 389 388 $columns = $this->_setColumnDefaults($columns); 390 389 $this->_ensureColumnNameCompatibility($columns); 390 391 391 $equivalences = array( 392 392 '/ ((limit|max|length) ?= ?)([0-9]+)([ \n\r,]+)/'=> ' (\3) ', 393 393 '/([ \n\r,]+)default([ =]+)([^\'^,^\n]+)/i'=> ' DEFAULT \'\3\'', 394 '/([ \n\r,]+)(integer|int)([( \n\r,] *)/'=> '\1 I \3',394 '/([ \n\r,]+)(integer|int)([( \n\r,]+)/'=> '\1 I \3', 395 395 '/([ \n\r,]+)float([( \n\r,]+)/'=> '\1 F \2', 396 '/([ \n\r,]+)datetime([( \n\r,] *)/'=> '\1 T \2',397 '/([ \n\r,]+)date([( \n\r,] *)/'=> '\1 D \2',398 '/([ \n\r,]+)timestamp([( \n\r,] *)/'=> '\1 T \2',399 '/([ \n\r,]+)time([( \n\r,] *)/'=> '\1 T \2',400 '/([ \n\r,]+)text([( \n\r,] *)/'=> '\1 XL \2',401 '/([ \n\r,]+)string([( \n\r,] *)/'=> '\1 C \2',402 '/([ \n\r,]+)binary([( \n\r,] *)/'=> '\1 B \2',403 '/([ \n\r,]+)boolean([( \n\r,] *)/'=> '\1 L(1) \2',396 '/([ \n\r,]+)datetime([( \n\r,]+)/'=> '\1 T \2', 397 '/([ \n\r,]+)date([( \n\r,]+)/'=> '\1 D \2', 398 '/([ \n\r,]+)timestamp([( \n\r,]+)/'=> '\1 T \2', 399 '/([ \n\r,]+)time([( \n\r,]+)/'=> '\1 T \2', 400 '/([ \n\r,]+)text([( \n\r,]+)/'=> '\1 XL \2', 401 '/([ \n\r,]+)string([( \n\r,]+)/'=> '\1 C \2', 402 '/([ \n\r,]+)binary([( \n\r,]+)/'=> '\1 B \2', 403 '/([ \n\r,]+)boolean([( \n\r,]+)/'=> '\1 L(1) \2', 404 404 '/ NOT( |_)?NULL/i'=> ' NOTNULL', 405 405 '/ AUTO( |_)?INCREMENT/i'=> ' AUTO ', branches/kaste/framework/test/unit/lib/AkActiveRecord/AkActsAsList.php
r396 r407 1 1 <?php 2 3 defined('AK_TEST_DATABASE_ON') ? null : define('AK_TEST_DATABASE_ON', true); 4 require_once(dirname(__FILE__).'/../../../fixtures/config/config.php'); 5 6 if(!defined('AK_ACTIVE_RECORD_PROTECT_GET_RECURSION')){ 7 define('AK_ACTIVE_RECORD_PROTECT_GET_RECURSION', false); 8 } 2 9 3 10 class AkActiveRecord_actsAsListTestCase extends AkUnitTest 4 11 { 5 /**/6 var $_testing_models_to_delete = array();7 var $_testing_model_databases_to_delete = array();8 12 9 13 function test_AkActiveRecord_actsAsList() 10 14 { 11 parent::UnitTestCase(); 12 $this->_createNewTestingModelDatabase('AkTestTodoItem'); 13 $this->_createNewTestingModel('AkTestTodoItem'); 14 } 15 16 function tearDown() 17 { 18 unset($_SESSION['__activeRecordColumnsSettingsCache']); 19 } 20 21 function _createNewTestingModel($test_model_name) 22 { 23 24 static $shutdown_called; 25 switch ($test_model_name) { 26 27 case 'AkTestTodoItem': 28 $model_source = 29 '<?php 30 class AkTestTodoItem extends AkActiveRecord 31 { 32 var $act_as = "list"; 33 } 34 ?>'; 35 break; 36 37 default: 38 $model_source = '<?php class '.$test_model_name.' extends AkActiveRecord { } ?>'; 39 break; 40 } 41 42 $file_name = AkInflector::toModelFilename($test_model_name); 43 44 if(!Ak::file_put_contents($file_name,$model_source)){ 45 die('Ooops!, in order to perform this test, you must set your app/model permissions so this can script can create and delete files into/from it'); 46 } 47 if(!in_array($file_name, get_included_files()) && !class_exists($test_model_name)){ 48 include($file_name); 49 }else { 50 return false; 51 } 52 $this->_testing_models_to_delete[] = $file_name; 53 if(!isset($shutdown_called)){ 54 $shutdown_called = true; 55 register_shutdown_function(array(&$this,'_deleteTestingModels')); 56 } 57 return true; 58 } 59 60 function _deleteTestingModels() 61 { 62 foreach ($this->_testing_models_to_delete as $file){ 63 Ak::file_delete($file); 64 } 65 } 66 67 68 69 70 function _createNewTestingModelDatabase($test_model_name) 71 { 72 static $shutdown_called; 73 // Create a data dictionary object, using this connection 74 $db =& AK::db(); 75 //$db->debug = true; 76 $table_name = AkInflector::tableize($test_model_name); 77 if(in_array($table_name, (array)$db->MetaTables())){ 78 return false; 79 } 80 switch ($table_name) { 81 case 'ak_test_todo_items': 82 $table = 83 array( 84 'table_name' => 'ak_test_todo_items', 85 'fields' => 'id I AUTO KEY, 86 position I(20), 87 task X, 88 due_time T, 89 created_at T, 90 expires T, 91 updated_at T, 92 new_position I(10)', 93 'index_fileds' => 'id', 94 'table_options' => array('mysql' => 'TYPE=InnoDB', 'REPLACE') 95 ); 96 break; 97 default: 98 return false; 99 break; 100 } 101 102 $dict = NewDataDictionary($db->connection); 103 $sqlarray = $dict->CreateTableSQL($table['table_name'], $table['fields'], $table['table_options']); 104 $dict->ExecuteSQLArray($sqlarray); 105 if(isset($table['index_fileds'])){ 106 $sqlarray = $dict->CreateIndexSQL('idx_'.$table['table_name'], $table['table_name'], $table['index_fileds']); 107 $dict->ExecuteSQLArray($sqlarray); 108 } 109 110 $db->CreateSequence('seq_'.$table['table_name']); 111 112 $this->_testing_model_databases_to_delete[] = $table_name; 113 if(!isset($shutdown_called)){ 114 $shutdown_called = true; 115 register_shutdown_function(array(&$this,'_deleteTestingModelDatabases')); 116 } 117 //$db->debug = false; 118 return true; 119 } 120 121 function _deleteTestingModelDatabases() 122 { 123 $db =& AK::db(); 124 foreach ($this->_testing_model_databases_to_delete as $table_name){ 125 $db->Execute('DROP TABLE '.$table_name); 126 $db->DropSequence('seq_'.$table_name); 127 } 15 $this->installAndIncludeModels(array( 16 'TodoItem'=>'id, position int(20), task text, due_time datetime, created_at, expires datetime, updated_at,new_position int(10)' 17 )); 128 18 } 129 19 130 20 function Test_of_actsAsList_instatiation() 131 21 { 132 $TodoItems =& new AkTestTodoItem();22 $TodoItems =& new TodoItem(); 133 23 $this->assertEqual($TodoItems->actsLike(), 'active record,list'); 134 24 $this->assertFalse(empty($TodoItems->list->column)); 135 25 $this->assertTrue(empty($TodoItems->list->scope)); 136 26 137 $TodoItems =& new AkTestTodoItem();27 $TodoItems =& new TodoItem(); 138 28 $this->assertErrorPattern('/not_available/',$TodoItems->actsAs('list', array('column'=>'not_available'))); 139 29 … … 144 34 function Test_of_Test_of___construct() 145 35 { 146 $TodoItems =& new AkTestTodoItem();36 $TodoItems =& new TodoItem(); 147 37 $TodoItems->actsAs('list', 148 38 array( … … 157 47 function Test_of__ensureIsActiveRecordInstance() 158 48 { 159 $TodoItems =& new AkTestTodoItem();49 $TodoItems =& new TodoItem(); 160 50 $Object =& new AkObject(); 161 51 $this->assertErrorPattern('/is not an active record/',$TodoItems->list->_ensureIsActiveRecordInstance(&$Object)); … … 164 54 function Test_of_getType() 165 55 { 166 $TodoItems =& new AkTestTodoItem();56 $TodoItems =& new TodoItem(); 167 57 $this->assertEqual($TodoItems->list->getType(), 'list'); 168 58 } … … 170 60 function Test_of_getScopeCondition_and_setScopeCondition() 171 61 { 172 $TodoItems =& new AkTestTodoItem();62 $TodoItems =& new TodoItem(); 173 63 $this->assertEqual($TodoItems->list->getScopeCondition(), ($TodoItems->_db->type() == 'postgre') ? 'true' : '1'); 174 64 $TodoItems->list->setScopeCondition('true'); … … 178 68 function Test_of_getBottomItem_1() 179 69 { 180 $TodoItems =& new AkTestTodoItem();70 $TodoItems =& new TodoItem(); 181 71 $this->assertFalse($TodoItems->list->getBottomItem()); 182 72 } … … 184 74 function Test_of_getBottomPosition_1() 185 75 { 186 $TodoItems =& new AkTestTodoItem();76 $TodoItems =& new TodoItem(); 187 77 $this->assertIdentical($TodoItems->list->getBottomPosition(), 0); 188 78 } … … 190 80 function Test_of__addToBottom_1() 191 81 { 192 $TodoItems =& new AkTestTodoItem();82 $TodoItems =& new TodoItem(); 193 83 $TodoItems->List->_addToBottom(); 194 84 $this->assertIdentical($TodoItems->position, 1); … … 198 88 function Test_of_beforeCreate() 199 89 { 200 $TodoItems =& new AkTestTodoItem();90 $TodoItems =& new TodoItem(); 201 91 $position = $TodoItems->getAttribute('position'); 202 92 $TodoItems->List->beforeCreate($TodoItems); … … 207 97 function Test_of_getBottomItem_2() 208 98 { 209 $TodoItems =& new AkTestTodoItem('task->','Email Hilario with new product specs','due_time->',Ak::getDate(Ak::time()+(60*60*24*7)));99 $TodoItems =& new TodoItem('task->','Email Hilario with new product specs','due_time->',Ak::getDate(Ak::time()+(60*60*24*7))); 210 100 $this->assertPattern('/list/',$TodoItems->actsLike()); 211 101 $this->assertTrue($TodoItems->isNewRecord()); … … 216 106 $this->assertEqual($getBottomItem->toString(), $TodoItems->toString()); 217 107 218 $TodoItems =& new AkTestTodoItem('task->','Book COMDEX trip','due_time->',Ak::getDate(Ak::time()+(60*60*24*3)));108 $TodoItems =& new TodoItem('task->','Book COMDEX trip','due_time->',Ak::getDate(Ak::time()+(60*60*24*3))); 219 109 $this->assertTrue($TodoItems->isNewRecord()); 220 110 $this->assertTrue($TodoItems->save()); … … 223 113 $this->assertEqual($getBottomItem->toString(), $TodoItems->toString()); 224 114 225 $TodoItems =& new AkTestTodoItem(1);115 $TodoItems =& new TodoItem(1); 226 116 $this->assertTrue($getBottomItem = $TodoItems->List->getBottomItem(2)); 227 117 $this->assertEqual($getBottomItem->toString(), $TodoItems->toString()); … … 231 121 function Test_of_getBottomPosition_2() 232 122 { 233 $TodoItems =& new AkTestTodoItem();123 $TodoItems =& new TodoItem(); 234 124 $this->assertEqual($TodoItems->list->getBottomPosition(), 2); 235 125 … … 240 130 function Test_of__addToBottom_2() 241 131 { 242 $TodoItems =& new AkTestTodoItem();132 $TodoItems =& new TodoItem(); 243 133 $TodoItems->list->_addToBottom(); 244 134 $this->assertIdentical($TodoItems->position, 3); … … 249 139 function Test_of_isInList() 250 140 { 251 $TodoItems =& new AkTestTodoItem();141 $TodoItems =& new TodoItem(); 252 142 $this->assertFalse($TodoItems->list->isInList()); 253 143 254 $TodoItems =& new AkTestTodoItem(1);144 $TodoItems =& new TodoItem(1); 255 145 $this->assertTrue($TodoItems->list->isInList()); 256 146 } … … 261 151 for ($i = 0; $i <= 30; $i++){ 262 152 $attributes = array('task'=>'Task number '.($i+3),'due_time'=>Ak::getDate(Ak::time()+(60*60*24*$i))); 263 $TodoTask =& new AkTestTodoItem($attributes);153 $TodoTask =& new TodoItem($attributes); 264 154 $this->assertTrue($TodoTask->save()); 265 155 $this->assertTrue(($TodoTask->task == $attributes['task']) && $TodoTask->due_time == $attributes['due_time']); … … 270 160 function Test_of_decrementPositionsOnLowerItems() 271 161 { 272 $TodoItems =& new AkTestTodoItem();162 $TodoItems =& new TodoItem(); 273 163 $TodoItems->transactionStart(); 274 164 $this->assertFalse($TodoItems->list->decrementPositionsOnLowerItems()); … … 276 166 $todo_list = $this->_getTodoList(); 277 167 $this->assertEqual($todo_list[10] , 'Task number 10'); 278 $TodoItems =& new AkTestTodoItem(10);168 $TodoItems =& new TodoItem(10); 279 169 280 170 $this->assertTrue($TodoItems->list->decrementPositionsOnLowerItems()); … … 293 183 function Test_of_removeFromList() 294 184 { 295 $TodoItems =& new AkTestTodoItem(10);185 $TodoItems =& new TodoItem(10); 296 186 297 187 $TodoItems->transactionStart(); … … 307 197 function Test_of_afterDestroy_and_beforeDestroy() 308 198 { 309 $TodoItems =& new AkTestTodoItem(10);199 $TodoItems =& new TodoItem(10); 310 200 311 201 $TodoItems->transactionStart(); … … 335 225 function Test_of_getLowerItem() 336 226 { 337 $TodoItems =& new AkTestTodoItem();227 $TodoItems =& new TodoItem(); 338 228 $this->assertFalse($TodoItems->list->getLowerItem()); 339 229 $TodoItem = $TodoItems->find(10); … … 346 236 347 237 348 $TodoItems =& new AkTestTodoItem();238 $TodoItems =& new TodoItem(); 349 239 $TodoItems->transactionStart(); 350 240 $this->assertTrue($TodoItems->deleteAll()); … … 358 248 function Test_of_decrementPosition() 359 249 { 360 $TodoItems =& new AkTestTodoItem(10);250 $TodoItems =& new TodoItem(10); 361 251 $TodoItems->transactionStart(); 362 252 … … 369 259 function Test_of_incrementPosition() 370 260 { 371 $TodoItems =& new AkTestTodoItem(10);261 $TodoItems =& new TodoItem(10); 372 262 $TodoItems->transactionStart(); 373 263 … … 380 270 function Test_of_moveLower() 381 271 { 382 $TodoItems =& new AkTestTodoItem();272 $TodoItems =& new TodoItem(); 383 273 $this->assertFalse($TodoItems->list->moveLower()); 384 274 … … 387 277 $this->assertEqual($todo_list[11] , 'Task number 11'); 388 278 389 $TodoItems =& new AkTestTodoItem(10);279 $TodoItems =& new TodoItem(10); 390 280 $TodoItems->transactionStart(); 391 281 … … 396 286 $this->assertEqual($todo_list[11] , 'Task number 10'); 397 287 398 $TodoItems =& new AkTestTodoItem(33);288 $TodoItems =& new TodoItem(33); 399 289 $this->assertFalse($TodoItems->list->moveLower()); 400 290 … … 406 296 function Test_of_getHigherItem() 407 297 { 408 $TodoItems =& new AkTestTodoItem();298 $TodoItems =& new TodoItem(); 409 299 $this->assertFalse($TodoItems->list->getHigherItem()); 410 300 … … 417 307 418 308 419 $TodoItems =& new AkTestTodoItem();309 $TodoItems =& new TodoItem(); 420 310 $TodoItems->transactionStart(); 421 311 $this->assertTrue($TodoItems->deleteAll()); … … 430 320 function Test_of_moveHigher() 431 321 { 432 $TodoItems =& new AkTestTodoItem();322 $TodoItems =& new TodoItem(); 433 323 $this->assertFalse($TodoItems->list->moveHigher()); 434 324 … … 437 327 $this->assertEqual($todo_list[10] , 'Task number 10'); 438 328 439 $TodoItems =& new AkTestTodoItem(10);329 $TodoItems =& new TodoItem(10); 440 330 $TodoItems->transactionStart(); 441 331 … … 446 336 $this->assertEqual($todo_list[10] , 'Task number 9'); 447 337 448 $TodoItems =& new AkTestTodoItem(1);338 $TodoItems =& new TodoItem(1); 449 339 $this->assertFalse($TodoItems->list->moveHigher()); 450 340 … … 458 348 $this->assertEqual($todo_list[10] , 'Task number 10'); 459 349 460 $TodoItems =& new AkTestTodoItem(10);350 $TodoItems =& new TodoItem(10); 461 351 $TodoItems->transactionStart(); 462 352 … … 475 365 $this->assertEqual($todo_list[10] , 'Task number 10'); 476 366 477 $TodoItems =& new AkTestTodoItem();367 $TodoItems =& new TodoItem(); 478 368 $this->assertFalse($TodoItems->list->moveToBottom()); 479 369 480 $TodoItems =& new AkTestTodoItem(10);370 $TodoItems =& new TodoItem(10); 481 371 $TodoItems->transactionStart(); 482 372 … … 491 381 $TodoItems->transactionComplete(); 492 382 493 $TodoItems =& new AkTestTodoItem(33);383 $TodoItems =& new TodoItem(33); 494 384 $TodoItems->transactionStart(); 495 385 … … 505 395 function Test_of_incrementPositionsOnHigherItems() 506 396 { 507 $TodoItems =& new AkTestTodoItem();397 $TodoItems =& new TodoItem(); 508 398 $TodoItems->transactionStart(); 509 399 $this->assertFalse($TodoItems->list->incrementPositionsOnHigherItems()); … … 511 401 $todo_list = $this->_getTodoList(); 512 402 $this->assertEqual($todo_list[10] , 'Task number 10'); 513 $TodoItems =& new AkTestTodoItem(10);403 $TodoItems =& new TodoItem(10); 514 404 $this->assertTrue($TodoItems->list->incrementPositionsOnHigherItems()); 515 405 $todo_list = $this->_getTodoList(); … … 523 413 function Test_of_assumeTopPosition() 524 414 { 525 $TodoItems =& new AkTestTodoItem();526 $TodoItems->transactionStart(); 527 528 $todo_list = $this->_getTodoList(); 529 $this->assertEqual($todo_list[10] , 'Task number 10'); 530 $TodoItems =& new AkTestTodoItem(10);415 $TodoItems =& new TodoItem(); 416 $TodoItems->transactionStart(); 417 418 $todo_list = $this->_getTodoList(); 419 $this->assertEqual($todo_list[10] , 'Task number 10'); 420 $TodoItems =& new TodoItem(10); 531 421 $this->assertTrue($TodoItems->list->assumeTopPosition()); 532 422 $todo_list = $this->_getTodoList(); … … 541 431 $this->assertEqual($todo_list[10] , 'Task number 10'); 542 432 543 $TodoItems =& new AkTestTodoItem();433 $TodoItems =& new TodoItem(); 544 434 $this->assertFalse($TodoItems->list->moveToTop()); 545 435 546 $TodoItems =& new AkTestTodoItem(10);436 $TodoItems =& new TodoItem(10); 547 437 $TodoItems->transactionStart(); 548 438 … … 557 447 $TodoItems->transactionComplete(); 558 448 559 $TodoItems =& new AkTestTodoItem(1);449 $TodoItems =& new TodoItem(1); 560 450 $TodoItems->transactionStart(); 561 451 … … 571 461 function Test_of_isFirst() 572 462 { 573 $TodoItems =& new AkTestTodoItem(1);463 $TodoItems =& new TodoItem(1); 574 464 575 465 $this->assertTrue($TodoItems->list->isFirst()); 576 466 577 $TodoItems =& new AkTestTodoItem(2);467 $TodoItems =& new TodoItem(2); 578 468 $this->assertFalse($TodoItems->list->isFirst()); 579 469 580 $TodoItems =& new AkTestTodoItem();470 $TodoItems =& new TodoItem(); 581 471 $this->assertFalse($TodoItems->list->isFirst()); 582 472 } … … 585 475 function Test_of_isLast() 586 476 { 587 $TodoItems =& new AkTestTodoItem(33);477 $TodoItems =& new TodoItem(33); 588 478 $this->assertTrue($TodoItems->list->isLast()); 589 479 590 $TodoItems =& new AkTestTodoItem(1);480 $TodoItems =& new TodoItem(1); 591 481 $this->assertFalse($TodoItems->list->isLast()); 592 482 593 $TodoItems =& new AkTestTodoItem();483 $TodoItems =& new TodoItem(); 594 484 $this->assertFalse($TodoItems->list->isLast()); 595 485 } … … 598 488 function Test_of_incrementPositionsOnLowerItems() 599 489 { 600 $TodoItems =& new AkTestTodoItem();601 $TodoItems->transactionStart(); 602 603 $todo_list = $this->_getTodoList(); 604 $this->assertEqual($todo_list[10] , 'Task number 10'); 605 $TodoItems =& new AkTestTodoItem(10);490 $TodoItems =& new TodoItem(); 491 $TodoItems->transactionStart(); 492 493 $todo_list = $this->_getTodoList(); 494 $this->assertEqual($todo_list[10] , 'Task number 10'); 495 $TodoItems =& new TodoItem(10); 606 496 $this->assertTrue($TodoItems->list->incrementPositionsOnLowerItems(10)); 607 497 $todo_list = $this->_getTodoList(); … … 615 505 function Test_of_insertAtPosition() 616 506 { 617 $TodoItems =& new AkTestTodoItem(10);507 $TodoItems =& new TodoItem(10); 618 508 $TodoItems->transactionStart(); 619 509 … … 623 513 624 514 625 $TodoItems =& new AkTestTodoItem('task->','ship new InmoEasy version');515 $TodoItems =& new TodoItem('task->','ship new InmoEasy version'); 626 516 $TodoItems->list->insertAtPosition(1); 627 517 $todo_list = $this->_getTodoList(); 628 518 $this->assertEqual($todo_list[1] , 'ship new InmoEasy version'); 629 519 630 $TodoItems =& new AkTestTodoItem(10);520 $TodoItems =& new TodoItem(10); 631 521 $TodoItems->list->insertAtPosition(10); 632 522 $todo_list = $this->_getTodoList(); 633 523 $this->assertEqual($todo_list[10] , 'Task number 10'); 634 524 635 $TodoItems =& new AkTestTodoItem(33);525 $TodoItems =& new TodoItem(33); 636 526 $TodoItems->list->insertAtPosition(40); 637 527 $todo_list = $this->_getTodoList(); … … 646 536 function Test_of_incrementPositionsOnAllItems() 647 537 { 648 $TodoItems =& new AkTestTodoItem();538 $TodoItems =& new TodoItem(); 649 539 $TodoItems->transactionStart(); 650 540 … … 663 553 function Test_of_decrementPositionsOnHigherItems() 664 554 { 665 $TodoItems =& new AkTestTodoItem();555 $TodoItems =& new TodoItem(); 666 556 $TodoItems->transactionStart(); 667 557 … … 679 569 function _getTodoList($use_id_as_index = false) 680 570 { 681 $TodoItems = new AkTestTodoItem();571 $TodoItems = new TodoItem(); 682 572 $TodoItems = $TodoItems->find('all',array('order'=>'id ASC')); 683 573 $list = array(); … … 724 614 } 725 615 616 ak_test('AkActiveRecord_actsAsListTestCase',true); 726 617 727 618 ?> branches/kaste/framework/test/unit/lib/AkActiveRecord/AkActsAsNestedSet.php
r396 r407 1 1 <?php 2 3 2 4 3 defined('AK_TEST_DATABASE_ON') ? null : define('AK_TEST_DATABASE_ON', true); 5 4 require_once(dirname(__FILE__).'/../../../fixtures/config/config.php'); 6 7 require_once(AK_LIB_DIR.DS.'AkActiveRecord.php');8 5 9 6 if(!defined('AK_ACTIVE_RECORD_PROTECT_GET_RECURSION')){ … … 11 8 } 12 9 13 14 10 class test_AkActiveRecord_actsAsNestedSet extends AkUnitTest 15 11 { 16 /**/ 17 var $_testing_models_to_delete = array(); 18 var $_testing_model_databases_to_delete = array(); 19 20 function test_AkActiveRecord_actsAsNestedSet() 21 { 22 parent::UnitTestCase(); 23 $this->_createNewTestingModelDatabase('AkTestNestedCategory'); 24 $this->_createNewTestingModel('AkTestNestedCategory'); 25 } 26 27 function tearDown() 28 { 29 unset($_SESSION['__activeRecordColumnsSettingsCache']); 30 } 31 32 function _createNewTestingModel($test_model_name) 33 { 34 35 static $shutdown_called; 36 switch ($test_model_name) { 37 38 case 'AkTestNestedCategory': 39 $model_source = 40 '<?php 41 class AkTestNestedCategory extends AkActiveRecord 42 { 43 var $act_as = "nested_set"; 44 } 45 ?>'; 46 break; 47 48 default: 49 $model_source = '<?php class '.$test_model_name.' extends AkActiveRecord { } ?>'; 50 break; 51 } 52 53 $file_name = AkInflector::toModelFilename($test_model_name); 54 55 if(!Ak::file_put_contents($file_name,$model_source)){ 56 die('Ooops!, in order to perform this test, you must set your app/model permissions so this can script can create and delete files into/from it'); 57 } 58 if(!in_array($file_name, get_included_files()) && !class_exists($test_model_name)){ 59 include($file_name); 60 }else { 61 return false; 62 } 63 $this->_testing_models_to_delete[] = $file_name; 64 if(!isset($shutdown_called)){ 65 $shutdown_called = true; 66 register_shutdown_function(array(&$this,'_deleteTestingModels')); 67 } 68 return true; 69 } 70 71 function _deleteTestingModels() 72 { 73 foreach ($this->_testing_models_to_delete as $file){ 74 Ak::file_delete($file); 75 } 76 } 77 78 79 80 81 function _createNewTestingModelDatabase($test_model_name) 82 { 83 static $shutdown_called; 84 // Create a data dictionary object, using this connection 85 $db =& AK::db(); 86 //$db->debug = true; 87 $table_name = AkInflector::tableize($test_model_name); 88 if(in_array($table_name, (array)$db->MetaTables())){ 89 return false; 90 } 91 switch ($table_name) { 92 case 'ak_test_nested_categories': 93 $table = 94 array( 95 'table_name' => 'ak_test_nested_categories', 96 'fields' => 97 'id I AUTO KEY, 98 lft I(11), 99 rgt I(11), 100 parent_id I(11), 101 description C(250), 102 department C(25)', 103 'index_fileds' => 'id', 104 'table_options' => array('mysql' => 'TYPE=InnoDB', 'REPLACE') 105 ); 106 107 break; 108 default: 109 return false; 110 break; 111 } 112 113 $dict = NewDataDictionary($db->connection); 114 $sqlarray = $dict->CreateTableSQL($table['table_name'], $table['fields'], $table['table_options']); 115 $dict->ExecuteSQLArray($sqlarray); 116 if(isset($table['index_fileds'])){ 117 $sqlarray = $dict->CreateIndexSQL('idx_'.$table['table_name'], $table['table_name'], $table['index_fileds']); 118 $dict->ExecuteSQLArray($sqlarray); 119 } 120 121 $db->CreateSequence('seq_'.$table['table_name']); 122 123 $this->_testing_model_databases_to_delete[] = $table_name; 124 if(!isset($shutdown_called)){ 125 $shutdown_called = true; 126 register_shutdown_function(array(&$this,'_deleteTestingModelDatabases')); 127 } 128 //$db->debug = false; 129 return true; 130 } 131 132 function _deleteTestingModelDatabases() 133 { 134 $db =& AK::db(); 135 foreach ($this->_testing_model_databases_to_delete as $table_name){ 136 $db->Execute('DROP TABLE '.$table_name); 137 $db->DropSequence('seq_'.$table_name); 138 } 12 13 function test_start() 14 { 15 $this->installAndIncludeModels(array( 16 'NestedCategory'=>'id,lft int(11),rgt int(11),parent_id,description,department string(25)' 17 )); 139 18 } 140 19 141 20
