| 1 | package MT::Test; |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | # Handle cwd = MT_DIR, MT_DIR/t |
|---|
| 5 | use lib 't/lib', 'extlib', 'lib', '../lib', '../extlib'; |
|---|
| 6 | use File::Spec; |
|---|
| 7 | use MT; |
|---|
| 8 | |
|---|
| 9 | BEGIN { |
|---|
| 10 | # if MT_HOME is not set, set it |
|---|
| 11 | unless ($ENV{MT_HOME}) { |
|---|
| 12 | require Cwd; |
|---|
| 13 | my $cwd = Cwd::getcwd(); |
|---|
| 14 | my @pieces = File::Spec->splitdir($cwd); |
|---|
| 15 | pop @pieces unless -d 't'; |
|---|
| 16 | $ENV{MT_HOME} = File::Spec->catdir(@pieces); |
|---|
| 17 | } |
|---|
| 18 | # if MT_CONFIG is not set, set it |
|---|
| 19 | if ($ENV{MT_CONFIG}) { |
|---|
| 20 | if (!File::Spec->file_name_is_absolute($ENV{MT_CONFIG})) { |
|---|
| 21 | $ENV{MT_CONFIG} = File::Spec->catfile($ENV{MT_HOME}, "t", $ENV{MT_CONFIG}); |
|---|
| 22 | } |
|---|
| 23 | } else { |
|---|
| 24 | $ENV{MT_CONFIG} = File::Spec->catfile($ENV{MT_HOME}, "t", "mt.cfg"); |
|---|
| 25 | } |
|---|
| 26 | chdir $ENV{MT_HOME}; |
|---|
| 27 | my $ds_dir = File::Spec->catdir($ENV{MT_HOME}, "t", "db"); |
|---|
| 28 | if (!-d $ds_dir) { |
|---|
| 29 | mkdir $ds_dir; |
|---|
| 30 | } |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | sub import { |
|---|
| 34 | my $pkg = shift; |
|---|
| 35 | foreach my $opt (@_) { |
|---|
| 36 | $pkg->init_db() if $opt eq ':db'; |
|---|
| 37 | $pkg->init_test_db() if $opt eq ':testdb'; |
|---|
| 38 | $pkg->sample_data() if $opt eq ':data'; |
|---|
| 39 | } |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | sub init_test_db { |
|---|
| 43 | my $pkg = shift; |
|---|
| 44 | # This is a bit of MT::Upgrade magic to prevent the full |
|---|
| 45 | # instantiation of the MT schema. We force the classes list |
|---|
| 46 | # to only contain the test 'Foo', 'Bar' classes and neuter |
|---|
| 47 | # the |
|---|
| 48 | require MT::Upgrade; |
|---|
| 49 | # Add our test 'Foo' and 'Bar' classes to the list of |
|---|
| 50 | # object classes to install. |
|---|
| 51 | %MT::Upgrade::classes = (foo=>'Foo',bar=>'Bar'); |
|---|
| 52 | #MT::Upgrade->register_class(['Foo', 'Bar']); |
|---|
| 53 | MT->instance; |
|---|
| 54 | MT->registry->{object_types}->{foo} = 'Foo'; |
|---|
| 55 | MT->registry->{object_types}->{bar} = 'Bar'; |
|---|
| 56 | |
|---|
| 57 | # Replace the standard seed_database/install_template functions |
|---|
| 58 | # with stubs since we're not creating a full schema. |
|---|
| 59 | MT::Upgrade->register_upgrade_function({ |
|---|
| 60 | core_seed_database => { code => sub { 1 } }, |
|---|
| 61 | core_upgrade_templates => { code => sub { 1 } }, |
|---|
| 62 | core_upgrade_templates => { code => sub { 1 } }, |
|---|
| 63 | core_finish => { code => sub { 1 } }, |
|---|
| 64 | }); |
|---|
| 65 | $pkg->init_db(); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | sub init_db { |
|---|
| 69 | my $pkg = shift; |
|---|
| 70 | my ($cfg) = @_; |
|---|
| 71 | |
|---|
| 72 | my $mt = MT->instance($cfg ? (Config => $cfg) : ()) |
|---|
| 73 | or die "No MT object " . MT->errstr; |
|---|
| 74 | |
|---|
| 75 | my $types = MT->registry('object_types'); |
|---|
| 76 | my @classes = map { $types->{$_} } grep { $_ !~ /\./ } keys %$types; |
|---|
| 77 | foreach my $class (@classes) { |
|---|
| 78 | if (ref($class) eq 'ARRAY') { |
|---|
| 79 | next; #TODO for now - it won't hurt when we do driver-tests. |
|---|
| 80 | } |
|---|
| 81 | else { |
|---|
| 82 | eval 'require '.$class or die $@; |
|---|
| 83 | } |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | # Clear existing database tables |
|---|
| 87 | my $driver = MT::Object->driver(); |
|---|
| 88 | foreach my $class (@classes) { |
|---|
| 89 | if (ref($class) eq 'ARRAY') { |
|---|
| 90 | next; #TODO for now - it won't hurt when we do driver-tests. |
|---|
| 91 | } |
|---|
| 92 | else { |
|---|
| 93 | if ($driver->dbd->ddl_class->table_exists($class)) { |
|---|
| 94 | $driver->sql( |
|---|
| 95 | $driver->dbd->ddl_class->drop_table_sql($class), |
|---|
| 96 | ); |
|---|
| 97 | $driver->dbd->ddl_class->drop_sequence($class), |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | require MT::Upgrade; |
|---|
| 103 | # Initialize the MT database |
|---|
| 104 | MT::Upgrade->do_upgrade( |
|---|
| 105 | Install => 1, |
|---|
| 106 | App => __PACKAGE__, |
|---|
| 107 | User => {}, |
|---|
| 108 | Blog => {} |
|---|
| 109 | ); |
|---|
| 110 | eval { |
|---|
| 111 | MT::Entry->remove; |
|---|
| 112 | MT::Comment->remove; |
|---|
| 113 | }; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | sub progress {} |
|---|
| 117 | sub error { |
|---|
| 118 | my ($x, $msg) = @_; |
|---|
| 119 | print "ERROR: $msg\n"; |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | sub sample_data { |
|---|
| 123 | my $pkg = shift; |
|---|
| 124 | my $blog = MT::Blog->new(); |
|---|
| 125 | $blog->set_values({ |
|---|
| 126 | name => 'none', |
|---|
| 127 | site_url => 'http://narnia.na/nana/', |
|---|
| 128 | archive_url => 'http://narnia.na/nana/archives/', |
|---|
| 129 | site_path => 't/site/', |
|---|
| 130 | archive_path => 't/site/archives/', |
|---|
| 131 | archive_type=>'Individual,Monthly,Weekly,Daily,Category,Page', |
|---|
| 132 | archive_type_preferred => 'Individual', |
|---|
| 133 | description => "Narnia None Test Blog", |
|---|
| 134 | custom_dynamic_templates => 'custom', |
|---|
| 135 | convert_paras => 1, |
|---|
| 136 | allow_reg_comments => 1, |
|---|
| 137 | allow_unreg_comments => 0, |
|---|
| 138 | allow_pings => 1, |
|---|
| 139 | sort_order_posts => 'descend', |
|---|
| 140 | sort_order_comments => 'ascend', |
|---|
| 141 | remote_auth_token => 'token', |
|---|
| 142 | convert_paras_comments => 1, |
|---|
| 143 | google_api_key => 'r9Vj5K8PsjEu+OMsNZ/EEKjWmbCeQAv1', |
|---|
| 144 | cc_license => 'by-nc-sa http://creativecommons.org/licenses/by-nc-sa/2.0/ http://creativecommons.org/images/public/somerights20.gif', |
|---|
| 145 | server_offset => '-3.5', |
|---|
| 146 | children_modified_on => '20000101000000', |
|---|
| 147 | language => 'en_us', |
|---|
| 148 | file_extension => 'html', |
|---|
| 149 | }); |
|---|
| 150 | $blog->id(1); |
|---|
| 151 | $blog->commenter_authenticators('enabled_TypeKey'); |
|---|
| 152 | $blog->save() or die "Couldn't save blog 1: ". $blog->errstr; |
|---|
| 153 | |
|---|
| 154 | require MT::Entry; |
|---|
| 155 | require MT::Author; |
|---|
| 156 | my $chuckd = MT::Author->new(); |
|---|
| 157 | $chuckd->set_values({ |
|---|
| 158 | name => 'Chuck D', |
|---|
| 159 | nickname => 'Chucky Dee', |
|---|
| 160 | email => 'chuckd@example.com', |
|---|
| 161 | url => 'http://chuckd.com/', |
|---|
| 162 | api_password => 'seecret', |
|---|
| 163 | auth_type => 'MT', |
|---|
| 164 | }); |
|---|
| 165 | $chuckd->set_password("bass"); |
|---|
| 166 | $chuckd->type(MT::Author::AUTHOR()); |
|---|
| 167 | $chuckd->id(2); |
|---|
| 168 | $chuckd->is_superuser(1); |
|---|
| 169 | $chuckd->save() |
|---|
| 170 | or die "Couldn't save author record 2: " . $chuckd->errstr; |
|---|
| 171 | |
|---|
| 172 | my $bobd = MT::Author->new(); |
|---|
| 173 | $bobd->set_values({ |
|---|
| 174 | name => 'Bob D', |
|---|
| 175 | nickname => 'Dylan', |
|---|
| 176 | email => 'bobd@example.com', |
|---|
| 177 | auth_type => 'MT', |
|---|
| 178 | }); |
|---|
| 179 | $bobd->set_password("flute"); |
|---|
| 180 | $bobd->type(MT::Author::AUTHOR()); |
|---|
| 181 | $bobd->id(3); |
|---|
| 182 | $bobd->save() or die "Couldn't save author record 3: " . $bobd->errstr; |
|---|
| 183 | |
|---|
| 184 | my $johnd = MT::Author->new(); |
|---|
| 185 | $johnd->set_values({ |
|---|
| 186 | name => 'John Doe', |
|---|
| 187 | nickname => 'John Doe', |
|---|
| 188 | email => 'jdoe@doe.com', |
|---|
| 189 | auth_type => 'TypeKey', |
|---|
| 190 | }); |
|---|
| 191 | $johnd->type(MT::Author::COMMENTER()); |
|---|
| 192 | $johnd->password('(none)'); |
|---|
| 193 | $johnd->id(4); |
|---|
| 194 | $johnd->save() or die "Couldn't save author record 4: " . $johnd->errstr; |
|---|
| 195 | |
|---|
| 196 | my $hiro = MT::Author->new(); |
|---|
| 197 | $hiro->set_values({ |
|---|
| 198 | name => 'Hiro Nakamura', |
|---|
| 199 | nickname => 'Hiro', |
|---|
| 200 | email => 'hiro@heroes.com', |
|---|
| 201 | auth_type => 'MT', |
|---|
| 202 | }); |
|---|
| 203 | $hiro->type(MT::Author::AUTHOR()); |
|---|
| 204 | $hiro->password('time'); |
|---|
| 205 | $hiro->id(5); |
|---|
| 206 | $hiro->status(2); |
|---|
| 207 | $hiro->save() or die "Couldn't save author record 5: " . $hiro->errstr; |
|---|
| 208 | |
|---|
| 209 | require MT::Association; |
|---|
| 210 | my $assoc = MT::Association->new(); |
|---|
| 211 | $assoc->author_id($chuckd->id); |
|---|
| 212 | $assoc->blog_id(1); |
|---|
| 213 | $assoc->role_id(3); |
|---|
| 214 | $assoc->type(1); |
|---|
| 215 | $assoc->save(); |
|---|
| 216 | |
|---|
| 217 | $assoc = MT::Association->new(); |
|---|
| 218 | $assoc->author_id($bobd->id); |
|---|
| 219 | $assoc->blog_id(1); |
|---|
| 220 | $assoc->role_id(4); |
|---|
| 221 | $assoc->type(1); |
|---|
| 222 | $assoc->save(); |
|---|
| 223 | |
|---|
| 224 | $assoc = MT::Association->new(); |
|---|
| 225 | $assoc->author_id($hiro->id); |
|---|
| 226 | $assoc->blog_id(1); |
|---|
| 227 | $assoc->role_id(3); |
|---|
| 228 | $assoc->type(1); |
|---|
| 229 | $assoc->save(); |
|---|
| 230 | |
|---|
| 231 | # set permission record for johnd commenter on blog 1 |
|---|
| 232 | $johnd->approve(1); |
|---|
| 233 | |
|---|
| 234 | my $entry = MT::Entry->load(1); |
|---|
| 235 | if (!$entry) { |
|---|
| 236 | $entry = MT::Entry->new(); |
|---|
| 237 | $entry->set_values({ |
|---|
| 238 | blog_id => 1, |
|---|
| 239 | title => 'A Rainy Day', |
|---|
| 240 | text => 'On a drizzly day last weekend,', |
|---|
| 241 | text_more => 'I took my grandpa for a walk.', |
|---|
| 242 | excerpt => 'A story of a stroll.', |
|---|
| 243 | keywords => 'keywords', |
|---|
| 244 | created_on => '19780131074500', |
|---|
| 245 | authored_on => '19780131074500', |
|---|
| 246 | modified_on => '19780131074600', |
|---|
| 247 | authored_on => '19780131074500', |
|---|
| 248 | author_id => $chuckd->id, |
|---|
| 249 | pinged_urls => 'http://technorati.com/', |
|---|
| 250 | allow_comments => 1, |
|---|
| 251 | allow_pings => 1, |
|---|
| 252 | status => MT::Entry::RELEASE(), |
|---|
| 253 | }); |
|---|
| 254 | $entry->id(1); |
|---|
| 255 | $entry->tags('rain', 'grandpa', 'strolling'); |
|---|
| 256 | $entry->save() or die "Couldn't save entry record 1: ".$entry->errstr; |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | $entry = MT::Entry->load(2); |
|---|
| 260 | if (!$entry) { |
|---|
| 261 | $entry = MT::Entry->new(); |
|---|
| 262 | $entry->set_values({ |
|---|
| 263 | blog_id => 1, |
|---|
| 264 | title => 'A preponderance of evidence', |
|---|
| 265 | text => 'It is sufficient to say...', |
|---|
| 266 | text_more => 'I suck at making up test data.', |
|---|
| 267 | created_on => '19790131074500', |
|---|
| 268 | authored_on => '19790131074500', |
|---|
| 269 | modified_on => '19790131074600', |
|---|
| 270 | authored_on => '19780131074500', |
|---|
| 271 | author_id => $bobd->id, |
|---|
| 272 | allow_comments => 1, |
|---|
| 273 | status => MT::Entry::FUTURE(), |
|---|
| 274 | }); |
|---|
| 275 | $entry->id(2); |
|---|
| 276 | $entry->save() or die "Couldn't save entry record 2: ".$entry->errstr; |
|---|
| 277 | } |
|---|
| 278 | |
|---|
| 279 | $entry = MT::Entry->load(3); |
|---|
| 280 | if (!$entry) { |
|---|
| 281 | $entry = MT::Entry->new(); |
|---|
| 282 | $entry->set_values({ |
|---|
| 283 | blog_id => 1, |
|---|
| 284 | title => 'Spurious anemones', |
|---|
| 285 | text => '...are better than the non-spurious', |
|---|
| 286 | text_more => 'variety.', |
|---|
| 287 | created_on => '19770131074500', |
|---|
| 288 | authored_on => '19790131074500', |
|---|
| 289 | modified_on => '19770131074600', |
|---|
| 290 | authored_on => '19780131074500', |
|---|
| 291 | author_id => $chuckd->id, |
|---|
| 292 | allow_comments => 1, |
|---|
| 293 | allow_pings => 0, |
|---|
| 294 | status => MT::Entry::HOLD(), |
|---|
| 295 | }); |
|---|
| 296 | $entry->id(3); |
|---|
| 297 | $entry->tags('anemones'); |
|---|
| 298 | $entry->save() or die "Couldn't save entry record 3: ".$entry->errstr; |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | require MT::Trackback; |
|---|
| 302 | my $tb = MT::Trackback->load(1); |
|---|
| 303 | if (!$tb) { |
|---|
| 304 | $tb = new MT::Trackback; |
|---|
| 305 | $tb->entry_id(1); |
|---|
| 306 | $tb->blog_id(1); |
|---|
| 307 | $tb->title("Entry TrackBack Title"); |
|---|
| 308 | $tb->description("Entry TrackBack Description"); |
|---|
| 309 | $tb->category_id(0); |
|---|
| 310 | $tb->id(1); |
|---|
| 311 | $tb->save or die "Couldn't save Trackback record 1: " . $tb->errstr;; |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | require MT::TBPing; |
|---|
| 315 | my $ping = MT::TBPing->load(1); |
|---|
| 316 | if (!$ping) { |
|---|
| 317 | $ping = new MT::TBPing; |
|---|
| 318 | $ping->tb_id(1); |
|---|
| 319 | $ping->blog_id(1); |
|---|
| 320 | $ping->ip('127.0.0.1'); |
|---|
| 321 | $ping->title('Foo'); |
|---|
| 322 | $ping->excerpt('Bar'); |
|---|
| 323 | $ping->source_url('http://example.com/'); |
|---|
| 324 | $ping->blog_name("Example Blog"); |
|---|
| 325 | $ping->created_on('20050405000000'); |
|---|
| 326 | $ping->id(1); |
|---|
| 327 | $ping->visible(1); |
|---|
| 328 | $ping->save or die "Couldn't save TBPing record 1: " . $ping->errstr; |
|---|
| 329 | } |
|---|
| 330 | |
|---|
| 331 | my @verses = ( |
|---|
| 332 | 'Oh, where have you been, my blue-eyed son? |
|---|
| 333 | Oh, where have you been, my darling young one?', |
|---|
| 334 | 'I saw a newborn baby with wild wolves all around it |
|---|
| 335 | I saw a highway of diamonds with nobody on it', |
|---|
| 336 | 'Heard one hundred drummers whose hands were a-blazin\', |
|---|
| 337 | Heard ten thousand whisperin\' and nobody listenin\'', |
|---|
| 338 | 'I met one man who was wounded in love, |
|---|
| 339 | I met another man who was wounded with hatred', |
|---|
| 340 | 'Where hunger is ugly, where souls are forgotten, |
|---|
| 341 | Where black is the color, where none is the number, |
|---|
| 342 | And it\'s a hard, it\'s a hard, it\'s a hard, it\'s a hard, |
|---|
| 343 | It\'s a hard rain\'s a-gonna fall', |
|---|
| 344 | ); |
|---|
| 345 | |
|---|
| 346 | require MT::Category; |
|---|
| 347 | my $cat = MT::Category->load({ label => 'foo', blog_id => 1}); |
|---|
| 348 | if (!$cat) { |
|---|
| 349 | $cat = new MT::Category; |
|---|
| 350 | $cat->blog_id(1); |
|---|
| 351 | $cat->label('foo'); |
|---|
| 352 | $cat->description('bar'); |
|---|
| 353 | $cat->author_id($chuckd->id); |
|---|
| 354 | $cat->parent(0); |
|---|
| 355 | $cat->id(1); |
|---|
| 356 | $cat->save or die "Couldn't save category record 1: ". $cat->errstr; |
|---|
| 357 | } |
|---|
| 358 | |
|---|
| 359 | $cat = MT::Category->load({ label => 'bar', blog_id => 1}); |
|---|
| 360 | if (!$cat) { |
|---|
| 361 | $cat = new MT::Category; |
|---|
| 362 | $cat->blog_id(1); |
|---|
| 363 | $cat->label('bar'); |
|---|
| 364 | $cat->description('foo'); |
|---|
| 365 | $cat->author_id($chuckd->id); |
|---|
| 366 | $cat->parent(0); |
|---|
| 367 | $cat->id(2); |
|---|
| 368 | $cat->save or die "Couldn't save category record 2: ". $cat->errstr; |
|---|
| 369 | } |
|---|
| 370 | |
|---|
| 371 | $tb = MT::Trackback->load(2); |
|---|
| 372 | if (!$tb) { |
|---|
| 373 | $tb = new MT::Trackback; |
|---|
| 374 | $tb->title("Category TrackBack Title"); |
|---|
| 375 | $tb->description("Category TrackBack Description"); |
|---|
| 376 | $tb->entry_id(0); |
|---|
| 377 | $tb->blog_id(1); |
|---|
| 378 | $tb->category_id(2); |
|---|
| 379 | $tb->id(2); |
|---|
| 380 | $tb->save or die "Couldn't save Trackback record 2: " . $tb->errstr;; |
|---|
| 381 | } |
|---|
| 382 | |
|---|
| 383 | $cat = MT::Category->load({ label => 'subfoo', blog_id => 1}); |
|---|
| 384 | if (!$cat) { |
|---|
| 385 | $cat = new MT::Category; |
|---|
| 386 | $cat->blog_id(1); |
|---|
| 387 | $cat->label('subfoo'); |
|---|
| 388 | $cat->description('subcat'); |
|---|
| 389 | $cat->author_id($bobd->id); |
|---|
| 390 | $cat->parent(1); |
|---|
| 391 | $cat->id(3); |
|---|
| 392 | $cat->save or die "Couldn't save category record 3: ". $cat->errstr; |
|---|
| 393 | } |
|---|
| 394 | |
|---|
| 395 | require MT::Placement; |
|---|
| 396 | foreach my $i (1..@verses) { |
|---|
| 397 | $entry = MT::Entry->load($i+3); |
|---|
| 398 | if (!$entry) { |
|---|
| 399 | $entry = MT::Entry->new(); |
|---|
| 400 | $entry->set_values({ |
|---|
| 401 | blog_id => 1, |
|---|
| 402 | title => "Verse $i", |
|---|
| 403 | text => $verses[$i], |
|---|
| 404 | author_id => ($i == 3 ? $bobd->id : $chuckd->id), |
|---|
| 405 | created_on => sprintf("%04d0131074501", $i + 1960), |
|---|
| 406 | authored_on => sprintf("%04d0131074501", $i + 1960), |
|---|
| 407 | modified_on => sprintf("%04d0131074601", $i + 1960), |
|---|
| 408 | authored_on => sprintf("%04d0131074501", $i + 1960), |
|---|
| 409 | allow_comments => ($i <= 2 ? 0 : 1), |
|---|
| 410 | status => MT::Entry::RELEASE(), |
|---|
| 411 | }); |
|---|
| 412 | $entry->id($i+3); |
|---|
| 413 | if ( $i == 1 || $i == 3 || $i == 5 ) { |
|---|
| 414 | $entry->tags('verse', 'rain'); |
|---|
| 415 | } |
|---|
| 416 | else { |
|---|
| 417 | $entry->tags('verse', 'anemones'); |
|---|
| 418 | } |
|---|
| 419 | $entry->save() |
|---|
| 420 | or die "Couldn't save entry record ".($entry->id).": ". $entry->errstr; |
|---|
| 421 | if ($i == 3) { |
|---|
| 422 | my $place = new MT::Placement; |
|---|
| 423 | $place->entry_id($entry->id); |
|---|
| 424 | $place->blog_id(1); |
|---|
| 425 | $place->category_id(1); |
|---|
| 426 | $place->is_primary(1); |
|---|
| 427 | $place->save |
|---|
| 428 | or die "Couldn't save placement record: ".$place->errstr; |
|---|
| 429 | } |
|---|
| 430 | if ($i == 4) { |
|---|
| 431 | my $place = new MT::Placement; |
|---|
| 432 | $place->entry_id($entry->id); |
|---|
| 433 | $place->blog_id(1); |
|---|
| 434 | $place->category_id(3); |
|---|
| 435 | $place->is_primary(1); |
|---|
| 436 | $place->save |
|---|
| 437 | or die "Couldn't save placement record: ".$place->errstr; |
|---|
| 438 | } |
|---|
| 439 | } |
|---|
| 440 | } |
|---|
| 441 | |
|---|
| 442 | # entry id 1 - 1 visible comment |
|---|
| 443 | # entry id 4 - no comments, commenting is off |
|---|
| 444 | require MT::Comment; |
|---|
| 445 | unless (MT::Comment->count({entry_id => 1})) { |
|---|
| 446 | my $cmt = new MT::Comment(); |
|---|
| 447 | $cmt->set_values({ |
|---|
| 448 | text => 'Postmodern false consciousness has always been firmly rooted in post-Freudian Lacanian neo-Marxist bojangles. Needless to say, this quickly and asymptotically approches a purpletacular jouissance of etic jumpinmypants.', |
|---|
| 449 | entry_id => 1, |
|---|
| 450 | author => 'v14GrUH 4 cheep', |
|---|
| 451 | visible => 1, |
|---|
| 452 | email => 'jake@fatman.com', |
|---|
| 453 | url => 'http://fatman.com/', |
|---|
| 454 | blog_id => 1, |
|---|
| 455 | ip => '127.0.0.1', |
|---|
| 456 | created_on => '20040914182800', |
|---|
| 457 | }); |
|---|
| 458 | $cmt->id(1); |
|---|
| 459 | $cmt->save() or die "Couldn't save comment record 1: ".$cmt->errstr; |
|---|
| 460 | |
|---|
| 461 | $cmt->id(11); |
|---|
| 462 | $cmt->text('Comment reply for comment 1'); |
|---|
| 463 | $cmt->author('Comment 11'); |
|---|
| 464 | $cmt->created_on('20040812182900'); |
|---|
| 465 | $cmt->parent_id(1); |
|---|
| 466 | $cmt->save() or die "Couldn't save comment record 11: ".$cmt->errstr; |
|---|
| 467 | |
|---|
| 468 | $cmt->id(12); |
|---|
| 469 | $cmt->text('Comment reply for comment 11'); |
|---|
| 470 | $cmt->author('Comment 12'); |
|---|
| 471 | $cmt->created_on('20040810183000'); |
|---|
| 472 | $cmt->parent_id(11); |
|---|
| 473 | $cmt->save() or die "Couldn't save comment record 12: ".$cmt->errstr; |
|---|
| 474 | } |
|---|
| 475 | # entry id 5 - 1 comment, commenting is off (closed) |
|---|
| 476 | unless (MT::Comment->count({entry_id => 5})) { |
|---|
| 477 | my $cmt = new MT::Comment(); |
|---|
| 478 | $cmt->set_values({ |
|---|
| 479 | text => 'Comment for entry 5, visible', |
|---|
| 480 | entry_id => 5, |
|---|
| 481 | author => 'Comment 2', |
|---|
| 482 | visible => 1, |
|---|
| 483 | email => 'johnd@doe.com', |
|---|
| 484 | url => 'http://john.doe.com/', |
|---|
| 485 | commenter_id => $johnd->id, |
|---|
| 486 | blog_id => 1, |
|---|
| 487 | ip => '127.0.0.1', |
|---|
| 488 | created_on => '20040912182800', |
|---|
| 489 | }); |
|---|
| 490 | $cmt->id(2); |
|---|
| 491 | $cmt->junk_score(1.5); |
|---|
| 492 | $cmt->save() or die "Couldn't save comment record 2: ".$cmt->errstr; |
|---|
| 493 | } |
|---|
| 494 | # entry id 6 - 3 comment visible, 1 moderated |
|---|
| 495 | unless (MT::Comment->count({entry_id => 6})) { |
|---|
| 496 | my $cmt = new MT::Comment(); |
|---|
| 497 | $cmt->set_values({ |
|---|
| 498 | text => 'Comment for entry 6, visible', |
|---|
| 499 | entry_id => 6, |
|---|
| 500 | author => 'Comment 3', |
|---|
| 501 | visible => 1, |
|---|
| 502 | email => '', |
|---|
| 503 | url => '', |
|---|
| 504 | blog_id => 1, |
|---|
| 505 | ip => '127.0.0.1', |
|---|
| 506 | created_on => '20040911182800', |
|---|
| 507 | }); |
|---|
| 508 | $cmt->id(3); |
|---|
| 509 | $cmt->save() or die "Couldn't save comment record 3: ".$cmt->errstr; |
|---|
| 510 | |
|---|
| 511 | $cmt->id(4); |
|---|
| 512 | $cmt->visible(0); |
|---|
| 513 | $cmt->author('Comment 4'); |
|---|
| 514 | $cmt->text('Comment for entry 6, moderated'); |
|---|
| 515 | $cmt->created_on('20040910182800'); |
|---|
| 516 | $cmt->save() or die "Couldn't save comment record 4: ".$cmt->errstr; |
|---|
| 517 | |
|---|
| 518 | $cmt->text("All your comments are belonged to me."); |
|---|
| 519 | $cmt->commenter_id($chuckd->id); |
|---|
| 520 | $cmt->visible(1); |
|---|
| 521 | $cmt->id(14); |
|---|
| 522 | $cmt->save or die "Couldn't save comment record 1: ".$cmt->errstr; |
|---|
| 523 | |
|---|
| 524 | $cmt->text("All your comments are belonged to us MT Authors."); |
|---|
| 525 | $cmt->commenter_id($bobd->id); |
|---|
| 526 | $cmt->visible(1); |
|---|
| 527 | $cmt->id(15); |
|---|
| 528 | $cmt->save or die "Couldn't save comment record 1: ".$cmt->errstr; |
|---|
| 529 | } |
|---|
| 530 | # entry id 7 - 0 comment visible, 1 moderated |
|---|
| 531 | unless (MT::Comment->count({entry_id => 7})) { |
|---|
| 532 | my $cmt = new MT::Comment(); |
|---|
| 533 | $cmt->set_values({ |
|---|
| 534 | text => 'Comment for entry 7, moderated', |
|---|
| 535 | entry_id => 7, |
|---|
| 536 | author => 'Comment 7', |
|---|
| 537 | visible => 0, |
|---|
| 538 | email => '', |
|---|
| 539 | url => '', |
|---|
| 540 | blog_id => 1, |
|---|
| 541 | ip => '127.0.0.1', |
|---|
| 542 | created_on => '20040909182800', |
|---|
| 543 | }); |
|---|
| 544 | $cmt->id(5); |
|---|
| 545 | $cmt->save() or die "Couldn't save comment record 5: ".$cmt->errstr; |
|---|
| 546 | } |
|---|
| 547 | # entry id 8 - 1 comment visible, 1 moderated, 1 junk |
|---|
| 548 | unless (MT::Comment->count({entry_id => 8})) { |
|---|
| 549 | my $cmt = new MT::Comment(); |
|---|
| 550 | $cmt->set_values({ |
|---|
| 551 | text => 'Comment for entry 8, visible', |
|---|
| 552 | entry_id => 8, |
|---|
| 553 | author => 'Comment 8', |
|---|
| 554 | visible => 1, |
|---|
| 555 | email => '', |
|---|
| 556 | url => '', |
|---|
| 557 | blog_id => 1, |
|---|
| 558 | ip => '127.0.0.1', |
|---|
| 559 | created_on => '20040814182800', |
|---|
| 560 | }); |
|---|
| 561 | $cmt->id(6); |
|---|
| 562 | $cmt->save() or die "Couldn't save comment record 6: ".$cmt->errstr; |
|---|
| 563 | |
|---|
| 564 | $cmt->id(7); |
|---|
| 565 | $cmt->visible(0); |
|---|
| 566 | $cmt->text('Comment for entry 8, moderated'); |
|---|
| 567 | $cmt->author('JD7'); |
|---|
| 568 | $cmt->created_on('20040812182800'); |
|---|
| 569 | $cmt->save() or die "Couldn't save comment record 7: ".$cmt->errstr; |
|---|
| 570 | |
|---|
| 571 | $cmt->id(8); |
|---|
| 572 | $cmt->visible(0); |
|---|
| 573 | $cmt->junk_status(-1); |
|---|
| 574 | $cmt->text('Comment for entry 8, junk'); |
|---|
| 575 | $cmt->author('JD8'); |
|---|
| 576 | $cmt->created_on('20040810182800'); |
|---|
| 577 | $cmt->save() or die "Couldn't save comment record 8: ".$cmt->errstr; |
|---|
| 578 | } |
|---|
| 579 | |
|---|
| 580 | require MT::Template; |
|---|
| 581 | require MT::TemplateMap; |
|---|
| 582 | |
|---|
| 583 | my $tmpl = new MT::Template; |
|---|
| 584 | $tmpl->blog_id(1); |
|---|
| 585 | $tmpl->name('blog-name'); |
|---|
| 586 | $tmpl->text('<MTBlogName>'); |
|---|
| 587 | $tmpl->type('custom'); |
|---|
| 588 | $tmpl->save or die "Couldn't save template record 1: ".$tmpl->errstr; |
|---|
| 589 | |
|---|
| 590 | ### Asset |
|---|
| 591 | use MT::Asset; |
|---|
| 592 | |
|---|
| 593 | my $img_pkg = MT::Asset->class_handler('image'); |
|---|
| 594 | my $file_pkg = MT::Asset->class_handler('file'); |
|---|
| 595 | my $asset = new $img_pkg; |
|---|
| 596 | $asset->blog_id(1); |
|---|
| 597 | $asset->url('http://narnia.na/nana/images/test.jpg'); |
|---|
| 598 | $asset->file_path(File::Spec->catfile($ENV{MT_HOME}, "t", 'images', 'test.jpg')); |
|---|
| 599 | $asset->file_name('test.jpg'); |
|---|
| 600 | $asset->file_ext('jpg'); |
|---|
| 601 | $asset->image_width(640); |
|---|
| 602 | $asset->image_height(480); |
|---|
| 603 | $asset->mime_type('image/jpeg'); |
|---|
| 604 | $asset->label('Image photo'); |
|---|
| 605 | $asset->description('This is a test photo.'); |
|---|
| 606 | $asset->created_by(1); |
|---|
| 607 | $asset->tags('alpha', 'beta', 'gamma'); |
|---|
| 608 | $asset->save; |
|---|
| 609 | |
|---|
| 610 | $asset->set_score('unit test', $bobd, 5, 1); |
|---|
| 611 | $asset->set_score('unit test', $johnd, 3, 1); |
|---|
| 612 | $asset->set_score('unit test', MT::Author->load(1), 4, 1); |
|---|
| 613 | |
|---|
| 614 | $asset = new $file_pkg; |
|---|
| 615 | $asset->blog_id(1); |
|---|
| 616 | $asset->url('http://narnia.na/nana/files/test.tmpl'); |
|---|
| 617 | $asset->file_path(File::Spec->catfile($ENV{MT_HOME}, "t", 'test.tmpl')); |
|---|
| 618 | $asset->file_name('test.tmpl'); |
|---|
| 619 | $asset->file_ext('tmpl'); |
|---|
| 620 | $asset->mime_type('text/plain'); |
|---|
| 621 | $asset->label('Template'); |
|---|
| 622 | $asset->description('This is a test template.'); |
|---|
| 623 | $asset->created_by(1); |
|---|
| 624 | $asset->created_on('19780131074500'); |
|---|
| 625 | $asset->tags('beta'); |
|---|
| 626 | $asset->save; |
|---|
| 627 | |
|---|
| 628 | $asset->set_score('unit test', $chuckd, 2, 1); |
|---|
| 629 | $asset->set_score('unit test', $johnd, 3, 1); |
|---|
| 630 | |
|---|
| 631 | ## ObjectScore |
|---|
| 632 | my $e5 = MT::Entry->load(5); |
|---|
| 633 | $e5->set_score('unit test', $bobd, 5, 1); |
|---|
| 634 | $e5->set_score('unit test', $johnd, 3, 1); |
|---|
| 635 | $e5->set_score('unit test', MT::Author->load(1), 4, 1); |
|---|
| 636 | |
|---|
| 637 | my $e6 = MT::Entry->load(6); |
|---|
| 638 | $e6->set_score('unit test', $chuckd, 1, 1); |
|---|
| 639 | $e6->set_score('unit test', $johnd, 1, 1); |
|---|
| 640 | |
|---|
| 641 | my $e4 = MT::Entry->load(4); |
|---|
| 642 | $e4->set_score('unit test', $chuckd, 2, 1); |
|---|
| 643 | $e4->set_score('unit test', $johnd, 3, 1); |
|---|
| 644 | |
|---|
| 645 | ## Page |
|---|
| 646 | require MT::Page; |
|---|
| 647 | my $page = MT::Page->new(); |
|---|
| 648 | $page->set_values({ |
|---|
| 649 | blog_id => 1, |
|---|
| 650 | title => 'Watching the River Flow', |
|---|
| 651 | text => 'What the matter with me,', |
|---|
| 652 | text_more => 'I don\'t have much to say,', |
|---|
| 653 | keywords => 'no folder', |
|---|
| 654 | excerpt => 'excerpt', |
|---|
| 655 | created_on => '19780131074500', |
|---|
| 656 | authored_on => '19780131074500', |
|---|
| 657 | modified_on => '19780131074600', |
|---|
| 658 | author_id => $chuckd->id, |
|---|
| 659 | status => MT::Entry::RELEASE(), |
|---|
| 660 | }); |
|---|
| 661 | $page->id(20); |
|---|
| 662 | $page->tags('river', 'flow', 'watch'); |
|---|
| 663 | $page->save() or die "Couldn't save page record 20: ".$page->errstr; |
|---|
| 664 | |
|---|
| 665 | require MT::Folder; |
|---|
| 666 | my $folder = MT::Folder->new(); |
|---|
| 667 | $folder->blog_id(1); |
|---|
| 668 | $folder->label('info'); |
|---|
| 669 | $folder->description('information'); |
|---|
| 670 | $folder->author_id($chuckd->id); |
|---|
| 671 | $folder->parent(0); |
|---|
| 672 | $folder->id(20); |
|---|
| 673 | $folder->save or die "Could'n sae folder record 20:" . $folder->errstr; |
|---|
| 674 | |
|---|
| 675 | $folder = MT::Folder->new(); |
|---|
| 676 | $folder->blog_id(1); |
|---|
| 677 | $folder->label('download'); |
|---|
| 678 | $folder->description('download top'); |
|---|
| 679 | $folder->author_id($chuckd->id); |
|---|
| 680 | $folder->parent(0); |
|---|
| 681 | $folder->id(21); |
|---|
| 682 | $folder->save or die "Could'n sae folder record 21:" . $folder->errstr; |
|---|
| 683 | |
|---|
| 684 | $folder = MT::Folder->new(); |
|---|
| 685 | $folder->blog_id(1); |
|---|
| 686 | $folder->label('nightly'); |
|---|
| 687 | $folder->description('nightly build'); |
|---|
| 688 | $folder->author_id($chuckd->id); |
|---|
| 689 | $folder->parent(21); |
|---|
| 690 | $folder->id(22); |
|---|
| 691 | $folder->save or die "Could'n sae folder record 22:" . $folder->errstr; |
|---|
| 692 | |
|---|
| 693 | $page = MT::Page->new(); |
|---|
| 694 | $page->set_values({ |
|---|
| 695 | blog_id => 1, |
|---|
| 696 | title => 'Page #1', |
|---|
| 697 | text => 'Wish I was back in the city', |
|---|
| 698 | text_more => 'Instead of this old bank of sand,', |
|---|
| 699 | keywords => 'keywords', |
|---|
| 700 | created_on => '19790131074500', |
|---|
| 701 | authored_on => '19790131074500', |
|---|
| 702 | modified_on => '19790131074600', |
|---|
| 703 | author_id => $chuckd->id, |
|---|
| 704 | status => MT::Entry::RELEASE(), |
|---|
| 705 | }); |
|---|
| 706 | $page->id(21); |
|---|
| 707 | $page->tags('page1', 'page2', 'page3'); |
|---|
| 708 | $page->save() or die "Couldn't save page record 21: ".$page->errstr; |
|---|
| 709 | |
|---|
| 710 | my $folder_place = new MT::Placement; |
|---|
| 711 | $folder_place->entry_id(21); |
|---|
| 712 | $folder_place->blog_id(1); |
|---|
| 713 | $folder_place->category_id(20); |
|---|
| 714 | $folder_place->is_primary(1); |
|---|
| 715 | $folder_place->save |
|---|
| 716 | or die "Couldn't save placement record: ".$folder_place->errstr; |
|---|
| 717 | |
|---|
| 718 | $page = MT::Page->new(); |
|---|
| 719 | $page->set_values({ |
|---|
| 720 | blog_id => 1, |
|---|
| 721 | title => 'Page #2', |
|---|
| 722 | text => 'With the sub beating down over the chimney tops', |
|---|
| 723 | text_more => 'And the one I love so close at hand', |
|---|
| 724 | keywords => 'keywords', |
|---|
| 725 | created_on => '19800131074500', |
|---|
| 726 | authored_on => '19800131074500', |
|---|
| 727 | modified_on => '19800131074600', |
|---|
| 728 | author_id => $chuckd->id, |
|---|
| 729 | status => MT::Entry::RELEASE(), |
|---|
| 730 | }); |
|---|
| 731 | $page->id(22); |
|---|
| 732 | $page->tags('page2', 'page3'); |
|---|
| 733 | $page->save() or die "Couldn't save page record 22: ".$page->errstr; |
|---|
| 734 | |
|---|
| 735 | $folder_place = new MT::Placement; |
|---|
| 736 | $folder_place->entry_id(22); |
|---|
| 737 | $folder_place->blog_id(1); |
|---|
| 738 | $folder_place->category_id(21); |
|---|
| 739 | $folder_place->is_primary(1); |
|---|
| 740 | $folder_place->save |
|---|
| 741 | or die "Couldn't save placement record: ".$folder_place->errstr; |
|---|
| 742 | |
|---|
| 743 | $page = MT::Page->new(); |
|---|
| 744 | $page->set_values({ |
|---|
| 745 | blog_id => 1, |
|---|
| 746 | title => 'Page #3', |
|---|
| 747 | text => 'If I had wings and I could fly,', |
|---|
| 748 | text_more => 'I know where I would go.', |
|---|
| 749 | keywords => 'keywords', |
|---|
| 750 | created_on => '19810131074500', |
|---|
| 751 | authored_on => '19810131074500', |
|---|
| 752 | modified_on => '19810131074600', |
|---|
| 753 | author_id => $bobd->id, |
|---|
| 754 | status => MT::Entry::RELEASE(), |
|---|
| 755 | }); |
|---|
| 756 | $page->id(23); |
|---|
| 757 | $page->tags('page3'); |
|---|
| 758 | $page->save() or die "Couldn't save page record 23: ".$page->errstr; |
|---|
| 759 | |
|---|
| 760 | $folder_place = new MT::Placement; |
|---|
| 761 | $folder_place->entry_id(23); |
|---|
| 762 | $folder_place->blog_id(1); |
|---|
| 763 | $folder_place->category_id(22); |
|---|
| 764 | $folder_place->is_primary(1); |
|---|
| 765 | $folder_place->save |
|---|
| 766 | or die "Couldn't save placement record: ".$folder_place->errstr; |
|---|
| 767 | |
|---|
| 768 | unless (MT::Comment->count({entry_id => $page->id})) { |
|---|
| 769 | my $page_cmt = new MT::Comment(); |
|---|
| 770 | $page_cmt->set_values({ |
|---|
| 771 | text => "Your time is limited, so don't waste it living someone else's life. Don't be trapped by dogma - which is living with the results of other people's thinking. Don't let the noise of others' opinions drown out your own inner voice. And most important, have the courage to follow your heart and intuition. They somehow already know what you truly want to become. Everything else is secondary.", |
|---|
| 772 | entry_id => 23, |
|---|
| 773 | author => 'Steve Jobs', |
|---|
| 774 | visible => 1, |
|---|
| 775 | email => 'f@example.com', |
|---|
| 776 | url => 'http://example.com/', |
|---|
| 777 | blog_id => 1, |
|---|
| 778 | ip => '127.0.0.1', |
|---|
| 779 | created_on => '20040114182800', |
|---|
| 780 | modified_on => '20040114182800', |
|---|
| 781 | }); |
|---|
| 782 | $page_cmt->id(13); |
|---|
| 783 | $page_cmt->save() or die "Couldn't save comment record 1: ".$page_cmt->errstr; |
|---|
| 784 | } |
|---|
| 785 | |
|---|
| 786 | my $page_tb = MT::Trackback->new; |
|---|
| 787 | $page_tb->entry_id($page->id); |
|---|
| 788 | $page_tb->blog_id(1); |
|---|
| 789 | $page_tb->title("Page TrackBack Title"); |
|---|
| 790 | $page_tb->description("Page TrackBack Description"); |
|---|
| 791 | $page_tb->category_id(0); |
|---|
| 792 | $page_tb->id(3); |
|---|
| 793 | $page_tb->save or die "Couldn't save Trackback record 1: " . $tb->errstr;; |
|---|
| 794 | |
|---|
| 795 | my $page_ping = MT::TBPing->new; |
|---|
| 796 | $page_ping->tb_id($page_tb->id); |
|---|
| 797 | $page_ping->blog_id(1); |
|---|
| 798 | $page_ping->ip('127.0.0.1'); |
|---|
| 799 | $page_ping->title('Trackbacking to a page'); |
|---|
| 800 | $page_ping->excerpt('Four bridges in the bayarea. Golden Gate, Bay, San Mateo and Dan Burton.'); |
|---|
| 801 | $page_ping->source_url('http://example.com/'); |
|---|
| 802 | $page_ping->blog_name("Example Blog"); |
|---|
| 803 | $page_ping->created_on('20040101000000'); |
|---|
| 804 | $page_ping->modified_on('20040101000000'); |
|---|
| 805 | $page_ping->visible(1); |
|---|
| 806 | $page_ping->id(3); |
|---|
| 807 | $page_ping->save or die "Couldn't save TBPing record 1: " . $ping->errstr; |
|---|
| 808 | |
|---|
| 809 | MT->instance->rebuild( |
|---|
| 810 | BlogId => 1, |
|---|
| 811 | EntryCallback => sub { print STDERR "# Rebuilding entry " . $_[0]->id . "\n" } |
|---|
| 812 | ); |
|---|
| 813 | |
|---|
| 814 | ### Make ObjectAsset mappings |
|---|
| 815 | require MT::ObjectAsset; |
|---|
| 816 | my $map; |
|---|
| 817 | $entry = MT::Entry->load(1); |
|---|
| 818 | if ($entry) { |
|---|
| 819 | $map = new MT::ObjectAsset; |
|---|
| 820 | $map->blog_id($entry->blog_id); |
|---|
| 821 | $map->asset_id(1); |
|---|
| 822 | $map->object_ds($entry->datasource); |
|---|
| 823 | $map->object_id($entry->id); |
|---|
| 824 | $map->save; |
|---|
| 825 | } |
|---|
| 826 | $page = MT::Page->load(20); |
|---|
| 827 | if ($entry) { |
|---|
| 828 | $map = new MT::ObjectAsset; |
|---|
| 829 | $map->blog_id($page->blog_id); |
|---|
| 830 | $map->asset_id(2); |
|---|
| 831 | $map->object_ds($page->datasource); |
|---|
| 832 | $map->object_id($page->id); |
|---|
| 833 | $map->save; |
|---|
| 834 | } |
|---|
| 835 | |
|---|
| 836 | 1; |
|---|
| 837 | } |
|---|
| 838 | |
|---|
| 839 | 1; |
|---|