Skip to content

Commit

Permalink
fix: report all epub:type value checks as USAGE
Browse files Browse the repository at this point in the history
Message changes:
- `OPF-086` (`WARNING`) only reports deprecated properties other than
  `epub:type`.
- `OPF-086b` new message reports deprecated `epub:type` values as `USAGE`
- `OPF-087`, reporting not-allowed properties, becomes a `USAGE`.

Fix #1009
  • Loading branch information
rdeltour committed Mar 17, 2019
1 parent ced3c15 commit f248483
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ private void initialize()
severities.put(MessageId.OPF_084, Severity.ERROR);
severities.put(MessageId.OPF_085, Severity.WARNING);
severities.put(MessageId.OPF_086, Severity.WARNING);
severities.put(MessageId.OPF_087, Severity.ERROR);
severities.put(MessageId.OPF_086b, Severity.USAGE);
severities.put(MessageId.OPF_087, Severity.USAGE);
severities.put(MessageId.OPF_088, Severity.USAGE);
severities.put(MessageId.OPF_089, Severity.ERROR);

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/adobe/epubcheck/messages/MessageId.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ public enum MessageId implements Comparable<MessageId>
OPF_084("OPF-084"),
OPF_085("OPF-085"),
OPF_086("OPF-086"),
OPF_086b("OPF-086b"),
OPF_087("OPF-087"),
OPF_088("OPF-088"),
OPF_089("OPF-089"),
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/adobe/epubcheck/vocab/VocabUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,14 @@ private static Set<Property> parseProperties(String value, Map<String, ? extends
{
if (found.get().isDeprecated())
{
MessageId messageId = (StructureVocab.URI.equals(found.get().getVocabURI()))
? MessageId.OPF_086b
: MessageId.OPF_086;
// Replacement suggestions for deprecated properties are given
// in message strings of the form OPF_086_SUG.property-name
String suggestion = LocalizedMessages.getInstance(context.locale)
.getSuggestion(MessageId.OPF_086, found.get().getName());
context.report.message(MessageId.OPF_086, location, property, suggestion);
.getSuggestion(messageId, found.get().getName());
context.report.message(messageId, location, property, suggestion);
}
if (!found.get().isAllowed(context))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,22 +250,24 @@ OPF_084=Found an EPUB Dictionary collection containing resource '%1$s' which is
OPF_085='dc:identifier' value '%1$s' is marked as a UUID, but is an invalid UUID.
OPF_086=Property '%1$s' is deprecated. Consider using %2$s instead.
OPF_086_SUG.default=a custom prefixed property
OPF_086_SUG.annoref=open annotations
OPF_086_SUG.annotation=open annotations
OPF_086_SUG.help=the 'tip' property
OPF_086_SUG.marc21xml-record=the 'record' keyword and the media-type "application/marcxml+xml"
OPF_086_SUG.marginalia=a bare 'aside' element
OPF_086_SUG.mods-record=the 'record' keyword and the media-type "application/mods+xml"
OPF_086_SUG.note=a 'footnote' or 'endnote' property
OPF_086_SUG.onix-record=the 'record' keyword with the properties attribute value 'onix'
OPF_086_SUG.rearnote=the 'endnote' property
OPF_086_SUG.rearnotes=the 'endnotes' property
OPF_086_SUG.sidebar=a bare 'aside' element
OPF_086_SUG.warning=the 'notice' property
OPF_086_SUG.xml-signature=no signature-identifying link
OPF_086_SUG.xmp-record=the 'record' keyword with the properties attribute value 'xmp'
OPF_087=Property '%1$s' is not allowed on documents of type '%2$s'.
OPF_088=Unrecognized property '%1$s'.
OPF_086b=epub:type value '%1$s' is deprecated. Consider using %2$s instead.
OPF_086b_SUG.default=a custom prefixed value
OPF_086b_SUG.annoref=open annotations
OPF_086b_SUG.annotation=open annotations
OPF_086b_SUG.help=the 'tip' property
OPF_086b_SUG.marginalia=a bare 'aside' element
OPF_086b_SUG.note=a 'footnote' or 'endnote' property
OPF_086b_SUG.rearnote=the 'endnote' property
OPF_086b_SUG.rearnotes=the 'endnotes' property
OPF_086b_SUG.sidebar=a bare 'aside' element
OPF_086b_SUG.warning=the 'notice' property
OPF_087=epub:type value '%1$s' is not allowed on documents of type '%2$s'.
OPF_088=Unrecognized epub:type value '%1$s'.
OPF_089=The 'alternate' link rel keyword cannot be paired with other keywords.

#Package
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/adobe/epubcheck/ops/OPSCheckerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -487,15 +487,15 @@ public void testEPUBTypeUnknownIsIgnored()
@Test
public void testEPUBTypeDeprecated()
{
expectedWarnings.addAll(Collections.nCopies(10, MessageId.OPF_086));
expectedUsage.addAll(Collections.nCopies(10, MessageId.OPF_086b));
testValidateDocument("xhtml/invalid/epubtype-deprecated.xhtml", "application/xhtml+xml",
EPUBVersion.VERSION_3);
}

@Test
public void testEPUBTypeDisallowed()
{
expectedErrors.addAll(Collections.nCopies(7, MessageId.OPF_087));
expectedUsage.addAll(Collections.nCopies(7, MessageId.OPF_087));
testValidateDocument("xhtml/invalid/epubtype-disallowed.xhtml", "application/xhtml+xml",
EPUBVersion.VERSION_3);
}
Expand Down
19 changes: 13 additions & 6 deletions src/test/java/com/adobe/epubcheck/vocab/VocabTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.adobe.epubcheck.messages.MessageId;
import com.adobe.epubcheck.opf.ValidationContext;
import com.adobe.epubcheck.opf.ValidationContext.ValidationContextBuilder;
import com.adobe.epubcheck.util.ReportingLevel;
import com.adobe.epubcheck.util.ThrowingResourceProvider;
import com.adobe.epubcheck.util.ValidationReport;
import com.adobe.epubcheck.util.outWriter;
Expand Down Expand Up @@ -135,6 +136,7 @@ public boolean isDeprecated()

private List<MessageId> expectedErrors = Lists.newLinkedList();
private List<MessageId> expectedWarnings = Lists.newLinkedList();
private List<MessageId> expectedUsages = Lists.newLinkedList();
private List<MessageId> expectedFatals = Lists.newLinkedList();
private ValidationContext context;
private ValidationReport report;
Expand All @@ -143,6 +145,7 @@ public boolean isDeprecated()
public void before()
{
report = new ValidationReport(VocabTest.class.getSimpleName());
report.setReportingLevel(ReportingLevel.Usage);
context = new ValidationContextBuilder().resourceProvider(new ThrowingResourceProvider())
.report(report).build();
}
Expand All @@ -161,9 +164,10 @@ private Set<Property> testPropertyList(String value, Map<String, Vocab> vocabs,
outWriter.println(report);
}

assertEquals("The fatal error results do not match", expectedFatals, report.getFatalErrorIds());
assertEquals("The error results do not match", expectedErrors, report.getErrorIds());
assertEquals("The warning results do not match", expectedWarnings, report.getWarningIds());
assertEquals("The fatal error results do not match", expectedFatals, report.getFatalErrorIds());
assertEquals("The usage results do not match", expectedUsages, report.getUsageIds());

return props;
}
Expand All @@ -183,9 +187,10 @@ private Optional<Property> testProperty(String value, Map<String, Vocab> vocabs,
outWriter.println(report);
}

assertEquals("The fatal error results do not match", expectedFatals, report.getFatalErrorIds());
assertEquals("The error results do not match", expectedErrors, report.getErrorIds());
assertEquals("The warning results do not match", expectedWarnings, report.getWarningIds());
assertEquals("The fatal error results do not match", expectedFatals, report.getFatalErrorIds());
assertEquals("The usages results do not match", expectedUsages, report.getUsageIds());

return prop;
}
Expand All @@ -207,20 +212,22 @@ private Map<String, Vocab> testVocabs(String value, boolean verbose)
outWriter.println(testReport);
}

assertEquals("The error results do not match", expectedErrors, testReport.getErrorIds());
assertEquals("The warning results do not match", expectedWarnings, testReport.getWarningIds());
assertEquals("The fatal error results do not match", expectedFatals,
testReport.getFatalErrorIds());
assertEquals("The error results do not match", expectedErrors, testReport.getErrorIds());
assertEquals("The warning results do not match", expectedWarnings, testReport.getWarningIds());
assertEquals("The usages results do not match", expectedUsages, testReport.getUsageIds());

return result;
}

@Before
public void setup()
{
expectedFatals.clear();
expectedErrors.clear();
expectedWarnings.clear();
expectedFatals.clear();
expectedUsages.clear();
}

@Test(expected = NullPointerException.class)
Expand Down Expand Up @@ -268,7 +275,7 @@ public void testDeprecated()
@Test
public void testDisallowed()
{
expectedErrors.add(MessageId.OPF_087);
expectedUsages.add(MessageId.OPF_087);
testProperty("disallowed:prop", PREDEF_VOCABS);
}

Expand Down

0 comments on commit f248483

Please sign in to comment.