use of org.asqatasun.ruleimplementation.ElementHandlerImpl in project Asqatasun by Asqatasun.
the class Aw22Rule11011 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());
}
use of org.asqatasun.ruleimplementation.ElementHandlerImpl 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);
}
use of org.asqatasun.ruleimplementation.ElementHandlerImpl in project Asqatasun by Asqatasun.
the class Aw22Rule06034 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 Aw22Rule06031 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 AbstractDownloadableLinkRuleImplementation method check.
@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
// invoke getElementChecker instead of super.check() to use local
// collection of elements
setServicesToChecker(getElementChecker());
getElementChecker().check(sspHandler, linkWithSimpleExtension, testSolutionHandler);
TestSolution checkerSolution = testSolutionHandler.getTestSolution();
if (checkerSolution.equals(TestSolution.NOT_APPLICABLE) && !getElements().isEmpty()) {
testSolutionHandler.addTestSolution(TestSolution.NEED_MORE_INFO);
sspHandler.getProcessRemarkService().addProcessRemark(TestSolution.NEED_MORE_INFO, RuleCheckHelper.specifyMessageToRule(CHECK_MANUALLY_LINK_WITHOUT_EXT_MSG, this.getTest().getCode()));
return;
}
if (checkerSolution.equals(TestSolution.PASSED)) {
// the test result is NMI
if (getElements().get().size() > linkWithSimpleExtension.get().size()) {
testSolutionHandler.addTestSolution(TestSolution.NEED_MORE_INFO);
sspHandler.getProcessRemarkService().addProcessRemark(TestSolution.NEED_MORE_INFO, RuleCheckHelper.specifyMessageToRule(CHECK_MANUALLY_LINK_WITHOUT_EXT_MSG, this.getTest().getCode()));
return;
}
// we search whether the page contains form, if yes, the result
// is nmi, if not, the test is not applicable
ElementHandler<Element> formHandler = new ElementHandlerImpl();
new SimpleElementSelector(FORM_ELEMENT).selectElements(sspHandler, formHandler);
if (formHandler.isEmpty()) {
testSolutionHandler.cleanTestSolutions();
testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
} else {
testSolutionHandler.addTestSolution(TestSolution.NEED_MORE_INFO);
sspHandler.getProcessRemarkService().addProcessRemark(TestSolution.NEED_MORE_INFO, RuleCheckHelper.specifyMessageToRule(CHECK_DOWNLOADABLE_DOCUMENT_FROM_FORM_MSG, this.getTest().getCode()));
}
}
}
Aggregations