Skip to content

Commit

Permalink
XWIKI-22580: New release input fields have no text alternative (#3580) (
Browse files Browse the repository at this point in the history
#3830)

(cherry picked from commit d3227ee)

Co-authored-by: LucasC <lucas.charpentier@xwiki.com>
  • Loading branch information
github-actions[bot] and Sereza7 authored Jan 23, 2025
1 parent 60f0924 commit ea922e7
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ public void displayCustom(StringBuffer buffer, String fieldName, String prefix,
ScriptContext.ENGINE_SCOPE);
scontext.setAttribute("object", new com.xpn.xwiki.api.Object(object, context), ScriptContext.ENGINE_SCOPE);
scontext.setAttribute("type", type, ScriptContext.ENGINE_SCOPE);
// This is a text alternative fallback to explain what the input is about.
// If the input has already been labelled in another way, this fallback will be ignored by Assistive Techs.
scontext.setAttribute("aria-label",
localizePlainOrKey("core.model.xclass.editClassProperty.textAlternative",
this.getTranslatedPrettyName(context)), ScriptContext.ENGINE_SCOPE);

BaseProperty prop = (BaseProperty) object.safeget(fieldName);
if (prop != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCol
input.setID(prefix + name);
input.setSize(getSize());
input.setDisabled(isDisabled());
/* This is a text alternative fallback to explain what the input is about.
If the input has already been labelled in another way, this fallback will be ignored by Assistive Techs.
*/
input.addAttribute("aria-label", localizePlainOrKey("core.model.xclass.editClassProperty.textAlternative",
this.getTranslatedPrettyName(context)));

if (isPicker()) {
displayPickerEdit(input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ core.importer.saveDocumentComment=Imported from XAR
core.importer.securitySettingsChanged=Security settings have changed during the import. You will need <a href="{0}">to authenticate</a> in order to continue to administrate the wiki.
core.importer.importAsBackup=Import as backup package

core.model.xclass.editClassProperty.textAlternative=Edit the property "{0}".
core.model.xclass.deleteClassProperty.versionSummary=Removed class property "{0}"
core.model.xclass.disableClassProperty.versionSummary=Disabled class property "{0}"
core.model.xclass.enableClassProperty.versionSummary=Enabled class property "{0}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void setDisplayMode() throws Exception
context.setDisplayMode("edit");

// We verify that the result contains a form input
assertEquals("<input size='5' id='space.page_0_prop' value='value' name='space.page_0_prop' " + "type='text'/>",
assertEquals("<input size='5' id='space.page_0_prop' aria-label='core.model.xclass.editClassProperty.textAlternative' value='value' name='space.page_0_prop' " + "type='text'/>",
document.display("prop", xcontext));

assertEquals("edit", context.getDisplayMode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ public void display()
this.document.setSyntax(Syntax.XWIKI_2_0);

assertEquals(
"{{html clean=\"false\" wiki=\"false\"}}<input size='30' id='Space.Page_0_string' value='string' name='Space.Page_0_string' type='text'/>{{/html}}",
"{{html clean=\"false\" wiki=\"false\"}}<input size='30' id='Space.Page_0_string' aria-label='core.model.xclass.editClassProperty.textAlternative' value='string' name='Space.Page_0_string' type='text'/>{{/html}}",
this.document.display("string", "edit", this.oldcore.getXWikiContext()));

assertEquals("string", this.document.display("string", "view", this.oldcore.getXWikiContext()));
Expand Down Expand Up @@ -634,7 +634,7 @@ public void display1020()

assertEquals("string", this.document.display("string", "view", this.oldcore.getXWikiContext()));
assertEquals(
"{pre}<input size='30' id='Space.Page_0_string' value='string' name='Space.Page_0_string' type='text'/>{/pre}",
"{pre}<input size='30' id='Space.Page_0_string' aria-label='core.model.xclass.editClassProperty.textAlternative' value='string' name='Space.Page_0_string' type='text'/>{/pre}",
this.document.display("string", "edit", this.oldcore.getXWikiContext()));

assertEquals("<p>area</p>", this.document.display("area", "view", this.oldcore.getXWikiContext()));
Expand All @@ -651,7 +651,7 @@ public void displayTemplate20()

assertEquals("string", this.document.display("string", "view", this.oldcore.getXWikiContext()));
assertEquals(
"<input size='30' id='Space.Page_0_string' value='string' name='Space.Page_0_string' type='text'/>",
"<input size='30' id='Space.Page_0_string' aria-label='core.model.xclass.editClassProperty.textAlternative' value='string' name='Space.Page_0_string' type='text'/>",
this.document.display("string", "edit", this.oldcore.getXWikiContext()));

assertEquals("<p>area</p>", this.document.display("area", "view", this.oldcore.getXWikiContext()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.xwiki.localization.ContextualLocalizationManager;
import org.xwiki.display.internal.DocumentDisplayer;
import org.xwiki.display.internal.DocumentDisplayerParameters;
import org.xwiki.job.event.status.JobProgressManager;
Expand Down Expand Up @@ -108,6 +109,7 @@ public void before() throws Exception
this.oldCore.getMocker().registerMockComponent(EntityReferenceSerializer.TYPE_STRING, "compactwiki");
this.oldCore.getMocker().registerMockComponent(DocumentReferenceResolver.TYPE_STRING, "currentmixed");
this.oldCore.getMocker().registerMockComponent(EntityReferenceSerializer.TYPE_STRING, "local");
this.oldCore.getMocker().registerMockComponent(ContextualLocalizationManager.class);

DocumentReference contextDocumentReference = new DocumentReference("wiki", "XWiki", "Context");
this.oldCore.getXWikiContext().setDoc(new XWikiDocument(contextDocumentReference));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.xwiki.localization.ContextualLocalizationManager;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.model.reference.LocalDocumentReference;

Expand Down Expand Up @@ -50,8 +51,11 @@ class StringClassTest
private XWikiURLFactory urlFactory;

@Test
void displayEdit()
void displayEdit() throws Exception
{
// Setup
this.oldCore.getMocker().registerMockComponent(ContextualLocalizationManager.class);

XWikiContext xWikiContext = this.oldCore.getXWikiContext();
xWikiContext.setURLFactory(this.urlFactory);
when(this.oldCore.getSpyXWiki()
Expand All @@ -70,14 +74,14 @@ void displayEdit()
StringBuffer stringBuffer = new StringBuffer();
stringClass.displayEdit(stringBuffer, fieldName, spaceName + "." + pageName + "_0_", baseClass,
xWikiContext);
assertEquals("<input "
assertEquals("<input aria-label='core.model.xclass.editClassProperty.textAlternative' "
+ "onfocus='new ajaxSuggest(this, &#123;script:&#34;\\/a\\/b?xpage=suggest&#38;"
+ "classname=%22%20%2B%20alert%281%29%20%2B%20%22.WebHome&#38;fieldname=test&#38;firCol=-&#38;"
+ "secCol=-&#38;&#34;, varname:&#34;input&#34;} )' "
+ "size='30' "
+ "id='&#34; + alert(1) + &#34;.WebHome_0_test' "
+ "class='suggested' "
+ "id='&#34; + alert(1) + &#34;.WebHome_0_test' "
+ "name='&#34; + alert(1) + &#34;.WebHome_0_test' "
+ "size='30' "
+ "type='text'/>", stringBuffer.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
'name': $id,
'value': $value,
'disabled': $disabled,
'data-format': $format
'data-format': $format,
'aria-label': $aria-label
})
#set ($picker = $field.getProperty('picker').value == 1)
#if ($picker)
Expand Down

0 comments on commit ea922e7

Please sign in to comment.