From 956289d9f8b32f8952487277c00317f8875aab6b Mon Sep 17 00:00:00 2001
From: Veloman Yunkan
Date: Sat, 26 Nov 2022 11:58:27 +0400
Subject: [PATCH 1/2] Introduced a fake language for i18n testing
We need a fake language for tests that won't be affected by
modifications made by 3rd party translators (see kiwix/libkiwix#749).
- static/i18n/hy.json was cloned as static/i18n/test.json
- usage of "hy" in unit-tests was replaced with "test"
---
static/i18n/test.json | 20 ++++++++++++++++++++
static/i18n_resources_list.txt | 1 +
test/server.cpp | 18 +++++++++---------
3 files changed, 30 insertions(+), 9 deletions(-)
create mode 100644 static/i18n/test.json
diff --git a/static/i18n/test.json b/static/i18n/test.json
new file mode 100644
index 000000000..decb1845f
--- /dev/null
+++ b/static/i18n/test.json
@@ -0,0 +1,20 @@
+{
+ "@metadata": {
+ "authors": [
+ "Kareyac"
+ ]
+ },
+ "name": "Հայերեն",
+ "suggest-full-text-search": "որոնել '{{{SEARCH_TERMS}}}'...",
+ "no-such-book": "Գիրքը բացակայում է՝ {{BOOK_NAME}}",
+ "url-not-found": "Սխալ հասցե՝ {{url}}",
+ "suggest-search": "Որոնել {{PATTERN}}",
+ "400-page-title": "Անվավեր հարցում",
+ "400-page-heading": "Անվավեր հարցում",
+ "404-page-title": "Սխալ հասցե",
+ "404-page-heading": "Սխալ հասցե",
+ "library-button-text": "Գրադարանի էջ",
+ "home-button-text": "Դեպի '{{BOOK_TITLE}}'֊ի գլխավոր էջը",
+ "random-page-button-text": "Բացել պատահական էջ",
+ "searchbox-tooltip": "Որոնել '{{BOOK_TITLE}}'֊ում"
+}
diff --git a/static/i18n_resources_list.txt b/static/i18n_resources_list.txt
index 48bf7cb83..9cc231af7 100644
--- a/static/i18n_resources_list.txt
+++ b/static/i18n_resources_list.txt
@@ -16,6 +16,7 @@ i18n/ru.json
i18n/sc.json
i18n/sk.json
i18n/sv.json
+i18n/test.json
i18n/tr.json
i18n/zh-hans.json
i18n/zh-hant.json
diff --git a/test/server.cpp b/test/server.cpp
index 76541d0b3..ff5f220aa 100644
--- a/test/server.cpp
+++ b/test/server.cpp
@@ -611,7 +611,7 @@ TEST_F(ServerTest, Http404HtmlError)
)" },
- { /* url */ "/ROOT/random?content=non-existent-book&userlang=hy",
+ { /* url */ "/ROOT/random?content=non-existent-book&userlang=test",
expected_page_title=="Սխալ հասցե" &&
expected_body==R"(
Սխալ հասցե
@@ -636,7 +636,7 @@ TEST_F(ServerTest, Http404HtmlError)
)" },
- { /* url */ "/ROOT/catalog/?userlang=hy",
+ { /* url */ "/ROOT/catalog/?userlang=test",
expected_page_title=="Սխալ հասցե" &&
expected_body==R"(
Սխալ հասցե
@@ -653,7 +653,7 @@ TEST_F(ServerTest, Http404HtmlError)
)" },
- { /* url */ "/ROOT/catalog/invalid_endpoint?userlang=hy",
+ { /* url */ "/ROOT/catalog/invalid_endpoint?userlang=test",
expected_page_title=="Սխալ հասցե" &&
expected_body==R"(
Սխալ հասցե
@@ -710,7 +710,7 @@ TEST_F(ServerTest, Http404HtmlError)
)" },
- { /* url */ "/ROOT/content/zimfile/invalid-article?userlang=hy",
+ { /* url */ "/ROOT/content/zimfile/invalid-article?userlang=test",
expected_page_title=="Սխալ հասցե" &&
book_name=="zimfile" &&
book_title=="Ray Charles" &&
@@ -1001,7 +1001,7 @@ TEST_F(ServerTest, UserLanguageControl)
/* expected */ "Not Found"
},
{
- /*url*/ "/ROOT/content/zimfile/invalid-article?userlang=hy",
+ /*url*/ "/ROOT/content/zimfile/invalid-article?userlang=test",
/*Accept-Language:*/ "",
/* expected */ "Սխալ հասցե"
},
@@ -1012,13 +1012,13 @@ TEST_F(ServerTest, UserLanguageControl)
},
{
/*url*/ "/ROOT/content/zimfile/invalid-article",
- /*Accept-Language:*/ "hy",
+ /*Accept-Language:*/ "test",
/* expected */ "Սխալ հասցե"
},
{
// userlang query parameter takes precedence over Accept-Language
/*url*/ "/ROOT/content/zimfile/invalid-article?userlang=en",
- /*Accept-Language:*/ "hy",
+ /*Accept-Language:*/ "test",
/* expected */ "Not Found"
},
{
@@ -1026,7 +1026,7 @@ TEST_F(ServerTest, UserLanguageControl)
// In case of a comma separated list of languages (optionally weighted
// with quality values) the default (en) language is used instead.
/*url*/ "/ROOT/content/zimfile/invalid-article",
- /*Accept-Language:*/ "hy;q=0.9, en;q=0.2",
+ /*Accept-Language:*/ "test;q=0.9, en;q=0.2",
/* expected */ "Not Found"
},
};
@@ -1542,7 +1542,7 @@ R"EXPECTEDRESPONSE([
]
)EXPECTEDRESPONSE"
},
- { /* url: */ "/ROOT/suggest?content=zimfile&term=abracadabra&userlang=hy",
+ { /* url: */ "/ROOT/suggest?content=zimfile&term=abracadabra&userlang=test",
R"EXPECTEDRESPONSE([
{
"value" : "abracadabra ",
From 160c95e317fa5447333c638e53e593be659606f7 Mon Sep 17 00:00:00 2001
From: Veloman Yunkan
Date: Fri, 25 Nov 2022 14:05:55 +0400
Subject: [PATCH 2/2] Fake language for testing is now based on English
Usage of non-latin scripts in unit-tests creates unnecessary problems
for maintainers.
---
static/i18n/test.json | 26 +++++++++++++-------------
test/server.cpp | 32 ++++++++++++++++----------------
2 files changed, 29 insertions(+), 29 deletions(-)
diff --git a/static/i18n/test.json b/static/i18n/test.json
index decb1845f..a96eac241 100644
--- a/static/i18n/test.json
+++ b/static/i18n/test.json
@@ -4,17 +4,17 @@
"Kareyac"
]
},
- "name": "Հայերեն",
- "suggest-full-text-search": "որոնել '{{{SEARCH_TERMS}}}'...",
- "no-such-book": "Գիրքը բացակայում է՝ {{BOOK_NAME}}",
- "url-not-found": "Սխալ հասցե՝ {{url}}",
- "suggest-search": "Որոնել {{PATTERN}}",
- "400-page-title": "Անվավեր հարցում",
- "400-page-heading": "Անվավեր հարցում",
- "404-page-title": "Սխալ հասցե",
- "404-page-heading": "Սխալ հասցե",
- "library-button-text": "Գրադարանի էջ",
- "home-button-text": "Դեպի '{{BOOK_TITLE}}'֊ի գլխավոր էջը",
- "random-page-button-text": "Բացել պատահական էջ",
- "searchbox-tooltip": "Որոնել '{{BOOK_TITLE}}'֊ում"
+ "name": "Fake language for i18n testing"
+ , "suggest-full-text-search": "[I18N TESTING] cOnTaInInG '{{{SEARCH_TERMS}}}'..."
+ , "no-such-book": "[I18N TESTING] No such book: {{BOOK_NAME}}. Sorry."
+ , "url-not-found": "[I18N TESTING] URL not found: {{url}}"
+ , "suggest-search": "[I18N TESTING] Make a full text search for {{PATTERN}}"
+ , "400-page-title": "[I18N TESTING] Invalid request ($400 fine must be paid)"
+ , "400-page-heading": "[I18N TESTING] -400 karma for an invalid request"
+ , "404-page-title": "[I18N TESTING] Not Found - Try Again"
+ , "404-page-heading": "[I18N TESTING] Content not found, but at least the server is alive"
+ , "library-button-text": "[I18N TESTING] Navigate to the welcome page"
+ , "home-button-text": "[I18N TESTING] Jump to the main page of '{{BOOK_TITLE}}'"
+ , "random-page-button-text": "[I18N TESTING] I am tired of determinism"
+ , "searchbox-tooltip": "[I18N TESTING] Let's search in '{{BOOK_TITLE}}'"
}
diff --git a/test/server.cpp b/test/server.cpp
index ff5f220aa..3d4cf7581 100644
--- a/test/server.cpp
+++ b/test/server.cpp
@@ -612,11 +612,11 @@ TEST_F(ServerTest, Http404HtmlError)
)" },
{ /* url */ "/ROOT/random?content=non-existent-book&userlang=test",
- expected_page_title=="Սխալ հասցե" &&
+ expected_page_title=="[I18N TESTING] Not Found - Try Again" &&
expected_body==R"(
- Սխալ հասցե
+ [I18N TESTING] Content not found, but at least the server is alive
- Գիրքը բացակայում է՝ non-existent-book
+ [I18N TESTING] No such book: non-existent-book. Sorry.
)" },
@@ -637,11 +637,11 @@ TEST_F(ServerTest, Http404HtmlError)
)" },
{ /* url */ "/ROOT/catalog/?userlang=test",
- expected_page_title=="Սխալ հասցե" &&
+ expected_page_title=="[I18N TESTING] Not Found - Try Again" &&
expected_body==R"(
- Սխալ հասցե
+ [I18N TESTING] Content not found, but at least the server is alive
- Սխալ հասցե՝ /ROOT/catalog/
+ [I18N TESTING] URL not found: /ROOT/catalog/
)" },
@@ -654,11 +654,11 @@ TEST_F(ServerTest, Http404HtmlError)
)" },
{ /* url */ "/ROOT/catalog/invalid_endpoint?userlang=test",
- expected_page_title=="Սխալ հասցե" &&
+ expected_page_title=="[I18N TESTING] Not Found - Try Again" &&
expected_body==R"(
- Սխալ հասցե
+ [I18N TESTING] Content not found, but at least the server is alive
- Սխալ հասցե՝ /ROOT/catalog/invalid_endpoint
+ [I18N TESTING] URL not found: /ROOT/catalog/invalid_endpoint
)" },
@@ -711,16 +711,16 @@ TEST_F(ServerTest, Http404HtmlError)
)" },
{ /* url */ "/ROOT/content/zimfile/invalid-article?userlang=test",
- expected_page_title=="Սխալ հասցե" &&
+ expected_page_title=="[I18N TESTING] Not Found - Try Again" &&
book_name=="zimfile" &&
book_title=="Ray Charles" &&
expected_body==R"(
- Սխալ հասցե
+ [I18N TESTING] Content not found, but at least the server is alive
- Սխալ հասցե՝ /ROOT/content/zimfile/invalid-article
+ [I18N TESTING] URL not found: /ROOT/content/zimfile/invalid-article
- Որոնել invalid-article
+ [I18N TESTING] Make a full text search for invalid-article
)" },
@@ -1003,7 +1003,7 @@ TEST_F(ServerTest, UserLanguageControl)
{
/*url*/ "/ROOT/content/zimfile/invalid-article?userlang=test",
/*Accept-Language:*/ "",
- /* expected */ "Սխալ հասցե"
+ /* expected */ "[I18N TESTING] Content not found, but at least the server is alive"
},
{
/*url*/ "/ROOT/content/zimfile/invalid-article",
@@ -1013,7 +1013,7 @@ TEST_F(ServerTest, UserLanguageControl)
{
/*url*/ "/ROOT/content/zimfile/invalid-article",
/*Accept-Language:*/ "test",
- /* expected */ "Սխալ հասցե"
+ /* expected */ "[I18N TESTING] Content not found, but at least the server is alive"
},
{
// userlang query parameter takes precedence over Accept-Language
@@ -1546,7 +1546,7 @@ R"EXPECTEDRESPONSE([
R"EXPECTEDRESPONSE([
{
"value" : "abracadabra ",
- "label" : "որոնել 'abracadabra'...",
+ "label" : "[I18N TESTING] cOnTaInInG 'abracadabra'...",
"kind" : "pattern"
//EOLWHITESPACEMARKER
}