Search in sources :

Example 11 with TextAttributeOfElementBuilder

use of org.asqatasun.rules.textbuilder.TextAttributeOfElementBuilder in project Asqatasun by Asqatasun.

the class Rgaa30Rule010202 method getMarkerElementChecker.

/**
     * 
     * @return the checker user for marked elements
     */
private ElementChecker getMarkerElementChecker() {
    CompositeChecker ec = new CompositeChecker(new TextEmptinessChecker(new TextAttributeOfElementBuilder(ALT_ATTR), new ImmutablePair(PASSED, ""), new ImmutablePair(FAILED, DECORATIVE_ELEMENT_WITH_NOT_EMPTY_ALT_MSG), ALT_ATTR, TITLE_ATTR), new AttributePresenceChecker(TITLE_ATTR, new ImmutablePair(FAILED, DECORATIVE_ELEMENT_WITH_TITLE_ATTR_MSG), new ImmutablePair(PASSED, ""), ALT_ATTR, TITLE_ATTR));
    ec.setIsOrCombinaison(false);
    return ec;
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) TextAttributeOfElementBuilder(org.asqatasun.rules.textbuilder.TextAttributeOfElementBuilder) TextEmptinessChecker(org.asqatasun.rules.elementchecker.text.TextEmptinessChecker) CompositeChecker(org.asqatasun.rules.elementchecker.CompositeChecker) AttributePresenceChecker(org.asqatasun.rules.elementchecker.attribute.AttributePresenceChecker)

Example 12 with TextAttributeOfElementBuilder

use of org.asqatasun.rules.textbuilder.TextAttributeOfElementBuilder in project Asqatasun by Asqatasun.

the class Rgaa30Rule010201 method getMarkerElementChecker.

/**
     * 
     * @return the checker user for marked elements
     */
private ElementChecker getMarkerElementChecker() {
    CompositeChecker ec = new CompositeChecker(new TextEmptinessChecker(new TextAttributeOfElementBuilder(ALT_ATTR), new ImmutablePair(PASSED, ""), new ImmutablePair(FAILED, DECORATIVE_ELEMENT_WITH_NOT_EMPTY_ALT_MSG), ALT_ATTR, TITLE_ATTR, SRC_ATTR), new AttributePresenceChecker(TITLE_ATTR, new ImmutablePair(FAILED, DECORATIVE_ELEMENT_WITH_TITLE_ATTR_MSG), new ImmutablePair(PASSED, ""), ALT_ATTR, TITLE_ATTR, SRC_ATTR));
    ec.setIsOrCombinaison(false);
    return ec;
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) TextAttributeOfElementBuilder(org.asqatasun.rules.textbuilder.TextAttributeOfElementBuilder) TextEmptinessChecker(org.asqatasun.rules.elementchecker.text.TextEmptinessChecker) CompositeChecker(org.asqatasun.rules.elementchecker.CompositeChecker) AttributePresenceChecker(org.asqatasun.rules.elementchecker.attribute.AttributePresenceChecker)

Example 13 with TextAttributeOfElementBuilder

use of org.asqatasun.rules.textbuilder.TextAttributeOfElementBuilder in project Asqatasun by Asqatasun.

the class Rgaa30Rule010301 method getMarkerElementChecker.

/**
     * 
     * @return the checker user for marked elements
     */
private ElementChecker getMarkerElementChecker() {
    CompositeChecker ec = new CompositeChecker(// checker for elements identified by marker
    new AttributePertinenceChecker(ALT_ATTR, // check emptiness
    true, // compare with src attribute
    new TextAttributeOfElementBuilder(SRC_ATTR), // compare attribute value with nomenclature
    IMAGE_FILE_EXTENSION_NOM, // not pertinent message
    NOT_PERTINENT_ALT_MSG, // manual check message
    CHECK_ALT_PERTINENCE_OF_INFORMATIVE_IMG_MSG, // evidence elements
    ALT_ATTR, TITLE_ATTR, SRC_ATTR), new TextNotIdenticalToAttributeChecker(new TextAttributeOfElementBuilder(TITLE_ATTR), new TextAttributeOfElementBuilder(ALT_ATTR), new ImmutablePair(PASSED, ""), new ImmutablePair(FAILED, TITLE_NOT_IDENTICAL_TO_ALT_MSG), // evidence elements
    ALT_ATTR, TITLE_ATTR, SRC_ATTR));
    ec.setIsOrCombinaison(false);
    return ec;
}
Also used : TextNotIdenticalToAttributeChecker(org.asqatasun.rules.elementchecker.text.TextNotIdenticalToAttributeChecker) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) TextAttributeOfElementBuilder(org.asqatasun.rules.textbuilder.TextAttributeOfElementBuilder) AttributePertinenceChecker(org.asqatasun.rules.elementchecker.pertinence.AttributePertinenceChecker) CompositeChecker(org.asqatasun.rules.elementchecker.CompositeChecker)

Example 14 with TextAttributeOfElementBuilder

use of org.asqatasun.rules.textbuilder.TextAttributeOfElementBuilder 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);
    }
}
Also used : ElementPresenceChecker(org.asqatasun.rules.elementchecker.element.ElementPresenceChecker) IdUnicityChecker(org.asqatasun.rules.elementchecker.attribute.IdUnicityChecker) Element(org.jsoup.nodes.Element) TextEmptinessChecker(org.asqatasun.rules.elementchecker.text.TextEmptinessChecker) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) TextAttributeOfElementBuilder(org.asqatasun.rules.textbuilder.TextAttributeOfElementBuilder) ElementHandler(org.asqatasun.ruleimplementation.ElementHandler) ElementChecker(org.asqatasun.rules.elementchecker.ElementChecker) AttributePresenceChecker(org.asqatasun.rules.elementchecker.attribute.AttributePresenceChecker) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with TextAttributeOfElementBuilder

use of org.asqatasun.rules.textbuilder.TextAttributeOfElementBuilder in project Asqatasun by Asqatasun.

the class Rgaa30Rule110103 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 Emptiness Checker. Keep default value i.e failed 
             when attribute is empty
             */
        ElementChecker attributeEmptinessChecker = new TextEmptinessChecker(new TextAttributeOfElementBuilder(ARIA_LABELLEDBY_ATTR), ARIA_LABELLEDBY_EMPTY_MSG, null);
        attributeEmptinessChecker.check(sspHandler, entry.getValue(), testSolutionHandler);
        ElementHandler<Element> inputWithoutLabel = new ElementHandlerImpl();
        ElementHandler<Element> notUniqueLabel = new ElementHandlerImpl();
        for (Element el : entry.getValue().get()) {
            if (StringUtils.isNotEmpty(el.attr(ARIA_LABELLEDBY_ATTR))) {
                ElementHandler<Element> labelHandler = new ElementHandlerImpl();
                labelHandler.addAll(entry.getKey().select(CssLikeSelectorBuilder.buildSelectorFromAttributeTypeAndValue(ID_ATTR, el.attr(ARIA_LABELLEDBY_ATTR))));
                if (labelHandler.get().isEmpty()) {
                    inputWithoutLabel.add(el);
                } else if (labelHandler.get().size() > 1) {
                    notUniqueLabel.add(el);
                    notUniqueLabel.addAll(labelHandler.get());
                }
            }
        }
        /* Check if the form element has a label associated */
        ElementChecker elementPresenceChecker = new ElementPresenceChecker(new ImmutablePair(TestSolution.FAILED, FORM_ELEMENT_WITHOUT_LABEL_MSG), new ImmutablePair(TestSolution.PASSED, ""));
        elementPresenceChecker.check(sspHandler, inputWithoutLabel, testSolutionHandler);
        /* Check if the id attr of the label associated to the form element is unique */
        elementPresenceChecker = new ElementPresenceChecker(new ImmutablePair(TestSolution.FAILED, FORM_ELEMENT_WITH_NOT_UNIQUE_LABEL_MSG), new ImmutablePair(TestSolution.PASSED, ""));
        elementPresenceChecker.check(sspHandler, notUniqueLabel, testSolutionHandler);
    }
}
Also used : ElementPresenceChecker(org.asqatasun.rules.elementchecker.element.ElementPresenceChecker) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) TextAttributeOfElementBuilder(org.asqatasun.rules.textbuilder.TextAttributeOfElementBuilder) Element(org.jsoup.nodes.Element) TextEmptinessChecker(org.asqatasun.rules.elementchecker.text.TextEmptinessChecker) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) ElementHandler(org.asqatasun.ruleimplementation.ElementHandler) ElementChecker(org.asqatasun.rules.elementchecker.ElementChecker) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

TextAttributeOfElementBuilder (org.asqatasun.rules.textbuilder.TextAttributeOfElementBuilder)16 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)13 CompositeChecker (org.asqatasun.rules.elementchecker.CompositeChecker)8 TextEmptinessChecker (org.asqatasun.rules.elementchecker.text.TextEmptinessChecker)8 AttributePresenceChecker (org.asqatasun.rules.elementchecker.attribute.AttributePresenceChecker)7 ElementChecker (org.asqatasun.rules.elementchecker.ElementChecker)5 AttributePertinenceChecker (org.asqatasun.rules.elementchecker.pertinence.AttributePertinenceChecker)4 TextNotIdenticalToAttributeChecker (org.asqatasun.rules.elementchecker.text.TextNotIdenticalToAttributeChecker)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ElementHandler (org.asqatasun.ruleimplementation.ElementHandler)3 ElementHandlerImpl (org.asqatasun.ruleimplementation.ElementHandlerImpl)3 IdUnicityChecker (org.asqatasun.rules.elementchecker.attribute.IdUnicityChecker)3 ElementPresenceChecker (org.asqatasun.rules.elementchecker.element.ElementPresenceChecker)3 Element (org.jsoup.nodes.Element)3 TextLengthChecker (org.asqatasun.rules.elementchecker.text.TextLengthChecker)1 SimpleTextElementBuilder (org.asqatasun.rules.textbuilder.SimpleTextElementBuilder)1 TextElementBuilder (org.asqatasun.rules.textbuilder.TextElementBuilder)1