Improve status codes and support HTML match responses

Change-Id: Ie11b68eb0836bb537a2869b87e78f3a695203e11
diff --git a/t/match_info.t b/t/match_info.t
index 486fe11..235ae66 100644
--- a/t/match_info.t
+++ b/t/match_info.t
@@ -25,14 +25,14 @@
 $fake_backend->pattern->defaults->{app}->log($t->app->log);
 
 # Query passed
-$t->get_ok('/corpus/WPD15/232/39681/p2133-2134?spans=false&foundry=*')
+$t->get_ok('/corpus/WPD15/232/39681/p2133-2134?spans=false&foundry=*&format=json')
   ->status_is(200)
   ->json_is('/textSigle', 'WPD15/232/39681')
   ->json_like('/snippet', qr!<span class=\"context-left\">!)
   ->header_isnt('X-Kalamar-Cache', 'true')
   ;
 
-$t->get_ok('/corpus/GOE/AGF/02286/p75682-75683')
+$t->get_ok('/corpus/GOE/AGF/02286/p75682-75683?format=json')
   ->status_is(200)
   ->json_is('/textSigle', 'GOE/AGF/02286')
   ->json_is('/title','Materialien zur Geschichte der Farbenlehre')
@@ -40,43 +40,39 @@
 
 # TODO:
 #   It's surprising, that it doesn't return a 404!
-$t->get_ok('/corpus/notfound/X/X/p0-1')
+$t->get_ok('/corpus/notfound/X/X/p0-1?format=json')
   ->status_is(200)
   ->json_is('/textSigle', 'NOTFOUND/X/X')
   ->json_is('/corpusID', undef)
   ;
 
-# TODO:
-#   Should probably return a 500!
-$t->get_ok('/corpus/fail/x/x/p0-0')
-  ->status_is(200)
+$t->get_ok('/corpus/fail/x/x/p0-0?format=json')
+  ->status_is(400)
   ->json_is('/notifications/0/0', 'error')
   ->json_like('/notifications/0/1', qr!Unable to load query response from .+?response_matchinfo_fail_x_x_p0-0\.json!)
   ;
 
 # TODO:
 #   Should probably return a 4xx!
-$t->get_ok('/corpus/GOE/AGF/02286/p-2-0')
-  ->status_is(200)
+$t->get_ok('/corpus/GOE/AGF/02286/p-2-0?format=json')
+  ->status_is(400)
   ->json_is('/notifications/0/0', 'error')
   ->json_is('/notifications/0/1', '730: Invalid match identifier')
   ;
 
-# TODO:
-#   It's surprising, that it doesn't return a 404!
-$t->get_ok('/corpus/notfound2/X/X/p0-1')
+$t->get_ok('/corpus/notfound2/X/X/p0-1?format=json')
   ->status_is(404)
   ->json_is('/notifications/0/0', 'error')
   ->json_is('/notifications/0/1', '404: Not Found')
   ;
 
-$t->get_ok('/corpus/brokenerr/X/X/p0-1')
+$t->get_ok('/corpus/brokenerr/X/X/p0-1?format=json')
   ->status_is(409)
   ->json_is('/notifications/0/0', 'error')
   ->json_is('/notifications/0/1', 'Message structure failed')
   ;
 
-$t->get_ok('/corpus/brokenwarn/X/X/p0-1')
+$t->get_ok('/corpus/brokenwarn/X/X/p0-1?format=json')
   ->status_is(200)
   ->json_is('/notifications/0/0', 'warn')
   ->json_is('/notifications/0/1', '1: Warning 1')
@@ -84,14 +80,14 @@
   ->json_is('/notifications/1/1', 'Message structure failed')
   ;
 
-$t->get_ok('/corpus/brokenerr2/X/X/p0-1')
+$t->get_ok('/corpus/brokenerr2/X/X/p0-1?format=json')
   ->status_is(417)
   ->json_is('/notifications/0/0', 'error')
   ->json_is('/notifications/0/1', 'Message structure failed')
   ;
 
 # Get from cache
-$t->get_ok('/corpus/WPD15/232/39681/p2133-2134?spans=false&foundry=*')
+$t->get_ok('/corpus/WPD15/232/39681/p2133-2134?spans=false&foundry=*&format=json')
   ->status_is(200)
   ->json_is('/textSigle', 'WPD15/232/39681')
   ->json_like('/snippet', qr!<span class=\"context-left\">!)
@@ -99,10 +95,17 @@
   ;
 
 # Check for validation error
-$t->get_ok('/corpus/WPD15/232/39681/p2133-2134?spans=no')
+$t->get_ok('/corpus/WPD15/232/39681/p2133-2134?spans=no&format=json')
   ->status_is(400)
   ->json_is('/notifications/0/1', 'Parameter "spans" invalid')
   ;
 
+$t->get_ok('/corpus/WPD15/232/39681/p2133-2134?spans=no&format=html')
+  ->status_is(400)
+  ->text_is('p.no-results', 'Unable to perform the action.')
+  ->text_is('div.notify', 'Parameter "spans" invalid')
+  ;
+
+
 done_testing;
 __END__
diff --git a/t/plugin/auth-oauth.t b/t/plugin/auth-oauth.t
index 93cd3ca..8556319 100644
--- a/t/plugin/auth-oauth.t
+++ b/t/plugin/auth-oauth.t
@@ -330,7 +330,7 @@
 # Query without cache
 # The token is invalid and can't be refreshed!
 $t->get_ok('/?q=baum&cutoff=true')
-  ->status_is(200)
+  ->status_is(400)
   ->session_hasnt('/auth')
   ->session_hasnt('/auth_r')
   ->text_is('#error','')
@@ -373,7 +373,7 @@
 
 # The token is invalid and can't be refreshed!
 $csrf = $t->get_ok('/?q=baum&cutoff=true')
-  ->status_is(200)
+  ->status_is(400)
   ->session_hasnt('/auth')
   ->session_hasnt('/auth_r')
   ->text_is('#error','')
diff --git a/t/query.t b/t/query.t
index 035560d..f3b83a6 100644
--- a/t/query.t
+++ b/t/query.t
@@ -86,7 +86,7 @@
   ->element_exists('.notify-error')
   ->text_is('.notify-error', '302: Parantheses/brackets unbalanced.')
   ->content_like(qr!KorAP\.koralQuery =!)
-  ->text_is('.no-results:nth-of-type(1)', 'Unable to perform the search.')
+  ->text_is('.no-results:nth-of-type(1)', 'Unable to perform the action.')
   ;