use of org.asqatasun.ruleimplementation.ElementHandlerImpl in project Asqatasun by Asqatasun.
the class Rgaa30Rule060301 method testTitleAttributeLink.
/**
*
* @param sspHandler
* @param el
* @param linkText
* @return
*/
private TestSolution testTitleAttributeLink(SSPHandler sspHandler, Element el, String linkText) {
// content identical to the link text, returns not applicable.
if (!el.hasAttr(TITLE_ATTR)) {
return TestSolution.NOT_APPLICABLE;
}
String attrValue = el.attr(TITLE_ATTR);
if (StringUtils.isBlank(attrValue)) {
return TestSolution.NOT_APPLICABLE;
}
if (StringUtils.equalsIgnoreCase(attrValue, linkText)) {
return TestSolution.NOT_APPLICABLE;
}
ElementHandler<Element> elHandler = new ElementHandlerImpl(el);
TestSolutionHandler tsHandler = new TestSolutionHandlerImpl();
titlePertinenceElementChecker.check(sspHandler, elHandler, tsHandler);
return tsHandler.getTestSolution();
}
use of org.asqatasun.ruleimplementation.ElementHandlerImpl in project Asqatasun by Asqatasun.
the class Rgaa30Rule060304 method testLink.
/**
*
* @param sspHandler
* @param el
* @return
*/
private TestSolution testLink(SSPHandler sspHandler, Element el) {
ElementHandler<Element> elHandler = new ElementHandlerImpl(el);
TestSolutionHandler tsHandler = new TestSolutionHandlerImpl();
// reset the service for each tested element. We use the collection
// handled by the service to feed the local collection of remarks
prs.resetService();
// check the pertinence of the link
getDecidableElementsChecker().check(sspHandler, elHandler, tsHandler);
// get the processRemark for eventually override it with the result
// returned by the title pertinence checker
ProcessRemark remark = prs.getRemarkList().iterator().next();
// to nmi but the inverse is impossible.
if (tsHandler.getTestSolution().equals(TestSolution.FAILED)) {
// check the pertinence of the title of the link
String linkText = getDecidableElementsChecker().getTextElementBuilder().buildTextFromElement(el);
if (testTitleAttributeLink(sspHandler, el, linkText).equals(TestSolution.NEED_MORE_INFO)) {
//override result (evidence element have already been collected
remark.setIssue(TestSolution.NEED_MORE_INFO);
remark.setMessageCode(CHECK_LINK_PERTINENCE_MSG);
remarks.add(remark);
return TestSolution.NEED_MORE_INFO;
}
}
remarks.add(remark);
return tsHandler.getTestSolution();
}
use of org.asqatasun.ruleimplementation.ElementHandlerImpl in project Asqatasun by Asqatasun.
the class Rgaa30Rule110101 method select.
@Override
protected void select(SSPHandler sspHandler) {
// Selection of all the input form elements of the page
ElementSelector elementSelector = new SimpleElementSelector(FORM_ELEMENT_CSS_LIKE_QUERY);
elementSelector.selectElements(sspHandler, inputFormHandler);
// the selection of the input form elements without label is initialised
// with all the elements of the page, some elements will be removed later
inputFormWithoutLabelHandler.addAll(inputFormHandler.get());
// selection of the input form elements with explicit label
ElementHandler<Element> inputFormLabelHandler = new ElementHandlerImpl();
ElementSelector explicitLabelSelector = new InputFormElementWithExplicitLabelSelector(inputFormHandler);
explicitLabelSelector.selectElements(sspHandler, inputFormLabelHandler);
// remove all the input form elements with explicit label from
// the selection of the input form elements without label
inputFormWithoutLabelHandler.removeAll(inputFormLabelHandler.get());
// selection of the input form with inplicit label
ElementSelector inplicitLabelSelector = new InputFormElementWithInplicitLabelSelector(inputFormHandler);
inplicitLabelSelector.selectElements(sspHandler, inputFormLabelHandler);
// remove all the input form elements with inplicit label from
// the selection of the input form elements without label
inputFormWithoutLabelHandler.removeAll(inputFormLabelHandler.get());
// selection of the input form elements with explicit label
ElementHandler<Element> inputFormWithAttrHandler = new ElementHandlerImpl();
for (Element el : inputFormWithoutLabelHandler.get()) {
if (el.hasAttr(TITLE_ATTR) || el.hasAttr(ARIA_LABEL_ATTR) || el.hasAttr(ARIA_LABELLEDBY_ATTR)) {
inputFormWithAttrHandler.add(el);
}
}
// remove all the input form elements with title, aria-label, or
// aria-labelledby attributes from the selection of the input form
// elements without label
inputFormWithoutLabelHandler.removeAll(inputFormWithAttrHandler.get());
}
use of org.asqatasun.ruleimplementation.ElementHandlerImpl in project Asqatasun by Asqatasun.
the class Rgaa30Rule110102 method putInputElementHandlerIntoTheMap.
/**
* This method linked each input on a page to its form in a map.
*/
private void putInputElementHandlerIntoTheMap() {
for (Element el : inputElementHandler.get()) {
if (!el.hasAttr(TITLE_ATTR) && !el.hasAttr(ARIA_LABEL_ATTR) && !el.hasAttr(ARIA_LABELLEDBY_ATTR)) {
Element tmpElement = el.parent();
while (StringUtils.isNotBlank(tmpElement.tagName())) {
if (tmpElement.tagName().equals(FORM_ELEMENT)) {
if (inputFormMap.containsKey(tmpElement)) {
inputFormMap.get(tmpElement).add(el);
} else {
ElementHandler<Element> inputElement = new ElementHandlerImpl();
inputElement.add(el);
inputFormMap.put(tmpElement, inputElement);
}
break;
}
tmpElement = tmpElement.parent();
}
}
}
}
use of org.asqatasun.ruleimplementation.ElementHandlerImpl in project Asqatasun by Asqatasun.
the class Rgaa30Rule110102 method check.
@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
/* If the page has no input form element, the test is not applicable */
if (inputFormMap.entrySet().isEmpty()) {
testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
return;
}
for (Map.Entry<Element, ElementHandler<Element>> entry : inputFormMap.entrySet()) {
/* The attribute Presence Checker */
ElementChecker attributePresenceChecker = new AttributePresenceChecker(ID_ATTR, new ImmutablePair(TestSolution.PASSED, ""), new ImmutablePair(TestSolution.FAILED, ID_MISSING_MSG));
attributePresenceChecker.check(sspHandler, entry.getValue(), testSolutionHandler);
/* The attribute Emptiness Checker. Keep default value i.e failed
when attribute is empty
*/
ElementChecker attributeEmptinessChecker = new TextEmptinessChecker(new TextAttributeOfElementBuilder(ID_ATTR), ID_MISSING_MSG, null);
attributeEmptinessChecker.check(sspHandler, entry.getValue(), testSolutionHandler);
/* The id unicityChecker */
ElementChecker idUnicityChecker = new IdUnicityChecker(ID_NOT_UNIQUE_MSG);
idUnicityChecker.check(sspHandler, entry.getValue(), testSolutionHandler);
}
for (Map.Entry<Element, ElementHandler<Element>> entry : labelFormMap.entrySet()) {
/* The attribute Presence Checker */
ElementChecker attributePresenceChecker = new AttributePresenceChecker(FOR_ATTR, new ImmutablePair(TestSolution.PASSED, ""), new ImmutablePair(TestSolution.FAILED, FOR_MISSING_MSG));
attributePresenceChecker.check(sspHandler, entry.getValue(), testSolutionHandler);
/* The attribute Emptiness Checker. Keep default value i.e failed
when attribute is empty
*/
ElementChecker attributeEmptinessChecker = new TextEmptinessChecker(new TextAttributeOfElementBuilder(FOR_ATTR), FOR_MISSING_MSG, null);
attributeEmptinessChecker.check(sspHandler, entry.getValue(), testSolutionHandler);
}
for (Map.Entry<Element, ElementHandler<Element>> entry : inputFormMap.entrySet()) {
ElementHandler<Element> inputOnError = new ElementHandlerImpl();
/* Check if each input id attribute is linked to a for attribute*/
for (Element el : entry.getValue().get()) {
String id = el.id();
if (StringUtils.isNotBlank(id)) {
ElementHandler<Element> linkedLabelToInputHandler = new ElementHandlerImpl();
if (entry.getKey().select(LABEL_ELEMENT + " " + CssLikeSelectorBuilder.buildSelectorFromElementsAndAttributeValue(INPUT_ELEMENT, ID_ATTR, id)).isEmpty()) {
linkedLabelToInputHandler.addAll(entry.getKey().select(CssLikeSelectorBuilder.buildSelectorFromElementsAndAttributeValue(LABEL_ELEMENT, FOR_ATTR, id)));
if (linkedLabelToInputHandler.isEmpty()) {
inputOnError.add(el);
}
}
}
}
ElementChecker elementPresenceChecker = new ElementPresenceChecker(new ImmutablePair(TestSolution.FAILED, INVALID_INPUT_MSG), new ImmutablePair(TestSolution.PASSED, ""));
elementPresenceChecker.check(sspHandler, inputOnError, testSolutionHandler);
}
for (Map.Entry<Element, ElementHandler<Element>> entry : labelFormMap.entrySet()) {
ElementHandler<Element> labelOnError = new ElementHandlerImpl();
/* Check if each label for attribute is associated to an input id attribute*/
for (Element el : entry.getValue().get()) {
String id = el.attr(FOR_ATTR);
if (StringUtils.isNotBlank(id)) {
ElementHandler<Element> linkedLabelToInputHandler = new ElementHandlerImpl();
linkedLabelToInputHandler.addAll(entry.getKey().select(CssLikeSelectorBuilder.buildSelectorFromId(id)));
if (linkedLabelToInputHandler.isEmpty()) {
labelOnError.add(el);
}
}
}
ElementChecker elementPresenceChecker = new ElementPresenceChecker(new ImmutablePair(TestSolution.FAILED, INVALID_LABEL_MSG), new ImmutablePair(TestSolution.PASSED, ""));
elementPresenceChecker.check(sspHandler, labelOnError, testSolutionHandler);
}
}
Aggregations