Search in sources :

Example 26 with ElementChecker

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

the class Aw22Rule11011 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(TestSolution.NOT_APPLICABLE);
        return;
    }
    // If all the input form have a label, the test is passed
    if (inputFormWithoutLabelHandler.isEmpty()) {
        testSolutionHandler.addTestSolution(TestSolution.PASSED);
        return;
    }
    ElementChecker titleAttrPresenceChecker = new AttributePresenceChecker(TITLE_ATTR, TestSolution.PASSED, TestSolution.FAILED, null, INVALID_FORM_FIELD_MSG);
    titleAttrPresenceChecker.check(sspHandler, inputFormWithoutLabelHandler, testSolutionHandler);
}
Also used : ElementChecker(org.asqatasun.rules.elementchecker.ElementChecker) AttributePresenceChecker(org.asqatasun.rules.elementchecker.attribute.AttributePresenceChecker)

Example 27 with ElementChecker

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

the class Aw22Rule11013 method check.

@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
    if (explicitLabelElements.isEmpty() && innerControlLabelElements.isEmpty()) {
        testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
        return;
    }
    // if all the label are explicitely defined, the test is passed
    if (innerControlLabelElements.isEmpty()) {
        // add the explicit label element to main handler for counter
        // purpose
        innerControlLabelElements.addAll(explicitLabelElements.get());
        testSolutionHandler.addTestSolution(TestSolution.PASSED);
        return;
    }
    ElementHandler<Element> labelOnError = new ElementHandlerImpl();
    for (Element el : innerControlLabelElements.get()) {
        if (!isForAttributeOfLabelEqualsToIdAttributeOfFormField(el, el.attr(FOR_ATTR))) {
            labelOnError.add(el);
        }
    }
    // use this checker to create sourceCodeRemark when needed
    ElementChecker checker = new ElementPresenceChecker(new ImmutablePair(TestSolution.FAILED, INVALID_LABEL_MSG), new ImmutablePair(TestSolution.PASSED, ""));
    checker.check(sspHandler, labelOnError, testSolutionHandler);
}
Also used : ElementPresenceChecker(org.asqatasun.rules.elementchecker.element.ElementPresenceChecker) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) ElementChecker(org.asqatasun.rules.elementchecker.ElementChecker)

Example 28 with ElementChecker

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

the class Aw22Rule11012 method check.

@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
    // If the page has no input form element, the test is not applicable
    if (labels.isEmpty()) {
        testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
        return;
    }
    /* The attribute Presence Checker */
    ElementChecker attributePresenceChecker = new AttributePresenceChecker(ID_ATTR, TestSolution.PASSED, TestSolution.FAILED, null, ID_MISSING_MSG);
    attributePresenceChecker.check(sspHandler, labels, 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, labels, testSolutionHandler);
    /* The id unicityChecker */
    ElementChecker idUnicityChecker = new IdUnicityChecker(ID_NOT_UNIQUE_MSG);
    idUnicityChecker.check(sspHandler, labels, testSolutionHandler);
}
Also used : TextAttributeOfElementBuilder(org.asqatasun.rules.textbuilder.TextAttributeOfElementBuilder) IdUnicityChecker(org.asqatasun.rules.elementchecker.attribute.IdUnicityChecker) TextEmptinessChecker(org.asqatasun.rules.elementchecker.text.TextEmptinessChecker) ElementChecker(org.asqatasun.rules.elementchecker.ElementChecker) AttributePresenceChecker(org.asqatasun.rules.elementchecker.attribute.AttributePresenceChecker)

Example 29 with ElementChecker

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

the class Aw22Rule10012 method check.

@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
    // Attributes checks
    for (Map.Entry<String, ElementHandler> attrElementHandlerMapEntry : attrElementHandlerMap.entrySet()) {
        ElementChecker attrEc = new ElementWithAttributePresenceChecker(new ImmutablePair(TestSolution.FAILED, PRESENTATION_ATTR_DETECTED_MSG), new ImmutablePair(TestSolution.PASSED, ""), attrElementHandlerMapEntry.getKey());
        attrEc.check(sspHandler, attrElementHandlerMapEntry.getValue(), testSolutionHandler);
    }
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ElementWithAttributePresenceChecker(org.asqatasun.rules.elementchecker.element.ElementWithAttributePresenceChecker) ElementHandler(org.asqatasun.ruleimplementation.ElementHandler) ElementChecker(org.asqatasun.rules.elementchecker.ElementChecker) HashMap(java.util.HashMap) Map(java.util.Map)

Example 30 with ElementChecker

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

the class Rgaa22Rule07091 method check.

@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
    if (linkWithoutTarget.isEmpty() && fieldsetNotWithinForm.isEmpty()) {
        sspHandler.getProcessRemarkService().addProcessRemark(TestSolution.NEED_MORE_INFO, RuleCheckHelper.specifyMessageToRule(NO_PATTERN_DETECTED_MSG, this.getTest().getCode()));
        testSolutionHandler.addTestSolution(TestSolution.NEED_MORE_INFO);
        return;
    }
    ElementChecker linkWithoutTargetChecker = new ElementPresenceChecker(TestSolution.FAILED, TestSolution.PASSED, LINK_WITHOUT_TARGET_MSG, null);
    linkWithoutTargetChecker.check(sspHandler, linkWithoutTarget, testSolutionHandler);
    ElementChecker fieldsetNotWithinFormChecker = new ElementPresenceChecker(TestSolution.FAILED, TestSolution.PASSED, FIELDSET_NOT_WITHIN_FORM_MSG, null);
    fieldsetNotWithinFormChecker.check(sspHandler, fieldsetNotWithinForm, testSolutionHandler);
}
Also used : ElementPresenceChecker(org.asqatasun.rules.elementchecker.element.ElementPresenceChecker) 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