Bugzilla – Attachment 189603 Details for
Bug 41247
ILL batches modal does not reset correctly
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 41247: Preparation: Cypress plugins
Bug-41247-Preparation-Cypress-plugins.patch (text/plain), 4.48 KB, created by
Pedro Amorim
on 2025-11-14 13:44:28 UTC
(
hide
)
Description:
Bug 41247: Preparation: Cypress plugins
Filename:
MIME Type:
Creator:
Pedro Amorim
Created:
2025-11-14 13:44:28 UTC
Size:
4.48 KB
patch
obsolete
>From 730635a4c1a7f6012bc671167a9cbc34aee600d6 Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@openfifth.co.uk> >Date: Fri, 14 Nov 2025 13:42:53 +0000 >Subject: [PATCH] Bug 41247: Preparation: Cypress plugins > >1) Add a way to access and manipulate koha-conf.xml (we need to ensure plugins_restricted is 0 for the actual tests) >2) Add a way to set sys prefs. This could be helpful as just an SQL query isn't enough, a flush_memcached is required for the sys pref change to be picked up >--- > t/cypress/plugins/db.js | 14 ++++++++++- > t/cypress/plugins/index.js | 10 ++++++-- > t/cypress/plugins/xml.js | 50 ++++++++++++++++++++++++++++++++++++++ > 3 files changed, 71 insertions(+), 3 deletions(-) > create mode 100644 t/cypress/plugins/xml.js > >diff --git a/t/cypress/plugins/db.js b/t/cypress/plugins/db.js >index 92f5234d460..d81482a911b 100644 >--- a/t/cypress/plugins/db.js >+++ b/t/cypress/plugins/db.js >@@ -9,6 +9,7 @@ > */ > > const mysql = require("mysql2/promise"); >+const { exec } = require("child_process"); > > /** > * Database connection configuration >@@ -63,4 +64,15 @@ async function query(sql, params = []) { > return rows; > } > >-module.exports = { query }; >+async function set_syspref({ variable, value }) { >+ await query("UPDATE systempreferences SET value = ? WHERE variable = ?", [ >+ value, >+ variable, >+ ]).then(() => { >+ exec("flush_memcached"); >+ return 1; >+ }); >+ return 0; >+} >+ >+module.exports = { query, set_syspref }; >diff --git a/t/cypress/plugins/index.js b/t/cypress/plugins/index.js >index 5970890dc02..e724b525ed1 100644 >--- a/t/cypress/plugins/index.js >+++ b/t/cypress/plugins/index.js >@@ -24,7 +24,9 @@ const { > > const { getBasicAuthHeader } = require("./auth.js"); > >-const { query } = require("./db.js"); >+const { query, set_syspref } = require("./db.js"); >+ >+const { modifyXmlElement, readXmlElementValue } = require("./xml.js"); > > const { apiGet, apiPost, apiPut, apiDelete } = require("./api-client.js"); > >@@ -50,8 +52,9 @@ const { apiGet, apiPost, apiPut, apiDelete } = require("./api-client.js"); > * - Data Insertion: insertSampleBiblio, insertSampleHold, insertSampleCheckout, insertSamplePatron > * - Data Cleanup: deleteSampleObjects > * - API Access: apiGet, apiPost, apiPut, apiDelete >- * - Database Access: query >+ * - Database Access: query, set_syspref > * - Authentication: getBasicAuthHeader >+ * - XML files Access: modifyXmlElement, readXmlElementValue > * > * @example > * // Usage in Cypress tests >@@ -104,6 +107,9 @@ module.exports = (on, config) => { > }, > deleteSampleObjects, > query, >+ set_syspref, >+ modifyXmlElement, >+ readXmlElementValue, > > apiGet(args) { > return apiGet({ ...args, baseUrl, authHeader }); >diff --git a/t/cypress/plugins/xml.js b/t/cypress/plugins/xml.js >new file mode 100644 >index 00000000000..d1e304f95d7 >--- /dev/null >+++ b/t/cypress/plugins/xml.js >@@ -0,0 +1,50 @@ >+const fs = require("fs"); >+const path = require("path"); >+const { exec } = require("child_process"); >+const { promisify } = require("util"); >+const execPromise = promisify(exec); >+ >+async function modifyXmlElement({ filePath, element, value }) { >+ const targetPath = path.resolve(filePath); >+ let xmlContent; >+ >+ try { >+ xmlContent = fs.readFileSync(targetPath, "utf8"); >+ const regex = new RegExp(`<${element}>[^<]*</${element}>`, "i"); >+ const replacement = `<${element}>${value}</${element}>`; >+ >+ if (!regex.test(xmlContent)) { >+ throw new Error(`Element <${element}> not found in ${targetPath}`); >+ } >+ >+ const newContent = xmlContent.replace(regex, replacement); >+ fs.writeFileSync(targetPath, newContent, "utf8"); >+ >+ await execPromise("koha-plack --restart kohadev"); >+ return null; >+ } catch (err) { >+ return err.message; >+ } >+} >+ >+async function readXmlElementValue({ filePath, element }) { >+ const targetPath = path.resolve(filePath); >+ let xmlContent; >+ >+ try { >+ xmlContent = fs.readFileSync(targetPath, "utf8"); >+ const regex = new RegExp(`<${element}>([^<]*)</${element}>`, "i"); >+ const match = xmlContent.match(regex); >+ >+ if (!match) { >+ throw new Error(`Element <${element}> not found in ${targetPath}`); >+ } >+ >+ // Return the value of the element >+ return match[1]; // match[1] contains the value between the tags >+ } catch (err) { >+ return err.message; >+ } >+} >+ >+module.exports = { readXmlElementValue, modifyXmlElement }; >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 41247
:
189572
|
189603
|
189604
|
189607
|
189608
|
189609
|
189618
|
190903
|
190904
|
190905