summary refs log tree commit diff
path: root/t/tests/Test
diff options
context:
space:
mode:
Diffstat (limited to 't/tests/Test')
-rw-r--r--t/tests/Test/MooseX/UserAgent.pm46
1 files changed, 34 insertions, 12 deletions
diff --git a/t/tests/Test/MooseX/UserAgent.pm b/t/tests/Test/MooseX/UserAgent.pm
index 0c5a630..b63b479 100644
--- a/t/tests/Test/MooseX/UserAgent.pm
+++ b/t/tests/Test/MooseX/UserAgent.pm
@@ -17,7 +17,8 @@ use Cache::MemoryCache;
         is      => 'rw',
         default => sub {
             return {
-                name     => 'Mozilla/5.0 (compatible; LWP; RTGI; http://rtgi.fr/)',
+                name =>
+                    'Mozilla/5.0 (compatible; LWP; RTGI; http://rtgi.fr/)',
                 mail     => 'bot@rtgi.fr',
                 timeout  => 30,
                 cache    => { use_cache => 0, },
@@ -37,11 +38,11 @@ use Cache::MemoryCache;
         is      => 'rw',
         default => sub {
             return {
-                name     => 'Mozilla/5.0 (compatible; Async; RTGI; http://rtgi.fr/)',
-                mail     => 'bot@rtgi.fr',
-                timeout  => 30,
-                cache    => { use_cache => 0, },
-                max_size => 3000000,
+                name =>
+                    'Mozilla/5.0 (compatible; Async; RTGI; http://rtgi.fr/)',
+                mail    => 'bot@rtgi.fr',
+                timeout => 30,
+                cache   => { use_cache => 0, },
             };
         }
     );
@@ -75,7 +76,8 @@ sub fetch : Tests(14) {
         # test with cache
         $obj = $ua->new(
             useragent_conf => {
-                name     => 'Mozilla/5.0 (compatible; Async; RTGI; http://rtgi.fr/)',
+                name =>
+                    'Mozilla/5.0 (compatible; Async; RTGI; http://rtgi.fr/)',
                 cache => {
                     use_cache => 1,
                     namespace => 'testua',
@@ -86,7 +88,6 @@ sub fetch : Tests(14) {
         $res = $obj->fetch($url);
         is $res->code, "200", "... fetch is a success";
 
-        # now data should be in cache
         my $ref = $obj->ua_cache->get($url);
         ok defined $ref, "... url is now in cache";
     }
@@ -95,16 +96,37 @@ sub fetch : Tests(14) {
 sub get_content : Tests(8) {
     my $test = shift;
 
+    my $url = 'http://lumberjaph.net';
     foreach my $ua (@ua_roles) {
         can_ok $ua, 'get_content';
-
         ok my $obj = $ua->new(), ' ... object is created';
-        my $url = 'http://google.com';
         my $res = $obj->fetch($url);
-        is $res->code, "200", "... fetch is a success";
+        cmp_ok $res->code, "<", 300, "... fetch is a success";
         my $content = $obj->get_content($res);
-        like $content, qr/google/, "... and content is good";
+        like $content, qr/lumberjaph/, "... and content is good";
     }
 }
 
+sub test_cache : Tests(4) {
+    my $test = shift;
+    my $url = 'http://en.wikipedia.org';
+
+    my $obj = Test::UserAgent->new(
+        useragent_conf => { cache => { use_cache => 1 } },
+        ua_cache       => $test->cache
+        ),
+        ' ... object is created';
+    can_ok $obj, 'get_content';
+    my $res = $obj->fetch($url);
+    cmp_ok $res->code, "<", 300, "... fetch is a success";
+
+    $obj = Test::UserAgent::Async->new(
+        useragent_conf => { cache => { use_cache => 1 } },
+        ua_cache       => $test->cache
+        ),
+        ' ... object is created';
+    can_ok $obj, 'get_content';
+    $res = $obj->fetch($url);
+    is $res->code, 304, '... already in cache';
+}
 1;