| 1 | use strict; |
|---|
| 2 | |
|---|
| 3 | use lib 't/lib', 'extlib', 'lib', '../lib', '../extlib'; |
|---|
| 4 | use Test::More tests => 8; |
|---|
| 5 | |
|---|
| 6 | use MT::Test qw(:db :data); |
|---|
| 7 | use MT; |
|---|
| 8 | |
|---|
| 9 | require MT::Category; |
|---|
| 10 | my $cat_cache = MT::Category->cache(blog_id => 1); |
|---|
| 11 | ok($cat_cache, "category cache exists for blog id 1"); |
|---|
| 12 | |
|---|
| 13 | # make sure order is consistent |
|---|
| 14 | @$cat_cache = sort { $a->[1] cmp $b->[1] } @$cat_cache; |
|---|
| 15 | |
|---|
| 16 | # check one of the elements |
|---|
| 17 | is($cat_cache->[0][0], '2', "category id is 2"); |
|---|
| 18 | is($cat_cache->[0][1], 'bar', "category name is 'bar'"); |
|---|
| 19 | is($cat_cache->[0][2], '0', "no parent for 'bar' category"); |
|---|
| 20 | |
|---|
| 21 | require MT::Tag; |
|---|
| 22 | my $tag_cache = MT::Tag->cache(blog_id => 1, class => 'MT::Entry'); |
|---|
| 23 | ok($tag_cache, "tag cache exists for blog id 1"); |
|---|
| 24 | |
|---|
| 25 | is(@$tag_cache, 5, "number of tags in cache is 5"); # relies on test data |
|---|
| 26 | |
|---|
| 27 | my $entry = MT::Entry->load(1); |
|---|
| 28 | $entry->tags($entry->get_tags(), 'newtag'); |
|---|
| 29 | $entry->save; |
|---|
| 30 | |
|---|
| 31 | $tag_cache = MT::Tag->cache(blog_id => 1, class => 'MT::Entry'); |
|---|
| 32 | ok(grep('newtag', @$tag_cache), "newtag is in cache"); |
|---|
| 33 | |
|---|
| 34 | my $cat = new MT::Category; |
|---|
| 35 | $cat->label("New category"); |
|---|
| 36 | $cat->blog_id(1); |
|---|
| 37 | $cat->save; |
|---|
| 38 | |
|---|
| 39 | my $new_cat_cache_count = (scalar @$cat_cache) + 1; |
|---|
| 40 | $cat_cache = MT::Category->cache(blog_id => 1); |
|---|
| 41 | is((scalar @$cat_cache), $new_cat_cache_count, "category cache count incremented"); |
|---|
| 42 | |
|---|
| 43 | 1; |
|---|