Changeset 407

Show
Ignore:
Timestamp:
10/16/07 16:51:35 (1 year ago)
Author:
kaste
Message:

refactored Active Record tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/kaste/framework/lib/AkActiveRecord/AkAssociation.php

    r285 r407  
    128128    { 
    129129        $this->Owner->_associationIds[$association_id]  = $associated_id; 
    130         $this->asssociated_ids[$association_id] = $associated_id; 
     130        $this->associated_ids[$association_id] = $associated_id; 
    131131    } 
    132132 
  • branches/kaste/framework/lib/AkActiveRecord/AkBelongsTo.php

    r329 r407  
    5757class AkBelongsTo extends AkAssociation 
    5858{ 
    59     var $asssociated_ids = array(); 
     59    var $associated_ids = array(); 
    6060 
    6161    function &addAssociated($association_id, $options = array()) 
  • branches/kaste/framework/lib/AkActiveRecord/AkHasAndBelongsToMany.php

    r396 r407  
    111111     */ 
    112112    var $JoinObject; 
    113     var $asssociated_ids = array(); 
     113    var $associated_ids = array(); 
    114114    var $association_id; 
    115115    var $_automatically_create_join_model_files = AK_HAS_AND_BELONGS_TO_MANY_CREATE_JOIN_MODEL_CLASSES; 
     
    501501                    } 
    502502                } 
    503                 unset($this->asssociated_ids[$record_id]); 
     503                unset($this->associated_ids[$record_id]); 
    504504                $this->_unsetAssociatedMemberId($records[$k]); 
    505505                if(!empty($options['after_remove']) && method_exists($this->Owner, $options['after_remove'])){ 
     
    521521        $object_id = $Member->getId(); 
    522522        if(!empty($object_id)){ 
    523             $this->asssociated_ids[$object_id] = $Member->__hasAndBelongsToManyMemberId; 
     523            $this->associated_ids[$object_id] = $Member->__hasAndBelongsToManyMemberId; 
    524524        } 
    525525    } 
     
    528528    { 
    529529        $id = $this->_getAssociatedMemberId($Member); 
    530         unset($this->asssociated_ids[$id]); 
     530        unset($this->associated_ids[$id]); 
    531531        unset($Member->__hasAndBelongsToManyMemberId); 
    532532    } 
     
    535535    { 
    536536        if(!empty($Member->__hasAndBelongsToManyMemberId)) { 
    537             return array_search($Member->__hasAndBelongsToManyMemberId, $this->asssociated_ids); 
     537            return array_search($Member->__hasAndBelongsToManyMemberId, $this->associated_ids); 
    538538        } 
    539539        return false; 
     
    543543    { 
    544544        $options = $this->getOptions($this->association_id); 
    545         if($options['unique'] && !$Member->isNewRecord() && isset($this->asssociated_ids[$Member->getId()])){ 
     545        if($options['unique'] && !$Member->isNewRecord() && isset($this->associated_ids[$Member->getId()])){ 
    546546            return true; 
    547547        } 
  • branches/kaste/framework/lib/AkActiveRecord/AkHasMany.php

    r328 r407  
    8080class AkHasMany extends AkAssociation 
    8181{ 
    82     var $asssociated_ids = array(); 
     82    var $associated_ids = array(); 
    8383    var $association_id; 
    8484 
     
    406406        $object_id = method_exists($Member,'getId') ? $Member->getId() : null; 
    407407        if(!empty($object_id)){ 
    408             $this->asssociated_ids[$object_id] = $Member->__hasManyMemberId; 
     408            $this->associated_ids[$object_id] = $Member->__hasManyMemberId; 
    409409        } 
    410410    } 
     
    413413    { 
    414414        $id = $this->_getAssociatedMemberId($Member); 
    415         unset($this->asssociated_ids[$id]); 
     415        unset($this->associated_ids[$id]); 
    416416        unset($Member->__hasManyMemberId); 
    417417    } 
     
    420420    { 
    421421        if(!empty($Member->__hasManyMemberId)) { 
    422             return array_search($Member->__hasManyMemberId, $this->asssociated_ids); 
     422            return array_search($Member->__hasManyMemberId, $this->associated_ids); 
    423423        } 
    424424        return false; 
  • branches/kaste/framework/lib/AkActiveRecord/AkHasOne.php

    r285 r407  
    5555class AkHasOne extends AkAssociation 
    5656{ 
    57     var $asssociated_ids = array(); 
     57    var $associated_ids = array(); 
    5858 
    5959    function &addAssociated($association_id, $options = array()) 
     
    112112    function getAssociatedId($association_id) 
    113113    { 
    114         return isset($this->asssociated_ids[$association_id]) ? $this->asssociated_ids[$association_id] : false; 
     114        return isset($this->associated_ids[$association_id]) ? $this->associated_ids[$association_id] : false; 
    115115    } 
    116116 
  • branches/kaste/framework/lib/AkActiveRecord/AkObserver.php

    r366 r407  
    132132        { 
    133133            $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();"); 
    136137            $this->observe(&$model); 
    137138        } 
  • branches/kaste/framework/lib/AkInstaller.php

    r396 r407  
    277277        ); 
    278278        $table_options = array_merge($default_table_options, $table_options); 
    279  
     279         
    280280        $column_string = $this->_getColumnsAsAdodbDataDictionaryString($column_options['columns']); 
    281          
    282281        $result = $this->data_dictionary->ExecuteSQLArray($this->data_dictionary->ChangeTableSQL($table_name, str_replace(array(' UNIQUE', ' INDEX', ' FULLTEXT', ' HASH'), '', $column_string), $table_options)); 
    283282 
     
    389388        $columns = $this->_setColumnDefaults($columns); 
    390389        $this->_ensureColumnNameCompatibility($columns); 
     390 
    391391        $equivalences = array( 
    392392        '/ ((limit|max|length) ?= ?)([0-9]+)([ \n\r,]+)/'=> ' (\3) ', 
    393393        '/([ \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', 
    395395        '/([ \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', 
    404404        '/ NOT( |_)?NULL/i'=> ' NOTNULL', 
    405405        '/ AUTO( |_)?INCREMENT/i'=> ' AUTO ', 
  • branches/kaste/framework/test/unit/lib/AkActiveRecord/AkActsAsList.php

    r396 r407  
    11<?php 
     2 
     3defined('AK_TEST_DATABASE_ON') ? null : define('AK_TEST_DATABASE_ON', true); 
     4require_once(dirname(__FILE__).'/../../../fixtures/config/config.php'); 
     5 
     6if(!defined('AK_ACTIVE_RECORD_PROTECT_GET_RECURSION')){ 
     7    define('AK_ACTIVE_RECORD_PROTECT_GET_RECURSION', false); 
     8} 
    29 
    310class AkActiveRecord_actsAsListTestCase extends  AkUnitTest 
    411{ 
    5     /**/ 
    6     var $_testing_models_to_delete = array(); 
    7     var $_testing_model_databases_to_delete = array(); 
    812 
    913    function test_AkActiveRecord_actsAsList() 
    1014    { 
    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        )); 
    12818    } 
    12919 
    13020    function Test_of_actsAsList_instatiation() 
    13121    { 
    132         $TodoItems =& new AkTestTodoItem(); 
     22        $TodoItems =& new TodoItem(); 
    13323        $this->assertEqual($TodoItems->actsLike(), 'active record,list'); 
    13424        $this->assertFalse(empty($TodoItems->list->column)); 
    13525        $this->assertTrue(empty($TodoItems->list->scope)); 
    13626 
    137         $TodoItems =& new AkTestTodoItem(); 
     27        $TodoItems =& new TodoItem(); 
    13828        $this->assertErrorPattern('/not_available/',$TodoItems->actsAs('list', array('column'=>'not_available'))); 
    13929 
     
    14434    function Test_of_Test_of___construct() 
    14535    { 
    146         $TodoItems =& new AkTestTodoItem(); 
     36        $TodoItems =& new TodoItem(); 
    14737        $TodoItems->actsAs('list', 
    14838        array( 
     
    15747    function Test_of__ensureIsActiveRecordInstance() 
    15848    { 
    159         $TodoItems =& new AkTestTodoItem(); 
     49        $TodoItems =& new TodoItem(); 
    16050        $Object =& new AkObject(); 
    16151        $this->assertErrorPattern('/is not an active record/',$TodoItems->list->_ensureIsActiveRecordInstance(&$Object)); 
     
    16454    function Test_of_getType() 
    16555    { 
    166         $TodoItems =& new AkTestTodoItem(); 
     56        $TodoItems =& new TodoItem(); 
    16757        $this->assertEqual($TodoItems->list->getType(), 'list'); 
    16858    } 
     
    17060    function Test_of_getScopeCondition_and_setScopeCondition() 
    17161    { 
    172         $TodoItems =& new AkTestTodoItem(); 
     62        $TodoItems =& new TodoItem(); 
    17363        $this->assertEqual($TodoItems->list->getScopeCondition(), ($TodoItems->_db->type() == 'postgre') ? 'true' : '1'); 
    17464        $TodoItems->list->setScopeCondition('true'); 
     
    17868    function Test_of_getBottomItem_1() 
    17969    { 
    180         $TodoItems =& new AkTestTodoItem(); 
     70        $TodoItems =& new TodoItem(); 
    18171        $this->assertFalse($TodoItems->list->getBottomItem()); 
    18272    } 
     
    18474    function Test_of_getBottomPosition_1() 
    18575    { 
    186         $TodoItems =& new AkTestTodoItem(); 
     76        $TodoItems =& new TodoItem(); 
    18777        $this->assertIdentical($TodoItems->list->getBottomPosition(), 0); 
    18878    } 
     
    19080    function Test_of__addToBottom_1() 
    19181    { 
    192         $TodoItems =& new AkTestTodoItem(); 
     82        $TodoItems =& new TodoItem(); 
    19383        $TodoItems->List->_addToBottom(); 
    19484        $this->assertIdentical($TodoItems->position, 1); 
     
    19888    function Test_of_beforeCreate() 
    19989    { 
    200         $TodoItems =& new AkTestTodoItem(); 
     90        $TodoItems =& new TodoItem(); 
    20191        $position = $TodoItems->getAttribute('position'); 
    20292        $TodoItems->List->beforeCreate($TodoItems); 
     
    20797    function Test_of_getBottomItem_2() 
    20898    { 
    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))); 
    210100        $this->assertPattern('/list/',$TodoItems->actsLike()); 
    211101        $this->assertTrue($TodoItems->isNewRecord()); 
     
    216106        $this->assertEqual($getBottomItem->toString(), $TodoItems->toString()); 
    217107 
    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))); 
    219109        $this->assertTrue($TodoItems->isNewRecord()); 
    220110        $this->assertTrue($TodoItems->save()); 
     
    223113        $this->assertEqual($getBottomItem->toString(), $TodoItems->toString()); 
    224114 
    225         $TodoItems =& new AkTestTodoItem(1); 
     115        $TodoItems =& new TodoItem(1); 
    226116        $this->assertTrue($getBottomItem = $TodoItems->List->getBottomItem(2)); 
    227117        $this->assertEqual($getBottomItem->toString(), $TodoItems->toString()); 
     
    231121    function Test_of_getBottomPosition_2() 
    232122    { 
    233         $TodoItems =& new AkTestTodoItem(); 
     123        $TodoItems =& new TodoItem(); 
    234124        $this->assertEqual($TodoItems->list->getBottomPosition(), 2); 
    235125 
     
    240130    function Test_of__addToBottom_2() 
    241131    { 
    242         $TodoItems =& new AkTestTodoItem(); 
     132        $TodoItems =& new TodoItem(); 
    243133        $TodoItems->list->_addToBottom(); 
    244134        $this->assertIdentical($TodoItems->position, 3); 
     
    249139    function Test_of_isInList() 
    250140    { 
    251         $TodoItems =& new AkTestTodoItem(); 
     141        $TodoItems =& new TodoItem(); 
    252142        $this->assertFalse($TodoItems->list->isInList()); 
    253143 
    254         $TodoItems =& new AkTestTodoItem(1); 
     144        $TodoItems =& new TodoItem(1); 
    255145        $this->assertTrue($TodoItems->list->isInList()); 
    256146    } 
     
    261151        for ($i = 0; $i <= 30; $i++){ 
    262152            $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); 
    264154            $this->assertTrue($TodoTask->save()); 
    265155            $this->assertTrue(($TodoTask->task == $attributes['task']) && $TodoTask->due_time == $attributes['due_time']); 
     
    270160    function Test_of_decrementPositionsOnLowerItems() 
    271161    { 
    272         $TodoItems =& new AkTestTodoItem(); 
     162        $TodoItems =& new TodoItem(); 
    273163        $TodoItems->transactionStart(); 
    274164        $this->assertFalse($TodoItems->list->decrementPositionsOnLowerItems()); 
     
    276166        $todo_list = $this->_getTodoList(); 
    277167        $this->assertEqual($todo_list[10] , 'Task number 10'); 
    278         $TodoItems =& new AkTestTodoItem(10); 
     168        $TodoItems =& new TodoItem(10); 
    279169 
    280170        $this->assertTrue($TodoItems->list->decrementPositionsOnLowerItems()); 
     
    293183    function Test_of_removeFromList() 
    294184    { 
    295         $TodoItems =& new AkTestTodoItem(10); 
     185        $TodoItems =& new TodoItem(10); 
    296186 
    297187        $TodoItems->transactionStart(); 
     
    307197    function Test_of_afterDestroy_and_beforeDestroy() 
    308198    { 
    309         $TodoItems =& new AkTestTodoItem(10); 
     199        $TodoItems =& new TodoItem(10); 
    310200 
    311201        $TodoItems->transactionStart(); 
     
    335225    function Test_of_getLowerItem() 
    336226    { 
    337         $TodoItems =& new AkTestTodoItem(); 
     227        $TodoItems =& new TodoItem(); 
    338228        $this->assertFalse($TodoItems->list->getLowerItem()); 
    339229        $TodoItem = $TodoItems->find(10); 
     
    346236 
    347237 
    348         $TodoItems =& new AkTestTodoItem(); 
     238        $TodoItems =& new TodoItem(); 
    349239        $TodoItems->transactionStart(); 
    350240        $this->assertTrue($TodoItems->deleteAll()); 
     
    358248    function Test_of_decrementPosition() 
    359249    { 
    360         $TodoItems =& new AkTestTodoItem(10); 
     250        $TodoItems =& new TodoItem(10); 
    361251        $TodoItems->transactionStart(); 
    362252 
     
    369259    function Test_of_incrementPosition() 
    370260    { 
    371         $TodoItems =& new AkTestTodoItem(10); 
     261        $TodoItems =& new TodoItem(10); 
    372262        $TodoItems->transactionStart(); 
    373263 
     
    380270    function Test_of_moveLower() 
    381271    { 
    382         $TodoItems =& new AkTestTodoItem(); 
     272        $TodoItems =& new TodoItem(); 
    383273        $this->assertFalse($TodoItems->list->moveLower()); 
    384274 
     
    387277        $this->assertEqual($todo_list[11] , 'Task number 11'); 
    388278 
    389         $TodoItems =& new AkTestTodoItem(10); 
     279        $TodoItems =& new TodoItem(10); 
    390280        $TodoItems->transactionStart(); 
    391281 
     
    396286        $this->assertEqual($todo_list[11] , 'Task number 10'); 
    397287 
    398         $TodoItems =& new AkTestTodoItem(33); 
     288        $TodoItems =& new TodoItem(33); 
    399289        $this->assertFalse($TodoItems->list->moveLower()); 
    400290 
     
    406296    function Test_of_getHigherItem() 
    407297    { 
    408         $TodoItems =& new AkTestTodoItem(); 
     298        $TodoItems =& new TodoItem(); 
    409299        $this->assertFalse($TodoItems->list->getHigherItem()); 
    410300 
     
    417307 
    418308 
    419         $TodoItems =& new AkTestTodoItem(); 
     309        $TodoItems =& new TodoItem(); 
    420310        $TodoItems->transactionStart(); 
    421311        $this->assertTrue($TodoItems->deleteAll()); 
     
    430320    function Test_of_moveHigher() 
    431321    { 
    432         $TodoItems =& new AkTestTodoItem(); 
     322        $TodoItems =& new TodoItem(); 
    433323        $this->assertFalse($TodoItems->list->moveHigher()); 
    434324 
     
    437327        $this->assertEqual($todo_list[10] , 'Task number 10'); 
    438328 
    439         $TodoItems =& new AkTestTodoItem(10); 
     329        $TodoItems =& new TodoItem(10); 
    440330        $TodoItems->transactionStart(); 
    441331 
     
    446336        $this->assertEqual($todo_list[10] , 'Task number 9'); 
    447337 
    448         $TodoItems =& new AkTestTodoItem(1); 
     338        $TodoItems =& new TodoItem(1); 
    449339        $this->assertFalse($TodoItems->list->moveHigher()); 
    450340 
     
    458348        $this->assertEqual($todo_list[10] , 'Task number 10'); 
    459349 
    460         $TodoItems =& new AkTestTodoItem(10); 
     350        $TodoItems =& new TodoItem(10); 
    461351        $TodoItems->transactionStart(); 
    462352 
     
    475365        $this->assertEqual($todo_list[10] , 'Task number 10'); 
    476366 
    477         $TodoItems =& new AkTestTodoItem(); 
     367        $TodoItems =& new TodoItem(); 
    478368        $this->assertFalse($TodoItems->list->moveToBottom()); 
    479369 
    480         $TodoItems =& new AkTestTodoItem(10); 
     370        $TodoItems =& new TodoItem(10); 
    481371        $TodoItems->transactionStart(); 
    482372 
     
    491381        $TodoItems->transactionComplete(); 
    492382 
    493         $TodoItems =& new AkTestTodoItem(33); 
     383        $TodoItems =& new TodoItem(33); 
    494384        $TodoItems->transactionStart(); 
    495385 
     
    505395    function Test_of_incrementPositionsOnHigherItems() 
    506396    { 
    507         $TodoItems =& new AkTestTodoItem(); 
     397        $TodoItems =& new TodoItem(); 
    508398        $TodoItems->transactionStart(); 
    509399        $this->assertFalse($TodoItems->list->incrementPositionsOnHigherItems()); 
     
    511401        $todo_list = $this->_getTodoList(); 
    512402        $this->assertEqual($todo_list[10] , 'Task number 10'); 
    513         $TodoItems =& new AkTestTodoItem(10); 
     403        $TodoItems =& new TodoItem(10); 
    514404        $this->assertTrue($TodoItems->list->incrementPositionsOnHigherItems()); 
    515405        $todo_list = $this->_getTodoList(); 
     
    523413    function Test_of_assumeTopPosition() 
    524414    { 
    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); 
    531421        $this->assertTrue($TodoItems->list->assumeTopPosition()); 
    532422        $todo_list = $this->_getTodoList(); 
     
    541431        $this->assertEqual($todo_list[10] , 'Task number 10'); 
    542432 
    543         $TodoItems =& new AkTestTodoItem(); 
     433        $TodoItems =& new TodoItem(); 
    544434        $this->assertFalse($TodoItems->list->moveToTop()); 
    545435 
    546         $TodoItems =& new AkTestTodoItem(10); 
     436        $TodoItems =& new TodoItem(10); 
    547437        $TodoItems->transactionStart(); 
    548438 
     
    557447        $TodoItems->transactionComplete(); 
    558448 
    559         $TodoItems =& new AkTestTodoItem(1); 
     449        $TodoItems =& new TodoItem(1); 
    560450        $TodoItems->transactionStart(); 
    561451 
     
    571461    function Test_of_isFirst() 
    572462    { 
    573         $TodoItems =& new AkTestTodoItem(1); 
     463        $TodoItems =& new TodoItem(1); 
    574464 
    575465        $this->assertTrue($TodoItems->list->isFirst()); 
    576466 
    577         $TodoItems =& new AkTestTodoItem(2); 
     467        $TodoItems =& new TodoItem(2); 
    578468        $this->assertFalse($TodoItems->list->isFirst()); 
    579469 
    580         $TodoItems =& new AkTestTodoItem(); 
     470        $TodoItems =& new TodoItem(); 
    581471        $this->assertFalse($TodoItems->list->isFirst()); 
    582472    } 
     
    585475    function Test_of_isLast() 
    586476    { 
    587         $TodoItems =& new AkTestTodoItem(33); 
     477        $TodoItems =& new TodoItem(33); 
    588478        $this->assertTrue($TodoItems->list->isLast()); 
    589479 
    590         $TodoItems =& new AkTestTodoItem(1); 
     480        $TodoItems =& new TodoItem(1); 
    591481        $this->assertFalse($TodoItems->list->isLast()); 
    592482 
    593         $TodoItems =& new AkTestTodoItem(); 
     483        $TodoItems =& new TodoItem(); 
    594484        $this->assertFalse($TodoItems->list->isLast()); 
    595485    } 
     
    598488    function Test_of_incrementPositionsOnLowerItems() 
    599489    { 
    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); 
    606496        $this->assertTrue($TodoItems->list->incrementPositionsOnLowerItems(10)); 
    607497        $todo_list = $this->_getTodoList(); 
     
    615505    function Test_of_insertAtPosition() 
    616506    { 
    617         $TodoItems =& new AkTestTodoItem(10); 
     507        $TodoItems =& new TodoItem(10); 
    618508        $TodoItems->transactionStart(); 
    619509 
     
    623513 
    624514 
    625         $TodoItems =& new AkTestTodoItem('task->','ship new InmoEasy version'); 
     515        $TodoItems =& new TodoItem('task->','ship new InmoEasy version'); 
    626516        $TodoItems->list->insertAtPosition(1); 
    627517        $todo_list = $this->_getTodoList(); 
    628518        $this->assertEqual($todo_list[1] , 'ship new InmoEasy version'); 
    629519 
    630         $TodoItems =& new AkTestTodoItem(10); 
     520        $TodoItems =& new TodoItem(10); 
    631521        $TodoItems->list->insertAtPosition(10); 
    632522        $todo_list = $this->_getTodoList(); 
    633523        $this->assertEqual($todo_list[10] , 'Task number 10'); 
    634524 
    635         $TodoItems =& new AkTestTodoItem(33); 
     525        $TodoItems =& new TodoItem(33); 
    636526        $TodoItems->list->insertAtPosition(40); 
    637527        $todo_list = $this->_getTodoList(); 
     
    646536    function Test_of_incrementPositionsOnAllItems() 
    647537    { 
    648         $TodoItems =& new AkTestTodoItem(); 
     538        $TodoItems =& new TodoItem(); 
    649539        $TodoItems->transactionStart(); 
    650540 
     
    663553    function Test_of_decrementPositionsOnHigherItems() 
    664554    { 
    665         $TodoItems =& new AkTestTodoItem(); 
     555        $TodoItems =& new TodoItem(); 
    666556        $TodoItems->transactionStart(); 
    667557 
     
    679569    function _getTodoList($use_id_as_index = false) 
    680570    { 
    681         $TodoItems = new AkTestTodoItem(); 
     571        $TodoItems = new TodoItem(); 
    682572        $TodoItems = $TodoItems->find('all',array('order'=>'id ASC')); 
    683573        $list = array(); 
     
    724614} 
    725615 
     616ak_test('AkActiveRecord_actsAsListTestCase',true); 
    726617 
    727618?> 
  • branches/kaste/framework/test/unit/lib/AkActiveRecord/AkActsAsNestedSet.php

    r396 r407  
    11<?php 
    2  
    32 
    43defined('AK_TEST_DATABASE_ON') ? null : define('AK_TEST_DATABASE_ON', true); 
    54require_once(dirname(__FILE__).'/../../../fixtures/config/config.php'); 
    6  
    7 require_once(AK_LIB_DIR.DS.'AkActiveRecord.php'); 
    85 
    96if(!defined('AK_ACTIVE_RECORD_PROTECT_GET_RECURSION')){ 
     
    118} 
    129 
    13  
    1410class test_AkActiveRecord_actsAsNestedSet extends  AkUnitTest 
    1511{ 
    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            )); 
    13918    } 
    14019 
    14120