Bug 27797: (QA follow-up) Make tests more robust
[srvgit] / t / db_dependent / selenium / regressions.t
old mode 100644 (file)
new mode 100755 (executable)
index 98fcf09..df6f8b8
@@ -19,7 +19,7 @@ use Modern::Perl;
 
 use C4::Context;
 
-use Test::More tests => 5;
+use Test::More tests => 6;
 use Test::MockModule;
 
 use C4::Context;
@@ -49,8 +49,8 @@ my $AudioAlerts_value = C4::Context->preference('AudioAlerts');
 C4::Context->set_preference('AudioAlerts', '1');
 
 our @cleanup;
-subtest 'OPAC - borrowernumber and branchcode as html attributes' => sub {
-    plan tests => 2;
+subtest 'OPAC - borrowernumber, branchcode and categorycode as html attributes' => sub {
+    plan tests => 3;
 
     my $patron = $builder->build_object(
         { class => 'Koha::Patrons', value => { flags => 1 } } );
@@ -59,21 +59,43 @@ subtest 'OPAC - borrowernumber and branchcode as html attributes' => sub {
     $patron->set_password({ password => $password });
     $s->opac_auth( $patron->userid, $password );
     my $elt = $driver->find_element('//span[@class="loggedinusername"]');
-    is( $elt->get_attribute('data-branchcode'), $patron->library->branchcode,
+    is( $elt->get_attribute('data-branchcode', 1), $patron->library->branchcode,
         "Since bug 20921 span.loggedinusername should contain data-branchcode"
+        # No idea why we need the second param of get_attribute(). As
+        # data-branchcode is still there after page finished loading.
     );
-    is( $elt->get_attribute('data-borrowernumber'), $patron->borrowernumber,
+    is( $elt->get_attribute('data-borrowernumber', 1), $patron->borrowernumber,
 "Since bug 20921 span.loggedinusername should contain data-borrowernumber"
     );
+    is( $elt->get_attribute('data-categorycode', 1), $patron->categorycode,
+"Since bug 26847 span.loggedinusername should contain data-categorycode"
+    );
     push @cleanup, $patron, $patron->category, $patron->library;
 };
 
+subtest 'OPAC - Bibliographic record detail page must contain the data-biblionumber' => sub {
+    plan tests => 1;
+
+    my $builder = t::lib::TestBuilder->new;
+
+    my ( $biblionumber, $biblioitemnumber ) = add_biblio();
+    my $biblio = Koha::Biblios->find($biblionumber);
+
+    $driver->get( $opac_base_url . "opac-detail.pl?biblionumber=$biblionumber" );
+
+    my $elt = $driver->find_element('//div[@id="catalogue_detail_biblio"]');
+    is( $elt->get_attribute( 'data-biblionumber', 1 ),
+        $biblionumber, "#catalogue_detail_biblio contains data-biblionumber" );
+
+    push @cleanup, $biblio;
+  };
+
 subtest 'OPAC - Remove from cart' => sub {
     plan tests => 4;
-   
+
     # We need to prevent scrolling to prevent the floating toolbar from overlapping buttons we are testing
     my $window_size = $driver->get_window_size();
-    $driver->set_window_size(1920,1080);
+    $driver->set_window_size(1920,10800);
 
     $driver->get( $opac_base_url . "opac-search.pl?q=d" );
 
@@ -168,11 +190,11 @@ subtest 'Display circulation table correctly' => sub {
 
     my @thead_th = $driver->find_elements('//table[@id="issues-table"]/thead/tr/th');
     my $thead_length = 0;
-    $thead_length += $_->get_attribute('colspan') || 0 for @thead_th;
+    $thead_length += $_->get_attribute('colspan', 1) || 0 for @thead_th;
 
     my @tfoot_td = $driver->find_elements('//table[@id="issues-table"]/tfoot/tr/td');
     my $tfoot_length = 0;
-    $tfoot_length += $_->get_attribute('colspan') || 0 for @tfoot_td;
+    $tfoot_length += $_->get_attribute('colspan', 1) || 0 for @tfoot_td;
 
     my @tbody_td = $driver->find_elements('//table[@id="issues-table"]/tbody/tr[2]/td');
     my $tbody_length = 0;
@@ -183,7 +205,7 @@ subtest 'Display circulation table correctly' => sub {
       or diag(
         "thead: $thead_length ; tfoot: $tfoot_length ; tbody: $tbody_length");
 
-    push @cleanup, $patron->checkouts, $item->biblio, $item, $patron,
+    push @cleanup, $patron->checkouts, $item, $item->biblio, $patron,
       $patron->category, $library;
 };
 
@@ -231,6 +253,8 @@ subtest 'XSS vulnerabilities in pagination' => sub {
     like( $second_page->get_attribute('href'), qr{category=2%22%3E%3Cscript%3Ealert%28%27booh%21%27%29%3C%2Fscript%3E}, 'The second page should display the variables and attributes correctly URI escaped' );
 
     push @cleanup, $patron, $patron->category, $patron->library;
+
+    $driver->quit();
 };
 
 END {