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 ed2a68c..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,31 +49,53 @@ 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 } } );
-    my $password = Koha::AuthUtils::generate_password();
+    my $password = Koha::AuthUtils::generate_password($patron->category);
     t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 );
     $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" );
 
@@ -88,18 +110,18 @@ subtest 'OPAC - Remove from cart' => sub {
     my $biblionumber3 = $checkboxes[2]->get_value();
     my $biblionumber5 = $checkboxes[4]->get_value();
 
-    $driver->find_element('//a[@class="btn btn-link addtocart cart cart'.$biblionumber1.'"]')->click;
+    $driver->find_element('//a[@class="btn btn-link btn-sm addtocart cart cart'.$biblionumber1.'"]')->click;
     my $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
     is( $basket_count_elt->get_text(),
         1, 'One element should have been added to the cart' );
 
-    $driver->find_element('//a[@class="btn btn-link addtocart cart cart'.$biblionumber3.'"]')->click;
-    $driver->find_element('//a[@class="btn btn-link addtocart cart cart'.$biblionumber5.'"]')->click;
+    $driver->find_element('//a[@class="btn btn-link btn-sm addtocart cart cart'.$biblionumber3.'"]')->click;
+    $driver->find_element('//a[@class="btn btn-link btn-sm addtocart cart cart'.$biblionumber5.'"]')->click;
     $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
     is( $basket_count_elt->get_text(),
         3, '3 elements should have been added to the cart' );
 
-    $driver->find_element('//a[@class="btn btn-link remove cartRemove cartR'.$biblionumber3.'"]')->click;
+    $driver->find_element('//a[@class="btn btn-link btn-sm remove cartRemove cartR'.$biblionumber3.'"]')->click;
     $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
     is( $basket_count_elt->get_text(),
         2, '1 element should have been removed from the cart' );
@@ -139,17 +161,10 @@ subtest 'Display circulation table correctly' => sub {
     );
 
     my ( $biblionumber, $biblioitemnumber ) = add_biblio();
-    my $item = $builder->build_object(
+    my $item = $builder->build_sample_item(
         {
-            class => 'Koha::Items',
-            value => {
-                biblionumber  => $biblionumber,
-                homebranch    => $library->branchcode,
-                holdingbranch => $library->branchcode,
-                notforloan    => 0,
-                itemlost      => 0,
-                withdrawn     => 0,
-            }
+            biblionumber => $biblionumber,
+            library      => $library->branchcode,
         }
     );
     my $context = Test::MockModule->new('C4::Context');
@@ -175,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;
@@ -190,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;
 };
 
@@ -212,7 +227,7 @@ subtest 'XSS vulnerabilities in pagination' => sub {
         );
     }
 
-    my $password = Koha::AuthUtils::generate_password();
+    my $password = Koha::AuthUtils::generate_password($patron->category);
     t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 );
     $patron->set_password({ password => $password });
     $s->opac_auth( $patron->userid, $password );
@@ -238,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 {