Changeset 2140
- Timestamp:
- 04/29/08 20:56:12 (7 months ago)
- Files:
-
- branches/release-36/t/driver-tests.pl (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/release-36/t/driver-tests.pl
r2133 r2140 56 56 57 57 # Test for existing table 58 ok(MT::Object->driver->dbd->ddl_class->column_defs('Foo'), "table mt_foo exists ");58 ok(MT::Object->driver->dbd->ddl_class->column_defs('Foo'), "table mt_foo exists after upgrade"); 59 59 # Test for non-existent table 60 ok(!MT::Object->driver->dbd->ddl_class->column_defs('Zot'), "table mt_zot does not exist ");60 ok(!MT::Object->driver->dbd->ddl_class->column_defs('Zot'), "table mt_zot does not exist after upgrade where undefined"); 61 61 62 62 ## Test creating object with new 63 63 ## test column access through column, then through AUTOLOAD 64 64 $foo[0] = Foo->new; 65 isa_ok($foo[0], 'Foo' );65 isa_ok($foo[0], 'Foo', 'New Foo'); 66 66 $foo[0]->column('name', 'foo'); 67 is($foo[0]->column('name'), 'foo', ' foo');67 is($foo[0]->column('name'), 'foo', 'Setting name field with column() persists through access'); 68 68 $foo[0]->name('foo'); 69 is($foo[0]->name, 'foo', ' foo');69 is($foo[0]->name, 'foo', 'Setting name field with mutator method persists through access'); 70 70 $foo[0]->status(2); 71 71 $foo[0]->text('bar'); 72 72 73 73 ## 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 74 ok($foo[0]->save, 'A Foo could be saved'); 75 is($foo[0]->id, 1, 'First Foo was given an id of 1, says accessor method'); 76 is($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 78 79 ## Test loading object using ID 79 80 $tmp = Foo->load($foo[0]->id); 81 isa_ok($tmp, 'Foo', 'Loaded Foo #1'); 82 is($tmp->id, $foo[0]->id, 'Loaded Foo #1 has 1 for an id'); 83 is($tmp->name, $foo[0]->name, 'Loaded Foo #1 has the same name as the saved Foo'); 84 is($tmp->text, $foo[0]->text, 'Loaded Foo #1 has the same text as the saved Foo'); 85 is($tmp->status, $foo[0]->status, 'Loaded Foo #1 has the same status as the saved Foo'); 86 is($tmp->created_on, $foo[0]->created_on, 'Loaded Foo #1 has the same created_on as the saved Foo'); 87 is(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 80 92 isa_ok($tmp, 'Foo'); 81 93 is($tmp->id, $foo[0]->id, 'id'); … … 86 98 is(length($tmp->created_on), 14, 'length is 14'); 87 99 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}); 91 102 isa_ok($tmp, 'Foo'); 92 103 is($tmp->id, $foo[0]->id, 'id'); … … 97 108 is(length($tmp->created_on), 14, 'length is 14'); 98 109 99 ## Test loading object using ID in a hash, w/other params100 $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 109 110 ## Test loading object using indexes 110 111 $tmp = Foo->load({ name => $foo[0]->name }); … … 118 119 is($tmp->id, $foo[0]->id, 'id'); 119 120 121 ## Sleep first so that they get different created_on timestamps. 122 # TODO: can we replace CORE::time to fake this? 120 123 sleep(2); 121 124 … … 146 149 ## Load all objects via iterator 147 150 my $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');151 isa_ok($iter, 'CODE', "load_iter() for all Foos returned an iterator"); 152 ok($tmp = $iter->(), 'Iterator for our two Foos had one object'); 153 is($tmp->id, $foo[0]->id, "All Foo iterator's first Foo was Foo #1"); 154 ok($tmp = $iter->(), 'Iterator for our two Foos had two objects'); 155 is($tmp->id, $foo[1]->id, "All Foo iterator's second Foo was Foo #2"); 156 ok(!$iter->(), 'Iterator for our two Foos did not have a third object'); 154 157 155 158 ## Load all objects with status == 1 via iterator 156 159 $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 160 isa_ok($iter, 'CODE', "load_iter() for status=1 Foos returned an iterator"); 161 ok($tmp = $iter->(), 'Iterator for our status=1 Foos had one object'); 162 is($tmp->id, $foo[1]->id, "Status=1 Foo iterator's first Foo was Foo #2"); 163 ok(!$iter->(), "Iterator for our status=1 Foos did not have a second object"); 164 165 # TODO: didn't we already do these tests? 162 166 ## Load using ID 163 167 $tmp = Foo->load($foo[1]->id); 164 isa_ok($iter, 'CODE'); 168 isa_ok($iter, 'CODE'); # TODO: useless test 165 169 is($foo[1]->id, $tmp->id, 'id'); 166 170 is($foo[1]->name, $tmp->name, 'name'); … … 169 173 ## Load using single-column index 170 174 $tmp = Foo->load({ name => $foo[1]->name, }); 171 isa_ok($iter, 'CODE'); 175 isa_ok($iter, 'CODE'); # TODO: useless test 172 176 is($foo[1]->id, $tmp->id, 'id'); 173 177 174 178 ## Load using non-existent ID (should fail) 175 179 $tmp = Foo->load(3); 176 ok(!$tmp, ' no Foo');180 ok(!$tmp, 'There is no Foo #3'); 177 181 178 182 ## Load using descending sort (newest)
