mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Html: Move get_elem_val to xo.elem
This commit is contained in:
@@ -0,0 +1,311 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.catpages; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.core.htmls.*; import gplx.core.intls.ucas.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.fmts.*;
|
||||
public class Xoctg_catpage_mgr__basic__tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoctg_catpage_mgr_fxt fxt = new Xoctg_catpage_mgr_fxt();
|
||||
@Test public void Page_itm() {
|
||||
fxt .Init_itms__pages("A1")
|
||||
.Test__html__page(Xoa_ctg_mgr.Tid__page, Byte_ascii.Ltr_A, "\n <li><a href=\"/wiki/A1\" title=\"A1\">A1</a></li>");
|
||||
}
|
||||
@Test public void Page_itm_missing() {
|
||||
fxt.Init_itms__pages("A1");
|
||||
Xoctg_catpage_itm itm = fxt.Ctg().Grp_by_tid(Xoa_ctg_mgr.Tid__page).Itms__get_at(0);
|
||||
itm.Page_ttl_(Xoa_ttl.Null);
|
||||
itm.Sortkey_handle_make(Bry_bfr_.New(), Bry_.Empty);
|
||||
fxt.Test__html__page(Xoa_ctg_mgr.Tid__page, Byte_ascii.Ltr_A, "\n <li class=\"xowa-missing-category-entry\"><span title=\"id not found: #0 might be talk/user page\">missing page (0)</li>");
|
||||
}
|
||||
@Test public void Visited_doesnt_work_for_space() {// PURPOSE: xowa-visited not inserted for pages with space
|
||||
byte[] page_bry = Bry_.new_a7("A 1");
|
||||
Xoa_url url = Xoa_url.New(Bry_.new_a7("en.wikipedia.org"), page_bry);
|
||||
Xoa_ttl ttl = Xoa_ttl.Parse(fxt.Wiki(), page_bry);
|
||||
fxt.Wiki().Appe().Usere().History_mgr().Add(fxt.Wiki().App(), url, ttl, page_bry);
|
||||
fxt .Init_itms__pages("A_1")
|
||||
.Test__html__all(Xoa_ctg_mgr.Tid__page, String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, "<div id=\"mw-pages\">"
|
||||
, " <h2>Pages in category \"Ctg_1\"</h2>"
|
||||
, " <p>This category contains only the following page.</p>"
|
||||
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
|
||||
, " <table style=\"width: 100%;\">"
|
||||
, " <tr style=\"vertical-align: top;\">"
|
||||
, " <td style=\"width: 33%;\">"
|
||||
, " <h3>A</h3>"
|
||||
, " <ul>"
|
||||
, " <li><a href=\"/wiki/A_1\" class=\"xowa-visited\" title=\"A 1\">A 1</a></li>"
|
||||
, " </ul>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Page_all() {
|
||||
fxt .Init_itms__pages("A1")
|
||||
.Test__html__all(Xoa_ctg_mgr.Tid__page, String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, "<div id=\"mw-pages\">"
|
||||
, " <h2>Pages in category \"Ctg_1\"</h2>"
|
||||
, " <p>This category contains only the following page.</p>"
|
||||
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
|
||||
, " <table style=\"width: 100%;\">"
|
||||
, " <tr style=\"vertical-align: top;\">"
|
||||
, " <td style=\"width: 33%;\">"
|
||||
, " <h3>A</h3>"
|
||||
, " <ul>"
|
||||
, " <li><a href=\"/wiki/A1\" title=\"A1\">A1</a></li>"
|
||||
, " </ul>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void File_all() {
|
||||
fxt .Init_itms__files("File:A1.png")
|
||||
.Test__html__all(Xoa_ctg_mgr.Tid__file, String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, "<div id=\"mw-category-media\">"
|
||||
, " <h2>Media in category \"Ctg_1\"</h2>"
|
||||
, " <p>This category contains only the following file.</p>"
|
||||
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
|
||||
, " <table style=\"width: 100%;\">"
|
||||
, " <tr style=\"vertical-align: top;\">"
|
||||
, " <td style=\"width: 33%;\">"
|
||||
, " <h3>A</h3>"
|
||||
, " <ul>"
|
||||
, " <li><a href=\"/wiki/File:A1.png\" title=\"File:A1.png\">File:A1.png</a></li>"
|
||||
, " </ul>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Subc_all() {
|
||||
fxt .Init_itms__subcs("Category:Subc_1")
|
||||
.Test__html__all(Xoa_ctg_mgr.Tid__subc, String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, "<div id=\"mw-subcategories\">"
|
||||
, " <h2>Subcategories</h2>"
|
||||
, " <p>This category has only the following subcategory.</p>"
|
||||
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
|
||||
, " <table style=\"width: 100%;\">"
|
||||
, " <tr style=\"vertical-align: top;\">"
|
||||
, " <td style=\"width: 33%;\">"
|
||||
, " <h3>S</h3>"
|
||||
, " <ul>"
|
||||
, " <li>"
|
||||
, " <div class=\"CategoryTreeSection\">"
|
||||
, " <div class=\"CategoryTreeItem\">"
|
||||
, " <span class=\"CategoryTreeBullet\">"
|
||||
, " <span class=\"CategoryTreeToggle\" style=\"display: none;\" data-ct-title=\"Subc_1\" title=\"Subc 1\" data-ct-state=\"collapsed\">"
|
||||
, " </span> "
|
||||
, " </span>"
|
||||
, " <a href=\"/wiki/Category:Subc_1\" class=\"CategoryTreeLabel CategoryTreeLabelNs14 CategoryTreeLabelCategory\">Subc 1"
|
||||
, " </a>"
|
||||
, " <span title=\"contains 0 subcategories, 0 pages, and 0 files\" dir=\"ltr\">"
|
||||
, " </span>"
|
||||
, " </div>"
|
||||
, " <div class=\"CategoryTreeChildren\" style=\"display:none\"></div>"
|
||||
, " </div>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Page_all_cols() {
|
||||
fxt.Init_itms__pages("A1", "A2", "A3", "B1", "C1");
|
||||
fxt.Init__grp_max_(6);
|
||||
fxt.Test__html__all(Xoa_ctg_mgr.Tid__page, String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, "<div id=\"mw-pages\">"
|
||||
, " <h2>Pages in category \"Ctg_1\"</h2>"
|
||||
, " <p>The following 5 pages are in this category, out of 5 total.</p>"
|
||||
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
|
||||
, " <table style=\"width: 100%;\">"
|
||||
, " <tr style=\"vertical-align: top;\">"
|
||||
, " <td style=\"width: 33%;\">"
|
||||
, " <h3>A</h3>"
|
||||
, " <ul>"
|
||||
, " <li><a href=\"/wiki/A1\" title=\"A1\">A1</a></li>"
|
||||
, " <li><a href=\"/wiki/A2\" title=\"A2\">A2</a></li>"
|
||||
, " </ul>"
|
||||
, " </td>"
|
||||
, " <td style=\"width: 33%;\">"
|
||||
, " <h3>A cont.</h3>"
|
||||
, " <ul>"
|
||||
, " <li><a href=\"/wiki/A3\" title=\"A3\">A3</a></li>"
|
||||
, " </ul>"
|
||||
, " <h3>B</h3>"
|
||||
, " <ul>"
|
||||
, " <li><a href=\"/wiki/B1\" title=\"B1\">B1</a></li>"
|
||||
, " </ul>"
|
||||
, " </td>"
|
||||
, " <td style=\"width: 33%;\">"
|
||||
, " <h3>C</h3>"
|
||||
, " <ul>"
|
||||
, " <li><a href=\"/wiki/C1\" title=\"C1\">C1</a></li>"
|
||||
, " </ul>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Page__numeric() { // PURPOSE: check numeric sorting; 0, 9, 10; not 0, 10, 9; DATE:2016-10-09
|
||||
fxt.Init_itms__pages("0", "9", "10");
|
||||
fxt.Init__grp_max_(6);
|
||||
fxt.Test__html__all(Xoa_ctg_mgr.Tid__page, String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, "<div id=\"mw-pages\">"
|
||||
, " <h2>Pages in category \"Ctg_1\"</h2>"
|
||||
, " <p>The following 3 pages are in this category, out of 3 total.</p>"
|
||||
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
|
||||
, " <table style=\"width: 100%;\">"
|
||||
, " <tr style=\"vertical-align: top;\">"
|
||||
, " <td style=\"width: 33%;\">"
|
||||
, " <h3>0-9</h3>"
|
||||
, " <ul>"
|
||||
, " <li><a href=\"/wiki/0\" title=\"0\">0</a></li>"
|
||||
, " </ul>"
|
||||
, " </td>"
|
||||
, " <td style=\"width: 33%;\">"
|
||||
, " <h3>0-9 cont.</h3>"
|
||||
, " <ul>"
|
||||
, " <li><a href=\"/wiki/9\" title=\"9\">9</a></li>"
|
||||
, " </ul>"
|
||||
, " </td>"
|
||||
, " <td style=\"width: 33%;\">"
|
||||
, " <h3>0-9 cont.</h3>"
|
||||
, " <ul>"
|
||||
, " <li><a href=\"/wiki/10\" title=\"10\">10</a></li>"
|
||||
, " </ul>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Title__escape_quotes() {// PURPOSE: quotes in title should be escaped; DATE:2015-12-28
|
||||
fxt .Init_itms__pages("A\"1")
|
||||
.Test__html__all(Xoa_ctg_mgr.Tid__page, String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, "<div id=\"mw-pages\">"
|
||||
, " <h2>Pages in category \"Ctg_1\"</h2>"
|
||||
, " <p>This category contains only the following page.</p>"
|
||||
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
|
||||
, " <table style=\"width: 100%;\">"
|
||||
, " <tr style=\"vertical-align: top;\">"
|
||||
, " <td style=\"width: 33%;\">"
|
||||
, " <h3>A</h3>"
|
||||
, " <ul>"
|
||||
, " <li><a href=\"/wiki/A%221\" title=\"A"1\">A"1</a></li>"
|
||||
, " </ul>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Calc_col_len() {
|
||||
fxt.Test__calc_col_len(10, 0, 4); // for 10 items, col 0 has 4 items
|
||||
fxt.Test__calc_col_len(10, 1, 3); // for 10 items, col 1 has 3 items
|
||||
fxt.Test__calc_col_len(10, 2, 3); // for 10 items, col 2 has 3 items
|
||||
fxt.Test__calc_col_len(11, 0, 4);
|
||||
fxt.Test__calc_col_len(11, 1, 4);
|
||||
fxt.Test__calc_col_len(11, 2, 3);
|
||||
fxt.Test__calc_col_len(12, 0, 4);
|
||||
fxt.Test__calc_col_len(12, 1, 4);
|
||||
fxt.Test__calc_col_len(12, 2, 4);
|
||||
}
|
||||
}
|
||||
class Xoctg_catpage_mgr_fxt {
|
||||
private int grp_max;
|
||||
private Uca_ltr_extractor ltr_extractor = new Uca_ltr_extractor(true);
|
||||
public Xoctg_catpage_mgr_fxt Clear() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
ctg_html = wiki.Ctg__catpage_mgr();
|
||||
}
|
||||
ctg = new Xoctg_catpage_ctg(1, Bry_.new_a7("Ctg_1"));
|
||||
grp_max = 3; // default to 3 paer page
|
||||
return this;
|
||||
} private Xoae_app app; private Xoctg_catpage_mgr ctg_html;
|
||||
public void Test__calc_col_len(int grp_len, int col_idx, int expd) {Tfds.Eq(expd, Xoctg_fmt_itm_base.Calc_col_len(grp_len, col_idx, 3));}
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public Xoctg_catpage_ctg Ctg() {return ctg;} private Xoctg_catpage_ctg ctg;
|
||||
public void Init__grp_max_(int v) {this.grp_max = v;}
|
||||
public void Init__prev_hide_y_(byte tid) {ctg.Grp_by_tid(tid).Prev_disable_(true);}
|
||||
public void Init__next_sortkey_(byte tid, String v) {ctg.Grp_by_tid(tid).Next_sortkey_(Bry_.new_u8(v));}
|
||||
public void Test__navlink(boolean next, String ctg_str, String expd) {
|
||||
byte[] actl = ctg_html.Fmt(Xoa_ctg_mgr.Tid__page).Bld_bwd_fwd(wiki, Xoa_ttl.Parse(wiki, Bry_.new_a7(ctg_str)), ctg.Grp_by_tid(Xoa_ctg_mgr.Tid__page), grp_max);
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
|
||||
}
|
||||
public Xoctg_catpage_mgr_fxt Init_itms__pages(String... titles) {return Init_itms(Xoa_ctg_mgr.Tid__page, titles);}
|
||||
public Xoctg_catpage_mgr_fxt Init_itms__files(String... titles) {return Init_itms(Xoa_ctg_mgr.Tid__file, titles);}
|
||||
public Xoctg_catpage_mgr_fxt Init_itms__subcs(String... titles) {return Init_itms(Xoa_ctg_mgr.Tid__subc, titles);}
|
||||
private Xoctg_catpage_mgr_fxt Init_itms(byte tid, String[] ttls) {
|
||||
int len = ttls.length;
|
||||
Xoctg_catpage_tmp tmp = new Xoctg_catpage_tmp();
|
||||
Xoctg_catpage_grp grp = ctg.Grp_by_tid(tid);
|
||||
grp.Count_all_(len);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
byte[] page_ttl_bry = Bry_.new_u8(ttls[i]);
|
||||
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, page_ttl_bry);
|
||||
Xoctg_catpage_itm itm = Xoctg_catpage_itm.New_by_ttl(tid, i, ttl);
|
||||
tmp.Add(itm);
|
||||
}
|
||||
tmp.Make_by_grp(grp);
|
||||
return this;
|
||||
}
|
||||
public void Test__html__page(byte tid, byte grp_char_0, String expd) {
|
||||
Xoctg_fmt_grp list_mgr = ctg_html.Fmt(tid);
|
||||
Xoctg_fmt_itm_base itm_fmt = list_mgr.Itm_fmt();
|
||||
Xoctg_catpage_grp list = ctg.Grp_by_tid(tid);
|
||||
itm_fmt.Init_from_ltr(wiki, list, ltr_extractor);
|
||||
itm_fmt.Set_ltr_and_bgn(new byte[] {grp_char_0}, 0);
|
||||
itm_fmt.Col_end_(0, 0);
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
itm_fmt.Bfr_arg__add(bfr);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_rls());
|
||||
}
|
||||
public void Test__html_grp(byte tid, String expd) {
|
||||
Xoctg_fmt_grp list_mgr = ctg_html.Fmt(tid);
|
||||
Xoctg_fmt_ltr fmtr_grp = new Xoctg_fmt_ltr(list_mgr.Itm_fmt());
|
||||
fmtr_grp.Init_from_grp(wiki, ctg.Grp_by_tid(tid), ltr_extractor);
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
fmtr_grp.Bfr_arg__add(bfr);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_rls());
|
||||
}
|
||||
public void Test__html__all(byte tid, String expd) {
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
ctg_html.Fmt(tid).Write_catpage_grp(bfr, wiki, wiki.Lang(), ltr_extractor, ctg, grp_max);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_rls());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.catpages; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.fmts.*;
|
||||
public class Xoctg_catpage_mgr__navlink__tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoctg_catpage_mgr_fxt fxt = new Xoctg_catpage_mgr_fxt();
|
||||
@Test public void Navlink__basic() {
|
||||
fxt.Init_itms__pages("A2", "A3", "A4");
|
||||
fxt.Init__next_sortkey_(Xoa_ctg_mgr.Tid__page, "A5");
|
||||
fxt.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
|
||||
( ""
|
||||
, "(<a href=\"/wiki/Category:Ctg_1?pageuntil=A2%0AA2#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 3</a>)"
|
||||
, "(<a href=\"/wiki/Category:Ctg_1?pagefrom=A5#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 3</a>)"
|
||||
));
|
||||
}
|
||||
@Test public void Navlink__encoded() { // escape quotes and spaces; DATE:2016-01-11
|
||||
fxt.Init_itms__pages("A\" 2", "A\" 3", "A\" 4");
|
||||
fxt.Init__next_sortkey_(Xoa_ctg_mgr.Tid__page, "A\" 5");
|
||||
fxt.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
|
||||
( ""
|
||||
, "(<a href=\"/wiki/Category:Ctg_1?pageuntil=A%22+2%0AA%22+2#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 3</a>)"
|
||||
, "(<a href=\"/wiki/Category:Ctg_1?pagefrom=A%22+5#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 3</a>)"
|
||||
));
|
||||
}
|
||||
@Test public void Navlink__bos() {
|
||||
fxt.Init_itms__pages("A2", "A3", "A4");
|
||||
fxt.Init__prev_hide_y_(Xoa_ctg_mgr.Tid__page);
|
||||
fxt.Init__next_sortkey_(Xoa_ctg_mgr.Tid__page, "A5");
|
||||
fxt.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
|
||||
( ""
|
||||
, "(previous 3)"
|
||||
, "(<a href=\"/wiki/Category:Ctg_1?pagefrom=A5#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 3</a>)"
|
||||
));
|
||||
}
|
||||
@Test public void Navlink__eos() {
|
||||
fxt.Init_itms__pages("A2", "A3", "A4");
|
||||
fxt.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
|
||||
( ""
|
||||
, "(<a href=\"/wiki/Category:Ctg_1?pageuntil=A2%0AA2#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 3</a>)"
|
||||
, "(next 3)"
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.xowa.apps.urls.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.langs.*;
|
||||
public class Xoctg_catlink_loader__tst {
|
||||
private final Xoctg_catlink_loader__fxt fxt = new Xoctg_catlink_loader__fxt();
|
||||
@Test public void Build_sortkey_val__v4() { // PURPOSE: remove "\n" and afterwards else will omit 1 record
|
||||
fxt.Test__build_sortkey_sql(4, "A\nA", "x'41'"); // fails if "x'410a41'"
|
||||
}
|
||||
@Test public void Build_sortkey_val__v2() { // PURPOSE: remove "\n" and afterwards else SQL will be malformed
|
||||
fxt.Test__build_sortkey_sql(2, "A\nA", "'A'"); // fails if "'A\nA'"
|
||||
}
|
||||
}
|
||||
class Xoctg_catlink_loader__fxt {
|
||||
public void Test__build_sortkey_sql(int version, String sortkey, String expd) {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, "de.wikipedia.org"); // use "de.wikipedia.org" for simple "uppercase" collation
|
||||
Xoctg_collation_mgr collation_mgr = new Xoctg_collation_mgr(wiki);
|
||||
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
Gftest.Eq__str(expd, Xoctg_catlink_loader.Build_sortkey_val(bfr, Byte_.By_int(version), collation_mgr, Bry_.new_u8(sortkey)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xoctg_collation_wkr___tst {
|
||||
private final Xoctg_collation_wkr___fxt fxt = new Xoctg_collation_wkr___fxt();
|
||||
@Test public void Uppercase() {fxt.Test__make("uppercase" , "uppercase");}
|
||||
@Test public void Identity() {fxt.Test__make("identity" , "identity");}
|
||||
@Test public void Unknown() {fxt.Test__make("unknown" , "uppercase");}
|
||||
@Test public void Uca__uca_default() {fxt.Test__make__uca("uca-default" , "en", false);}
|
||||
@Test public void Uca__xx_uca_ckb() {fxt.Test__make__uca("xx-uca-ckb" , "fa", false);}
|
||||
@Test public void Uca__xx_uca_et() {fxt.Test__make__uca("xx-uca-et" , "et", false);}
|
||||
@Test public void Uca__uca_default_u_kn() {fxt.Test__make__uca("uca-default-u-kn" , "en", true);}
|
||||
@Test public void Uca__uca_at_logic() {fxt.Test__make__uca("uca-sv@collation=standard" , "sv", false);}
|
||||
}
|
||||
class Xoctg_collation_wkr___fxt {
|
||||
public void Test__make(String wm_name, String expd_type) {
|
||||
Xoctg_collation_wkr actl = Xoctg_collation_wkr_.Make(null, wm_name);
|
||||
Gftest.Eq__str(expd_type, actl.Type_name());
|
||||
}
|
||||
public void Test__make__uca(String wm_name, String expd_locale, boolean expd_numeric_sorting) {
|
||||
Xoctg_collation_wkr__uca actl = (Xoctg_collation_wkr__uca)Xoctg_collation_wkr_.Make(null, wm_name);
|
||||
Gftest.Eq__str(expd_locale, actl.Icu_locale());
|
||||
Gftest.Eq__bool(expd_numeric_sorting, actl.Numeric_sorting());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.xowa.apps.urls.*;
|
||||
public class Xoctg_catpage_url__tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoctg_catpage_url__fxt fxt = new Xoctg_catpage_url__fxt();
|
||||
@Test public void Specific() {
|
||||
fxt.Exec__parse("A?subcatfrom=B&filefrom=C&pagefrom=D" ).Test__keys("B", "C", "D").Test__fwds(Bool_.Y, Bool_.Y, Bool_.Y);
|
||||
fxt.Exec__parse("A?subcatuntil=B&fileuntil=C&pageuntil=D" ).Test__keys("B", "C", "D").Test__fwds(Bool_.N, Bool_.N, Bool_.N);
|
||||
}
|
||||
@Test public void General() {
|
||||
fxt.Exec__parse("A?from=B" ).Test__keys("B", "B", "B").Test__fwds(Bool_.Y, Bool_.Y, Bool_.Y);
|
||||
fxt.Exec__parse("A?until=B" ).Test__keys("B", "B", "B").Test__fwds(Bool_.N, Bool_.N, Bool_.N);
|
||||
}
|
||||
@Test public void Url_encoded() {
|
||||
fxt.Exec__parse("A?from=B+C").Test__keys("B C", "B C", "B C").Test__fwds(Bool_.Y, Bool_.Y, Bool_.Y);
|
||||
}
|
||||
}
|
||||
class Xoctg_catpage_url__fxt {
|
||||
private Xow_url_parser xo_url_parser; private Xoctg_catpage_url ctg_url;
|
||||
public void Clear() {
|
||||
Xoa_app app = Xoa_app_fxt.Make__app__edit();
|
||||
this.xo_url_parser = app.User().Wikii().Utl__url_parser();
|
||||
}
|
||||
public Xoctg_catpage_url__fxt Exec__parse(String url_str) {
|
||||
Xoa_url page_url = xo_url_parser.Parse(Bry_.new_u8(url_str));
|
||||
this.ctg_url = Xoctg_catpage_url_parser.Parse(page_url);
|
||||
return this;
|
||||
}
|
||||
public Xoctg_catpage_url__fxt Test__keys(String... expd) {Gftest.Eq__ary(Bry_.Ary(expd), ctg_url.Grp_keys(), "keys"); return this;}
|
||||
public Xoctg_catpage_url__fxt Test__fwds(boolean... expd) {Gftest.Eq__ary(expd, ctg_url.Grp_fwds(), "fwds"); return this;}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.doubles; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xoctg_double_box__tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoctg_double_box__fxt fxt = new Xoctg_double_box__fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Init_ctg_hidden("Category:A", "Category:B", "Category:C");
|
||||
fxt.Init_ctg_normal("Category:D", "Category:E", "Category:F");
|
||||
fxt.Test_print_hidden(String_.Concat_lines_nl
|
||||
( "<div id=\"catlinks\" class=\"catlinks\">"
|
||||
, "<div id=\"mw-normal-catlinks\" class=\"mw-normal-catlinks\">"
|
||||
, "<a href=\"/wiki/Special:Categories\" title=\"Special:Categories\">Categories</a>:"
|
||||
, "<ul>"
|
||||
, "<li>"
|
||||
, "<a href=\"/wiki/Category:D\" title=\"Category:D\">D</a>"
|
||||
, "</li>"
|
||||
, "<li>"
|
||||
, "<a href=\"/wiki/Category:E\" title=\"Category:E\">E</a>"
|
||||
, "</li>"
|
||||
, "<li>"
|
||||
, "<a href=\"/wiki/Category:F\" title=\"Category:F\">F</a>"
|
||||
, "</li>"
|
||||
, "</ul>"
|
||||
, "</div>"
|
||||
, "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks mw-hidden-cats-user-shown\">Hidden categories:"
|
||||
, "<ul>"
|
||||
, "<li>"
|
||||
, "<a href=\"/wiki/Category:A\" title=\"Category:A\">A</a>"
|
||||
, "</li>"
|
||||
, "<li>"
|
||||
, "<a href=\"/wiki/Category:B\" title=\"Category:B\">B</a>"
|
||||
, "</li>"
|
||||
, "<li>"
|
||||
, "<a href=\"/wiki/Category:C\" title=\"Category:C\">C</a>"
|
||||
, "</li>"
|
||||
, "</ul>"
|
||||
, "</div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xoctg_double_box__fxt {
|
||||
private Xop_fxt fxt; private Xoctg_double_box hidden_wtr;
|
||||
private final List_adp init_ctgs = List_adp_.New();
|
||||
public void Clear() {
|
||||
fxt = new Xop_fxt();
|
||||
hidden_wtr = new Xoctg_double_box();
|
||||
hidden_wtr.Init_by_wiki(fxt.Wiki());
|
||||
init_ctgs.Clear();
|
||||
}
|
||||
public void Init_ctg_normal(String... ary) {Init_ctg(Bool_.N, ary);}
|
||||
public void Init_ctg_hidden(String... ary) {Init_ctg(Bool_.Y, ary);}
|
||||
public void Init_ctg(boolean hidden, String[] ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xoa_ttl ttl = fxt.Wiki().Ttl_parse(Bry_.new_u8(ary[i]));
|
||||
Xoctg_pagebox_itm itm = Xoctg_pagebox_itm.New_by_ttl(ttl);
|
||||
itm.Load_by_cat_core(hidden, 0, 0, 0);
|
||||
init_ctgs.Add_many(itm);
|
||||
}
|
||||
}
|
||||
public void Test_print_hidden(String expd) {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
Xoctg_pagebox_itm[] ary = (Xoctg_pagebox_itm[])init_ctgs.To_ary_and_clear(Xoctg_pagebox_itm.class);
|
||||
hidden_wtr.Write_pagebox(bfr, ary);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.singles; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.htmls.core.htmls.*;
|
||||
public class Xoctg_single_box__tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xoh_ctg_mgr_fxt fxt = new Xoh_ctg_mgr_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Init__ctgs("Category:A", "Category:B").Test_html(String_.Concat_lines_nl
|
||||
( "<div id=\"catlinks\" class=\"catlinks\">"
|
||||
, "<div id=\"mw-normal-catlinks\" class=\"mw-normal-catlinks\">"
|
||||
, "Categories"
|
||||
, "<ul>"
|
||||
, "<li>"
|
||||
, "<a href=\"/wiki/Category:A\" class=\"internal\" title=\"A\">A</a>"
|
||||
, "</li>"
|
||||
, "<li>"
|
||||
, "<a href=\"/wiki/Category:B\" class=\"internal\" title=\"B\">B</a>"
|
||||
, "</li>"
|
||||
, "</ul>"
|
||||
, "</div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xoh_ctg_mgr_fxt {
|
||||
private Xoctg_single_box ctg_grp_mgr; Xoae_app app; Xowe_wiki wiki; Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
private Xoae_page page;
|
||||
public void Clear() {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
page = wiki.Parser_mgr().Ctx().Page();
|
||||
ctg_grp_mgr = new Xoctg_single_box();
|
||||
ctg_grp_mgr.Init_by_wiki(wiki);
|
||||
}
|
||||
public Xoh_ctg_mgr_fxt Init__ctgs(String... ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
page.Wtxt().Ctgs__add(wiki.Ttl_parse(Bry_.new_u8(ary[i])));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public void Test_html(String expd) {
|
||||
ctg_grp_mgr.Write_pagebox(tmp_bfr, Xoctg_pagebox_itm.New_ary(page));
|
||||
Tfds.Eq_str_lines(expd, tmp_bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user