From c9e9075c6a450c3269218848269319e5a7b9c1d1 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Thu, 18 Oct 2018 20:06:07 -0300
Subject: [PATCH] Bug 21613: Turn strict SQL modes on for tests

This patch will turn the strict SQL modes on When tests are ran with prove.

Test plan:
- Apply the first patch
- prove t/db_dependent/Koha/Database.t
=> Will pass if you have <strict_sql_modes>1</strict_sql_modes> in your
koha-conf.xml
=> Will fail otherwise
- Apply the second patch
- prove t/db_dependent/Koha/Database.t
=> Will pass whatever the value of strict_sql_modes in your
koha-conf.xml
---
 Koha/Database.pm | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Koha/Database.pm b/Koha/Database.pm
index 56ffc46488..1da498fee4 100644
--- a/Koha/Database.pm
+++ b/Koha/Database.pm
@@ -76,10 +76,10 @@ sub _new_schema {
         %encoding_attr = ( mysql_enable_utf8 => 1 );
         $encoding_query = "set NAMES 'utf8mb4'";
         $tz_query = qq(SET time_zone = "$tz") if $tz;
-        unless ( C4::Context->config('strict_sql_modes') ) {
-            $sql_mode_query = q{SET sql_mode = 'IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'};
-        } else {
+        if ( $ENV{_} =~ m|prove| or C4::Context->config('strict_sql_modes') ) {
             $sql_mode_query = q{SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'};
+        } else {
+            $sql_mode_query = q{SET sql_mode = 'IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'};
         }
     }
     elsif ( $db_driver eq 'Pg' ) {
-- 
2.11.0