6 use Test::More 'no_plan';
9 use ok "Catalyst::Plugin::Cache";
11 use Catalyst::Plugin::Cache::Backend::Memory;
15 use base qw/Catalyst::Plugin::Cache/;
17 sub registered_plugins {}
20 sub config { \%config };
24 my $c = bless {}, "MockApp";
26 can_ok( $c, "register_cache_backend" );
27 can_ok( $c, "unregister_cache_backend" );
29 MockApp->register_cache_backend( default => Catalyst::Plugin::Cache::Backend::Memory->new );
30 MockApp->register_cache_backend( moose => Catalyst::Plugin::Cache::Backend::Memory->new );
32 can_ok( $c, "cache" );
34 ok( $c->cache, "->cache returns a value" );
36 can_ok( $c->cache, "get" ); #, "rv from cache" );
37 can_ok( $c->cache("default"), "get" ); #, "default backend" );
38 can_ok( $c->cache("moose"), "get" ); #, "moose backend" );
40 ok( !$c->cache("lalalala"), "no lalala backend");
42 MockApp->unregister_cache_backend( "moose" );
44 ok( !$c->cache("moose"), "moose backend unregistered");
48 MockApp->register_cache_backend( ding => undef );
49 } "can't register invalid backend";
52 MockApp->register_cache_backend( ding => bless {}, "SomeClass" );
53 } "can't register invalid backend";
57 can_ok( $c, "default_cache_backend" );
59 can_ok( $c, "choose_cache_backend_wrapper" );
60 can_ok( $c, "choose_cache_backend" );
62 can_ok( $c, "cache_set" );
63 can_ok( $c, "cache_get" );
64 can_ok( $c, "cache_remove" );
66 $c->cache_set( foo => "bar" );
67 is( $c->cache_get("foo"), "bar", "set" );
69 $c->cache_remove( "foo" );
70 is( $c->cache_get("foo"), undef, "remove" );
72 MockApp->register_cache_backend( elk => Catalyst::Plugin::Cache::Backend::Memory->new );
74 is( $c->choose_cache_backend_wrapper( key => "foo" ), $c->default_cache_backend, "choose default" );
75 is( $c->choose_cache_backend_wrapper( key => "foo", backend => "elk" ), $c->get_cache_backend("elk"), "override choice" );
78 $c->cache_set( foo => "gorch", backend => "elk" );
79 is( $c->cache_get("foo"), undef, "set to custom backend (get from non custom)" );
80 is( $c->cache_get("foo", backend => "elk"), "gorch", "set to custom backend (get from custom)" );
82 my $cache_elk = $c->cache( backend => "elk" );
83 my $cache_norm = $c->cache();
85 is( $cache_norm->get("foo"), undef, "default curried cache has no foo");
86 is( $cache_elk->get("foo"), "gorch", "curried custom backend has foo" );