Fix tests for Mojo >= 9.21

Change-Id: I541ce824cbad44896cf3a6fae4a849d30f29ffad
diff --git a/Changes b/Changes
index fdee0ba..1723f32 100755
--- a/Changes
+++ b/Changes
@@ -1,4 +1,4 @@
-0.43 2021-08-16
+0.43 2021-09-07
         - New menu class that has an entry at the very end,
           similar to the input text prefix,
           that is always available. (lerepp)
@@ -20,6 +20,7 @@
         - New menu class that has a container for further
           entries at the very end that is always available. (lerepp)
         - Fix init of matches.
+        - Fix tests on text method to accept undef for Mojo >= 9.21.
 
 0.42 2021-06-18
         - Added GitHub based CI for perl.
diff --git a/Makefile.PL b/Makefile.PL
index 2ed9908..2613a4a 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -20,7 +20,7 @@
     'Mojolicious::Plugin::TagHelpers::Pagination' => 0.08,
     'Mojolicious::Plugin::TagHelpers::MailToChiffre' => 0.13,
     'Mojolicious::Plugin::ClosedRedirect' => 0.15,
-    'Mojolicious::Plugin::Notifications' => 1.06,
+    'Mojolicious::Plugin::Notifications' => 1.07,
     'Mojolicious::Plugin::MailException' => 0.24,
     'Mojolicious::Plugin::Util::RandomString' => 0.09,
     'Mojolicious::Plugin::CHI' => 0.20,
diff --git a/t/fixtures.t b/t/fixtures.t
index 6508cfc..8a17bd7 100644
--- a/t/fixtures.t
+++ b/t/fixtures.t
@@ -18,28 +18,33 @@
   ->json_is('/errors/0/1',"cosmas3 is not a supported query language!")
   ;
 
-$t->get_ok('/v1.0/search?q=server_fail')
+my $err = $t->get_ok('/v1.0/search?q=server_fail')
   ->status_is(500)
-  ->text_is('#error', '')
   ->content_like(qr!Oooops!)
+  ->tx->res->dom->at('#error')
   ;
+is(defined $err ? $err->text : '', '');
 
-$t->get_ok('/v1.0/search?q=[orth=das&ql=poliqarp&offset=0&count=25')
+$err = $t->get_ok('/v1.0/search?q=[orth=das&ql=poliqarp&offset=0&count=25')
   ->status_is(400)
-  ->text_is('#error', '')
   ->json_is('/errors/0/0',302)
   ->json_is('/errors/0/1','Parantheses/brackets unbalanced.')
   ->json_is('/errors/1/0',302)
   ->json_is('/errors/1/1','Could not parse query >>> [orth=das <<<.')
+  ->tx->res->dom->at('#error')
   ;
+is(defined $err ? $err->text : '', '');
 
-$t->get_ok('/v1.0/search?q=baum&ql=poliqarp&offset=0&count=25')
+
+$err = $t->get_ok('/v1.0/search?q=baum&ql=poliqarp&offset=0&count=25')
   ->status_is(200)
-  ->text_is('#error', '')
   ->json_is('/meta/count', 25)
   ->json_is('/meta/serialQuery', "tokens:s:Baum")
   ->json_is('/matches/0/docSigle', "GOE/AGI")
+  ->tx->res->dom->at('#error')
   ;
+is(defined $err ? $err->text : '', '');
+
 
 $t->get_ok('/v1.0/corpus/WPD15/232/39681/p2133-2134/matchInfo?spans=false&foundry=*')
   ->status_is(200)
diff --git a/t/plugin/auth-oauth.t b/t/plugin/auth-oauth.t
index 33ffafa..cfcfc87 100644
--- a/t/plugin/auth-oauth.t
+++ b/t/plugin/auth-oauth.t
@@ -337,11 +337,10 @@
   ;
 
 # Query without partial cache (unfortunately) (but no total results)
-$t->get_ok('/?q=baum&cutoff=true')
+my $err = $t->get_ok('/?q=baum&cutoff=true')
   ->status_is(200)
   ->session_is('/auth', 'Bearer ' . $access_token_2)
   ->session_is('/auth_r', $refresh_token_2)
-  ->text_is('#error','')
   ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
   ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
   ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]')
@@ -349,7 +348,9 @@
   ->header_isnt('X-Kalamar-Cache', 'true')
   ->content_like(qr!${q}cutOff${q}:true!)
   ->element_exists_not('#total-results')
+  ->tx->res->dom->at('#error')
   ;
+is(defined $err ? $err->text : '', '');
 
 # Expire the session and remove the refresh option
 $t->get_ok('/x/expire-no-refresh')
@@ -367,11 +368,10 @@
 
 # Query without cache
 # The token is invalid and can't be refreshed!
-$t->get_ok('/?q=baum&cutoff=true')
+$err = $t->get_ok('/?q=baum&cutoff=true')
   ->status_is(400)
   ->session_hasnt('/auth')
   ->session_hasnt('/auth_r')
-  ->text_is('#error','')
   ->text_is('div.notify-error','Access token invalid')
   ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
   ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
@@ -379,7 +379,10 @@
   ->content_unlike(qr/${q}authorized${q}:${q}yes${q}/)
   ->header_isnt('X-Kalamar-Cache', 'true')
   ->element_exists('p.no-results')
+  ->tx->res->dom->at('#error')
   ;
+is(defined $err ? $err->text : '', '');
+
 
 $t->get_ok('/x/invalid')
   ->status_is(200)
@@ -388,11 +391,10 @@
 
 # Query without cache
 # The token is invalid and can't be refreshed!
-$t->get_ok('/?q=baum&cutoff=true')
+$err = $t->get_ok('/?q=baum&cutoff=true')
   ->status_is(200)
   ->session_is('/auth', 'Bearer ' . $access_token_2)
   ->session_is('/auth_r', $refresh_token_2)
-  ->text_is('#error','')
   ->element_exists_not('div.notify-error','Access token invalid')
   ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
   ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
@@ -400,7 +402,9 @@
   ->content_like(qr/${q}authorized${q}:${q}yes${q}/)
   ->header_isnt('X-Kalamar-Cache', 'true')
   ->element_exists_not('p.no-results')
+  ->tx->res->dom->at('#error')
   ;
+is(defined $err ? $err->text : '', '');
 
 
 $t->get_ok('/x/expired-with-wrong-refresh')
@@ -410,19 +414,24 @@
 
 
 # The token is invalid and can't be refreshed!
-$csrf = $t->get_ok('/?q=baum&cutoff=true')
+my $dom = $t->get_ok('/?q=baum&cutoff=true')
   ->status_is(400)
   ->session_hasnt('/auth')
   ->session_hasnt('/auth_r')
-  ->text_is('#error','')
   ->text_is('div.notify-error','Refresh token is expired')
   ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
   ->content_unlike(qr/${q}authorized${q}:${q}yes${q}/)
   ->element_exists('p.no-results')
-  ->tx->res->dom->at('input[name="csrf_token"]')
+  ->tx->res->dom;
+
+$csrf = $dom->at('input[name="csrf_token"]')
   ->attr('value')
   ;
 
+$err = $dom->at('#error');
+is(defined $err ? $err->text : '', '');
+
+
 # Login:
 $t->post_ok('/user/login' => form => {
   handle => 'test',
@@ -480,16 +489,17 @@
   ->header_is('Pragma','no-cache')
   ;
 
-$t->get_ok('/settings/oauth')
+my $anchor = $t->get_ok('/settings/oauth')
   ->text_is('.form-table legend', 'Register new client application')
   ->attr_is('.oauth-register','action', '/settings/oauth/register')
   ->text_is('ul.client-list > li > span.client-name a', 'MyApp')
   ->text_is('ul.client-list > li > span.client-desc', 'This is my application')
-  ->text_is('ul.client-list > li > span.client-url a', '')
   ->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate')
   ->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT')
   ->header_is('Pragma','no-cache')
+  ->tx->res->dom->at('ul.client-list > li > span.client-url a')
   ;
+is(defined $anchor ? $anchor->text : '', '');
 
 $t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==')
   ->status_is(200)
diff --git a/t/query.t b/t/query.t
index a2e2f44..1dc3d92 100644
--- a/t/query.t
+++ b/t/query.t
@@ -28,9 +28,8 @@
 my $q = qr!(?:\"|&quot;)!;
 
 # Query passed
-$t->get_ok('/?q=baum')
+my $err = $t->get_ok('/?q=baum')
   ->status_is(200)
-  ->text_is('#error','')
   ->content_type_is('text/html;charset=UTF-8')
 
   ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
@@ -76,7 +75,10 @@
   ->text_is('li:nth-of-type(1) p.ref time[datetime=1982]', 1982)
   ->text_is('li:nth-of-type(1) p.ref span.sigle', '[GOE/AGI/00000]')
   ->header_isnt('X-Kalamar-Cache', 'true')
+  ->tx->res->dom->at('#error')
   ;
+is(defined $err ? $err->text : '', '');
+
 
 $t->get_ok('/?q=[orth=das')
   ->status_is(400)
@@ -95,58 +97,62 @@
 
 
 # Query with partial cache (for total results)
-$t->get_ok('/?q=baum')
+$err = $t->get_ok('/?q=baum')
   ->status_is(200)
-  ->text_is('#error','')
   ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
   ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
   ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]')
   ->header_isnt('X-Kalamar-Cache', 'true')
   ->content_like(qr!${q}cutOff${q}:true!)
   ->text_is('#total-results', 51)
+  ->tx->res->dom->at('#error')
   ;
+is(defined $err ? $err->text : '', '');
 
 # Query without partial cache (unfortunately) (but no total results)
-$t->get_ok('/?q=baum&cutoff=true')
+$err = $t->get_ok('/?q=baum&cutoff=true')
   ->status_is(200)
-  ->text_is('#error','')
   ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
   ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
   ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]')
   ->header_isnt('X-Kalamar-Cache', 'true')
   ->content_like(qr!${q}cutOff${q}:true!)
   ->element_exists_not('#total-results')
+  ->tx->res->dom->at('#error')
   ;
+is(defined $err ? $err->text : '', '');
 
 # Query with partial cache (but no total results)
-$t->get_ok('/?q=baum&cutoff=true')
+$err = $t->get_ok('/?q=baum&cutoff=true')
   ->status_is(200)
-  ->text_is('#error','')
   ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
   ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
   ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]')
   ->header_is('X-Kalamar-Cache', 'true')
   ->content_like(qr!${q}cutOff${q}:true!)
   ->element_exists_not('#total-results')
+  ->tx->res->dom->at('#error')
   ;
+is(defined $err ? $err->text : '', '');
+
 
 # Query with full cache
-$t->get_ok('/?q=baum')
+$err = $t->get_ok('/?q=baum')
   ->status_is(200)
-  ->text_is('#error','')
   ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
   ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
   ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]')
   ->header_is('X-Kalamar-Cache', 'true')
   ->content_like(qr!${q}cutOff${q}:true!)
   ->text_is('#total-results', 51)
+  ->tx->res->dom->at('#error')
   ;
+is(defined $err ? $err->text : '', '');
 
 
 # Query with page information
-$t->get_ok('/?q=der&p=1&count=2')
+$err = $t->get_ok('/?q=der&p=1&count=2')
   ->status_is(200)
-  ->text_is('#error','')
   ->text_is('title', 'KorAP: Find »der« with Poliqarp')
 
   # Total results
@@ -164,7 +170,10 @@
 
   # Not searched for "der" before
   ->content_unlike(qr!${q}cutOff${q}:true!)
+  ->tx->res->dom->at('#error')
   ;
+is(defined $err ? $err->text : '', '');
+
 
 # Check pagination repetion of page
 my $next_href = $t->get_ok('/?q=der&p=1&count=2')
@@ -173,9 +182,8 @@
 unlike($next_href, qr/p=1/);
 
 # Query with page information - next page
-$t->get_ok('/?q=der&p=2&count=2')
+$err = $t->get_ok('/?q=der&p=2&count=2')
   ->status_is(200)
-  ->text_is('#error','')
   ->text_is('title', 'KorAP: Find »der« with Poliqarp')
   ->element_exists('#search')
 
@@ -192,7 +200,10 @@
   # No caching
   ->header_isnt('X-Kalamar-Cache', 'true')
   ->content_like(qr!${q}cutOff${q}:true!)
+  ->tx->res->dom->at('#error')
   ;
+is(defined $err ? $err->text : '', '');
+
 
 # Query with failing parameters
 $t->get_ok('/?q=fantastisch&ql=Fabelsprache')
@@ -214,11 +225,12 @@
 
 # Query too long
 my $long_query = 'b' x 2000;
-$t->get_ok('/?q=' . $long_query)
+$err = $t->get_ok('/?q=' . $long_query)
   ->status_is(400)
-  ->text_is('#error','')
   ->text_like('#notifications div.notify-error', qr!Parameter ".+?" invalid!)
+  ->tx->res->dom->at('#error')
   ;
+is(defined $err ? $err->text : '', '');
 
 # Query with timeout
 $t->get_ok('/?q=timeout')
@@ -245,12 +257,14 @@
 $t->app->defaults(no_cache => 1);
 
 # Query with collection
-$t->get_ok('/?q=baum&collection=availability+%3D+%2FCC-BY.*%2F')
+$err = $t->get_ok('/?q=baum&collection=availability+%3D+%2FCC-BY.*%2F')
   ->status_is(200)
   ->element_exists("input#cq[value='availability = /CC-BY.*/']")
   ->content_like(qr!${q}availability${q}!)
-  ->text_is('#error','')
+  ->tx->res->dom->at('#error')
   ;
+is(defined $err ? $err->text : '', '');
+
 
 $t->app->hook(
   after_search => sub {
@@ -260,13 +274,14 @@
 );
 
 # Query with corpus query
-$t->get_ok('/?q=baum&cq=availability+%3D+%2FCC-BY.*%2F')
+$err = $t->get_ok('/?q=baum&cq=availability+%3D+%2FCC-BY.*%2F')
   ->status_is(200)
   ->element_exists("input#cq[value='availability = /CC-BY.*/']")
   ->content_like(qr!${q}availability${q}!)
-  ->text_is('#error','')
   ->text_is('#special', 'Funny')
+  ->tx->res->dom->at('#error')
   ;
+is(defined $err ? $err->text : '', '');
 
 my $match = {
   matchID => 'match-FOLK/00070-SE-01/T-04-p5441-5442',
@@ -278,11 +293,12 @@
 is($match->{matchID}, 'p5441-5442');
 
 # Query with pipe
-$t->get_ok('/?q=baum&pipe=glemm')
+$err = $t->get_ok('/?q=baum&pipe=glemm')
   ->status_is(200)
-  ->text_is('#error','')
   ->content_like(qr/${q}pipes${q}:${q}glemm${q}/)
+  ->tx->res->dom->at('#error')
   ;
+is(defined $err ? $err->text : '', '');
 
 
 done_testing;