Changeset 2140

Show
Ignore:
Timestamp:
04/29/08 20:56:12 (7 months ago)
Author:
mpaschal
Message:

Better descriptions for these tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/release-36/t/driver-tests.pl

    r2133 r2140  
    5656 
    5757# Test for existing table 
    58 ok(MT::Object->driver->dbd->ddl_class->column_defs('Foo'), "table mt_foo exists"); 
     58ok(MT::Object->driver->dbd->ddl_class->column_defs('Foo'), "table mt_foo exists after upgrade"); 
    5959# Test for non-existent table 
    60 ok(!MT::Object->driver->dbd->ddl_class->column_defs('Zot'), "table mt_zot does not exist"); 
     60ok(!MT::Object->driver->dbd->ddl_class->column_defs('Zot'), "table mt_zot does not exist after upgrade where undefined"); 
    6161 
    6262## Test creating object with new 
    6363##     test column access through column, then through AUTOLOAD 
    6464$foo[0] = Foo->new; 
    65 isa_ok($foo[0], 'Foo'); 
     65isa_ok($foo[0], 'Foo', 'New Foo'); 
    6666$foo[0]->column('name', 'foo'); 
    67 is($foo[0]->column('name'), 'foo', 'foo'); 
     67is($foo[0]->column('name'), 'foo', 'Setting name field with column() persists through access'); 
    6868$foo[0]->name('foo'); 
    69 is($foo[0]->name, 'foo', 'foo'); 
     69is($foo[0]->name, 'foo', 'Setting name field with mutator method persists through access'); 
    7070$foo[0]->status(2); 
    7171$foo[0]->text('bar'); 
    7272 
    7373## Test saving created object 
    74 ok($foo[0]->save, 'saved'); 
    75 is($foo[0]->id, 1, 'id is 1'); 
    76 is($foo[0]->column('id'), $foo[0]->id, 'id'); 
    77  
     74ok($foo[0]->save, 'A Foo could be saved'); 
     75is($foo[0]->id, 1, 'First Foo was given an id of 1, says accessor method'); 
     76is($foo[0]->column('id'), $foo[0]->id, 'First Foo was given an id of 1, says column()'); 
     77 
     78# TODO: loop the tests for these three test loads 
    7879## Test loading object using ID 
    7980$tmp = Foo->load($foo[0]->id); 
     81isa_ok($tmp, 'Foo', 'Loaded Foo #1'); 
     82is($tmp->id, $foo[0]->id, 'Loaded Foo #1 has 1 for an id'); 
     83is($tmp->name, $foo[0]->name, 'Loaded Foo #1 has the same name as the saved Foo'); 
     84is($tmp->text, $foo[0]->text, 'Loaded Foo #1 has the same text as the saved Foo'); 
     85is($tmp->status, $foo[0]->status, 'Loaded Foo #1 has the same status as the saved Foo'); 
     86is($tmp->created_on, $foo[0]->created_on, 'Loaded Foo #1 has the same created_on as the saved Foo'); 
     87is(length($tmp->created_on), 14, "Loaded Foo's created_on is 14 characters"); 
     88 
     89## Test loading object using ID in a hash (new in MT 3.0) 
     90$tmp = Foo->load({id => $foo[0]->id}); 
     91 
    8092isa_ok($tmp, 'Foo'); 
    8193is($tmp->id, $foo[0]->id, 'id'); 
     
    8698is(length($tmp->created_on), 14, 'length is 14'); 
    8799 
    88 ## Test loading object using ID in a hash (new in MT 3.0) 
    89 $tmp = Foo->load({id => $foo[0]->id}); 
    90  
     100## Test loading object using ID in a hash, w/other params 
     101$tmp = Foo->load({id => $foo[0]->id, name => $foo[0]->name}); 
    91102isa_ok($tmp, 'Foo'); 
    92103is($tmp->id, $foo[0]->id, 'id'); 
     
    97108is(length($tmp->created_on), 14, 'length is 14'); 
    98109 
    99 ## Test loading object using ID in a hash, w/other params 
    100 $tmp = Foo->load({id => $foo[0]->id, name => $foo[0]->name}); 
    101 isa_ok($tmp, 'Foo'); 
    102 is($tmp->id, $foo[0]->id, 'id'); 
    103 is($tmp->name, $foo[0]->name, 'name'); 
    104 is($tmp->text, $foo[0]->text, 'text'); 
    105 is($tmp->status, $foo[0]->status, 'status'); 
    106 is($tmp->created_on, $foo[0]->created_on, 'created_on'); 
    107 is(length($tmp->created_on), 14, 'length is 14'); 
    108  
    109110## Test loading object using indexes 
    110111$tmp = Foo->load({ name => $foo[0]->name }); 
     
    118119is($tmp->id, $foo[0]->id, 'id'); 
    119120 
     121## Sleep first so that they get different created_on timestamps. 
     122# TODO: can we replace CORE::time to fake this? 
    120123sleep(2); 
    121124 
     
    146149## Load all objects via iterator 
    147150my $iter = Foo->load_iter(undef, { sort => 'created_on', direction => 'ascend' }); 
    148 isa_ok($iter, 'CODE'); 
    149 ok($tmp = $iter->(), 'set'); 
    150 is($tmp->id, $foo[0]->id, 'id'); 
    151 ok($tmp = $iter->(), 'set'); 
    152 is($tmp->id, $foo[1]->id, 'id'); 
    153 ok(!$iter->(), 'no $iter'); 
     151isa_ok($iter, 'CODE', "load_iter() for all Foos returned an iterator"); 
     152ok($tmp = $iter->(), 'Iterator for our two Foos had one object'); 
     153is($tmp->id, $foo[0]->id, "All Foo iterator's first Foo was Foo #1"); 
     154ok($tmp = $iter->(), 'Iterator for our two Foos had two objects'); 
     155is($tmp->id, $foo[1]->id, "All Foo iterator's second Foo was Foo #2"); 
     156ok(!$iter->(), 'Iterator for our two Foos did not have a third object'); 
    154157 
    155158## Load all objects with status == 1 via iterator 
    156159$iter = Foo->load_iter({ status => 1 }); 
    157 isa_ok($iter, 'CODE'); 
    158 ok($tmp = $iter->(), 'set'); 
    159 is($tmp->id, $foo[1]->id, 'id'); 
    160 ok(!$iter->(), 'no $iter'); 
    161  
     160isa_ok($iter, 'CODE', "load_iter() for status=1 Foos returned an iterator"); 
     161ok($tmp = $iter->(), 'Iterator for our status=1 Foos had one object'); 
     162is($tmp->id, $foo[1]->id, "Status=1 Foo iterator's first Foo was Foo #2"); 
     163ok(!$iter->(), "Iterator for our status=1 Foos did not have a second object"); 
     164 
     165# TODO: didn't we already do these tests? 
    162166## Load using ID 
    163167$tmp = Foo->load($foo[1]->id); 
    164 isa_ok($iter, 'CODE'); 
     168isa_ok($iter, 'CODE');  # TODO: useless test 
    165169is($foo[1]->id, $tmp->id, 'id'); 
    166170is($foo[1]->name, $tmp->name, 'name'); 
     
    169173## Load using single-column index 
    170174$tmp = Foo->load({ name => $foo[1]->name, }); 
    171 isa_ok($iter, 'CODE'); 
     175isa_ok($iter, 'CODE');  # TODO: useless test 
    172176is($foo[1]->id, $tmp->id, 'id'); 
    173177 
    174178## Load using non-existent ID (should fail) 
    175179$tmp = Foo->load(3); 
    176 ok(!$tmp, 'no Foo'); 
     180ok(!$tmp, 'There is no Foo #3'); 
    177181 
    178182## Load using descending sort (newest)