Search in sources :

Example 21 with ElementChecker

use of org.asqatasun.rules.elementchecker.ElementChecker in project Asqatasun by Asqatasun.

the class SeoRule01013 method check.

@Override
protected void check(final SSPHandler sspHandler, final TestSolutionHandler testSolutionHandler) {
    if (elementHandler.isEmpty() || elementHandler.get().size() > 1) {
        testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
        return;
    }
    ElementChecker checker = new TextLengthChecker(new TextAttributeOfElementBuilder(AttributeStore.CONTENT_ATTR), MAX_META_DESC_LENGTH, META_DESC_EXCEEDS_LIMIT_MSG, // evidence elements
    AttributeStore.CONTENT_ATTR);
    checker.check(sspHandler, elementHandler, testSolutionHandler);
}
Also used : TextLengthChecker(org.asqatasun.rules.elementchecker.text.TextLengthChecker) TextAttributeOfElementBuilder(org.asqatasun.rules.textbuilder.TextAttributeOfElementBuilder) ElementChecker(org.asqatasun.rules.elementchecker.ElementChecker)

Example 22 with ElementChecker

use of org.asqatasun.rules.elementchecker.ElementChecker in project Asqatasun by Asqatasun.

the class Rgaa32016Rule110101 method check.

@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
    // If the page has no input form element, the test is not applicable
    if (inputFormHandler.isEmpty()) {
        testSolutionHandler.addTestSolution(NOT_APPLICABLE);
        return;
    }
    // If all the input form have a label, the test is passed
    if (inputFormWithoutLabelHandler.isEmpty()) {
        testSolutionHandler.addTestSolution(PASSED);
        return;
    }
    ElementChecker ec = new ElementPresenceChecker(new ImmutablePair(FAILED, INVALID_FORM_FIELD_MSG), new ImmutablePair(PASSED, ""));
    ec.check(sspHandler, inputFormWithoutLabelHandler, testSolutionHandler);
}
Also used : ElementPresenceChecker(org.asqatasun.rules.elementchecker.element.ElementPresenceChecker) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ElementChecker(org.asqatasun.rules.elementchecker.ElementChecker)

Example 23 with ElementChecker

use of org.asqatasun.rules.elementchecker.ElementChecker in project Asqatasun by Asqatasun.

the class Rgaa32016Rule110102 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 24 with ElementChecker

use of org.asqatasun.rules.elementchecker.ElementChecker in project Asqatasun by Asqatasun.

the class Rgaa32016Rule050801 method check.

@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
    super.check(sspHandler, testSolutionHandler);
    ElementChecker ec;
    if (!notIdentifiedTableWithoutDataTableMarkup.isEmpty()) {
        ec = new ElementPresenceChecker(// nmi when element is found
        new ImmutablePair(TestSolution.NEED_MORE_INFO, CHECK_TABLE_IS_PRESENTATION_TABLE_MSG), // na when element is not found
        new ImmutablePair(TestSolution.NOT_APPLICABLE, ""));
        ec.check(sspHandler, notIdentifiedTableWithoutDataTableMarkup, testSolutionHandler);
    }
    if (!presentationTableWithoutDataTableMarkup.isEmpty()) {
        ec = new ElementPresenceChecker(// passed when element is foundexit
        new ImmutablePair(TestSolution.PASSED, ""), // na when element is not found
        new ImmutablePair(TestSolution.NOT_APPLICABLE, ""));
        ec.check(sspHandler, presentationTableWithoutDataTableMarkup, testSolutionHandler);
    }
}
Also used : ElementPresenceChecker(org.asqatasun.rules.elementchecker.element.ElementPresenceChecker) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ElementChecker(org.asqatasun.rules.elementchecker.ElementChecker)

Example 25 with ElementChecker

use of org.asqatasun.rules.elementchecker.ElementChecker in project Asqatasun by Asqatasun.

the class SeoRule06031 method check.

@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
    if (elementHandler.isEmpty()) {
        testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
        return;
    }
    // in case of more than one title, keep the first.
    if (elementHandler.get().size() > 1) {
        Element element = elementHandler.get().iterator().next();
        elementHandler.clean().add(element);
    }
    ElementChecker checker = new TextLengthChecker(new SimpleTextElementBuilder(), TITLE_MAX_LENGTH, TITLE_EXCEEDS_LIMIT_MSG, // evidence elements
    HtmlElementStore.TEXT_ELEMENT2);
    checker.check(sspHandler, elementHandler, testSolutionHandler);
}
Also used : TextLengthChecker(org.asqatasun.rules.elementchecker.text.TextLengthChecker) SimpleTextElementBuilder(org.asqatasun.rules.textbuilder.SimpleTextElementBuilder) Element(org.jsoup.nodes.Element) ElementChecker(org.asqatasun.rules.elementchecker.ElementChecker)

Aggregations

ElementChecker (org.asqatasun.rules.elementchecker.ElementChecker)39 ElementPresenceChecker (org.asqatasun.rules.elementchecker.element.ElementPresenceChecker)30 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)21 HashMap (java.util.HashMap)8 Map (java.util.Map)8 ElementHandler (org.asqatasun.ruleimplementation.ElementHandler)8 ElementWithAttributePresenceChecker (org.asqatasun.rules.elementchecker.element.ElementWithAttributePresenceChecker)5 TextEmptinessChecker (org.asqatasun.rules.elementchecker.text.TextEmptinessChecker)5 TextAttributeOfElementBuilder (org.asqatasun.rules.textbuilder.TextAttributeOfElementBuilder)5 Element (org.jsoup.nodes.Element)5 ElementHandlerImpl (org.asqatasun.ruleimplementation.ElementHandlerImpl)4 AttributePresenceChecker (org.asqatasun.rules.elementchecker.attribute.AttributePresenceChecker)4 IdUnicityChecker (org.asqatasun.rules.elementchecker.attribute.IdUnicityChecker)3 TextLengthChecker (org.asqatasun.rules.elementchecker.text.TextLengthChecker)2 TestSolution (org.asqatasun.entity.audit.TestSolution)1 TextBelongsToBlackListChecker (org.asqatasun.rules.elementchecker.text.TextBelongsToBlackListChecker)1 TextNotIdenticalToAttributeChecker (org.asqatasun.rules.elementchecker.text.TextNotIdenticalToAttributeChecker)1 TextOnlyContainsNonAlphanumericalCharactersChecker (org.asqatasun.rules.elementchecker.text.TextOnlyContainsNonAlphanumericalCharactersChecker)1 SimpleTextElementBuilder (org.asqatasun.rules.textbuilder.SimpleTextElementBuilder)1