Skip to content

Commit

Permalink
fix: items were listed twice and/or with null values in the JSON report
Browse files Browse the repository at this point in the history
This was caused by a regression after the refactoring of the parsing of the container structure and package documents.

This commit adds a new feature file to write tests for the JSON report.

The first test scenarios check basic assertions:
- JSON is well-formed
- the items array has the correct number of items (no items duplication)
- the checksum field

Fix #1475, Fix #1490
  • Loading branch information
rdeltour committed Apr 21, 2023
1 parent 13a11b9 commit b2c5d8c
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java
Expand Up @@ -28,7 +28,6 @@
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.w3c.epubcheck.constants.MIMEType;
Expand Down Expand Up @@ -319,7 +318,7 @@ private boolean checkContainerStructure(OCFCheckerState state)
new OCFFilenameChecker(resource.getPath(), state.context().build()).check();

// Report entry metadata
reportFeatures(resource.getProperties());
reportFeatures(resource);

// Add the resource to the container model
state.addResource(resource);
Expand Down Expand Up @@ -553,11 +552,12 @@ private EPUBVersion checkPublicationVersion(OCFCheckerState state)
}
}

private void reportFeatures(Map<FeatureEnum, String> features)
private void reportFeatures(OCFResource resource)
{
for (FeatureEnum feature : features.keySet())
for (FeatureEnum feature : resource.getProperties().keySet())
{
report.info(context.path, feature, features.get(feature));
// report.info(context.path, feature, resource.getProperties().get(feature));
report.info(resource.getPath(), feature, resource.getProperties().get(feature));
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/adobe/epubcheck/opf/OPFHandler.java
Expand Up @@ -287,8 +287,6 @@ else if (name.equals("item"))

String mediaOverlay = e.getAttribute("media-overlay");
itemBuilder.mediaOverlay(mediaOverlay);

report.info(href, FeatureEnum.UNIQUE_IDENT, id);
}
}
}
Expand Down Expand Up @@ -641,6 +639,7 @@ private void buildItems()
*/
protected void reportItem(OPFItem item)
{
report.info(item.getPath(), FeatureEnum.UNIQUE_IDENT, item.getId());
if (item.isInSpine())
{
report.info(item.getPath(), FeatureEnum.IS_SPINEITEM, "true");
Expand Down
11 changes: 11 additions & 0 deletions src/test/resources/reporting/files/minimal/EPUB/content_001.xhtml
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html xmlns:epub="http://www.idpf.org/2007/ops" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8"/>
<title>Minimal EPUB</title>
</head>
<body>
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
</body>
</html>
14 changes: 14 additions & 0 deletions src/test/resources/reporting/files/minimal/EPUB/nav.xhtml
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
<head>
<meta charset="utf-8"/>
<title>Minimal Nav</title>
</head>
<body>
<nav epub:type="toc">
<ol>
<li><a href="content_001.xhtml">content 001</a></li>
</ol>
</nav>
</body>
</html>
16 changes: 16 additions & 0 deletions src/test/resources/reporting/files/minimal/EPUB/package.opf
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="q">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title id="title">Minimal EPUB 3.0</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="q">NOID</dc:identifier>
<meta property="dcterms:modified">2017-06-14T00:00:01Z</meta>
</metadata>
<manifest>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
</manifest>
<spine>
<itemref idref="content_001" />
</spine>
</package>
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
1 change: 1 addition & 0 deletions src/test/resources/reporting/files/minimal/mimetype
@@ -0,0 +1 @@
application/epub+zip
15 changes: 15 additions & 0 deletions src/test/resources/reporting/json-report.feature
@@ -0,0 +1,15 @@
Feature: EPUBCheck - JSON Report tests

Checks the JSON report format


Background:
Given EPUB test files located at '/reporting/files/'
And the reporting format is set to JSON
And EPUBCheck with default settings

Scenario: Basic well-formedness checks
When checking EPUB 'minimal'
Then the JSON report is valid
And JSON at '$.items' contains 5 items
And JSON at '$..checkSum' has no null values

0 comments on commit b2c5d8c

Please sign in to comment.