Change config key in tests
[catagits/Catalyst-Plugin-Cache.git] / t / basic.t
CommitLineData
c28ee69c 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More 'no_plan';
7use Test::Exception;
8
9use ok "Catalyst::Plugin::Cache";
10
33002c69 11use Catalyst::Plugin::Cache::Backend::Memory;
12
c28ee69c 13{
14 package MockApp;
15 use base qw/Catalyst::Plugin::Cache/;
23b2d59b 16
17 sub registered_plugins {}
c28ee69c 18
e9154310 19 ### must register a backend class as of 0.06
20 ### the previous code simply ignored a croak
21 ### this is still in line with the documentation.
22 my %config = (
d18c37f3 23 'Plugin::Cache' => {
e9154310 24 backend => {
25 class => 'Catalyst::Plugin::Cache::Backend::Memory',
26 }
27 }
28 );
2e4bde89 29 sub config { \%config };
c28ee69c 30}
31
32MockApp->setup;
33my $c = bless {}, "MockApp";
34
35can_ok( $c, "register_cache_backend" );
36can_ok( $c, "unregister_cache_backend" );
37
33002c69 38MockApp->register_cache_backend( default => Catalyst::Plugin::Cache::Backend::Memory->new );
39MockApp->register_cache_backend( moose => Catalyst::Plugin::Cache::Backend::Memory->new );
c28ee69c 40
41can_ok( $c, "cache" );
42
43ok( $c->cache, "->cache returns a value" );
44
45can_ok( $c->cache, "get" ); #, "rv from cache" );
46can_ok( $c->cache("default"), "get" ); #, "default backend" );
47can_ok( $c->cache("moose"), "get" ); #, "moose backend" );
48
49ok( !$c->cache("lalalala"), "no lalala backend");
50
51MockApp->unregister_cache_backend( "moose" );
52
53ok( !$c->cache("moose"), "moose backend unregistered");
54
55
56dies_ok {
57 MockApp->register_cache_backend( ding => undef );
58} "can't register invalid backend";
59
60dies_ok {
61 MockApp->register_cache_backend( ding => bless {}, "SomeClass" );
62} "can't register invalid backend";
63
64
65
66can_ok( $c, "default_cache_backend" );
c28ee69c 67
68can_ok( $c, "choose_cache_backend_wrapper" );
69can_ok( $c, "choose_cache_backend" );
70
71can_ok( $c, "cache_set" );
72can_ok( $c, "cache_get" );
aed484da 73can_ok( $c, "cache_remove" );
c28ee69c 74
75$c->cache_set( foo => "bar" );
76is( $c->cache_get("foo"), "bar", "set" );
77
aed484da 78$c->cache_remove( "foo" );
79is( $c->cache_get("foo"), undef, "remove" );
c28ee69c 80
33002c69 81MockApp->register_cache_backend( elk => Catalyst::Plugin::Cache::Backend::Memory->new );
c28ee69c 82
83is( $c->choose_cache_backend_wrapper( key => "foo" ), $c->default_cache_backend, "choose default" );
84is( $c->choose_cache_backend_wrapper( key => "foo", backend => "elk" ), $c->get_cache_backend("elk"), "override choice" );
85
86
87$c->cache_set( foo => "gorch", backend => "elk" );
88is( $c->cache_get("foo"), undef, "set to custom backend (get from non custom)" );
89is( $c->cache_get("foo", backend => "elk"), "gorch", "set to custom backend (get from custom)" );
90
2e4bde89 91my $cache_elk = $c->cache( backend => "elk" );
92my $cache_norm = $c->cache();
93
94is( $cache_norm->get("foo"), undef, "default curried cache has no foo");
95is( $cache_elk->get("foo"), "gorch", "curried custom backend has foo" );