Skip to content
This repository was archived by the owner on Nov 21, 2019. It is now read-only.

Commit 3280f35

Browse files
Apply patch to fix Schematron attribute paths (#11)
* Apply patch to fix Schematron attribute paths * Change library and add output * Add comment * Add depth
1 parent 774af72 commit 3280f35

10 files changed

Lines changed: 83 additions & 13 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
/phpcs.xml
44
/phpstan.neon
55
/phpunit.xml
6+
/tmp/
67
/vendor/

bin/update-schematron.php

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,22 @@
33

44
declare(strict_types=1);
55

6+
use GitWrapper\GitWrapper;
67
use Symfony\Component\Filesystem\Filesystem;
78

89
require_once __DIR__.'/../vendor/autoload.php';
910

1011
$filesystem = new Filesystem();
11-
12-
$target = __DIR__.'/../lib/schematron';
13-
14-
$base = 'https://github.com/Schematron/schematron/raw/master';
12+
$git = new GitWrapper();
13+
$git->streamOutput();
14+
15+
$repoUri = 'https://github.com/Schematron/schematron';
16+
$repoDir = __DIR__.'/../tmp/schematron';
17+
$patchesDir = __DIR__.'/../tmp/patches';
18+
$targetDir = __DIR__.'/../lib/schematron';
19+
$patches = [
20+
'https://github.com/Schematron/schematron/pull/81.patch', // Fixes attribute paths.
21+
];
1522
$files = [
1623
'LICENSE',
1724
'trunk/schematron/code/iso_schematron_skeleton_for_xslt1.xsl',
@@ -20,8 +27,29 @@
2027
'trunk/converters/code/ToSchematron/ExtractSchFromXSD.xsl',
2128
];
2229

23-
$filesystem->remove(new FilesystemIterator($target));
30+
if (!$filesystem->exists($repoDir)) {
31+
$filesystem->mkdir($repoDir);
32+
$repo = $git->cloneRepository($repoUri, $repoDir, ['depth' => 1]);
33+
} else {
34+
$repo = $git->workingCopy($repoDir);
35+
$repo->fetch('origin', 'master', ['depth' => 1]);
36+
$repo->reset(['hard' => true], 'origin/master');
37+
}
38+
39+
foreach ($patches as $patch) {
40+
$patchTarget = "${patchesDir}/".md5($patch);
41+
42+
echo "Downloading {$patch} to {$patchTarget}\n";
43+
$filesystem->copy($patch, $patchTarget);
44+
$repo->apply($patchTarget, ['verbose' => true]);
45+
}
46+
47+
$filesystem->remove(new FilesystemIterator($targetDir));
2448

2549
foreach ($files as $file) {
26-
$filesystem->copy("{$base}/${file}", "{$target}/".basename($file));
50+
$origin = "${repoDir}/${file}";
51+
$target = "${targetDir}/".basename($file);
52+
53+
echo "Copying {$origin} to {$target}\n";
54+
$filesystem->copy($origin, $target);
2755
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
},
2121
"require-dev": {
2222
"ext-xsl": "*",
23+
"cpliakas/git-wrapper": "^2.0",
2324
"libero/coding-standard": "^0.3",
2425
"phpstan/phpstan": "^0.10",
2526
"phpstan/phpstan-phpunit": "^0.10",

lib/schematron/iso_schematron_skeleton_for_xslt1.xsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ THE SOFTWARE.
692692

693693

694694
<axsl:template match="@*" mode="schematron-get-full-path">
695+
<axsl:apply-templates select="parent::*" mode="schematron-get-full-path"/>
695696

696697
<!-- XSLT1 syntax -->
697698
<axsl:text>/</axsl:text>

tests/SchematronValidatorTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,15 @@ public function it_fails_on_invalid(string $format) : void
5050
$this->assertEquals(
5151
[
5252
new Failure(
53-
'Must not be empty',
53+
'Element must not be empty',
5454
6,
5555
$xpath->query('/example:parent/example:child')->item(0)
5656
),
57+
new Failure(
58+
'Attribute must not be empty',
59+
6,
60+
$xpath->query('/example:parent/example:child/@attribute')->item(0)
61+
),
5762
],
5863
$e->getFailures()
5964
);

tests/fixtures/invalid-empty-child.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
<parent xmlns="http://example.com">
55

6-
<child> </child>
6+
<child attribute=" "> </child>
77

88
</parent>

tests/fixtures/schema.dtd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@
44
<!ATTLIST parent xmlns CDATA #FIXED 'http://example.com'>
55

66
<!ELEMENT child (#PCDATA)>
7-
<!ATTLIST child xmlns CDATA #FIXED 'http://example.com'>
7+
<!ATTLIST child
8+
xmlns CDATA #FIXED 'http://example.com'
9+
attribute CDATA #IMPLIED
10+
>

tests/fixtures/schema.rng

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,20 @@
1010
<oneOrMore>
1111
<element name="child">
1212
<text/>
13+
<optional>
14+
<attribute name="attribute"/>
15+
</optional>
1316
<sch:pattern>
1417
<sch:rule context="example:child">
1518
<sch:assert test="* or normalize-space()">
16-
Must not be empty
19+
Element must not be empty
20+
</sch:assert>
21+
</sch:rule>
22+
</sch:pattern>
23+
<sch:pattern>
24+
<sch:rule context="example:child/@attribute">
25+
<sch:assert test="* or normalize-space()" subject="..">
26+
Attribute must not be empty
1727
</sch:assert>
1828
</sch:rule>
1929
</sch:pattern>

tests/fixtures/schema.sch

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77
<pattern>
88
<rule context="example:child">
99
<assert test="* or normalize-space()">
10-
Must not be empty
10+
Element must not be empty
11+
</assert>
12+
</rule>
13+
</pattern>
14+
<pattern>
15+
<rule context="example:child/@attribute">
16+
<assert test="* or normalize-space()">
17+
Attribute must not be empty
1118
</assert>
1219
</rule>
1320
</pattern>

tests/fixtures/schema.xsd

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,32 @@
1212
<element name="parent">
1313
<complexType>
1414
<sequence>
15-
<element name="child" type="string">
15+
<element name="child">
1616
<annotation>
1717
<appinfo>
1818
<sch:pattern>
1919
<sch:rule context="example:child">
2020
<sch:assert test="* or normalize-space()">
21-
Must not be empty
21+
Element must not be empty
22+
</sch:assert>
23+
</sch:rule>
24+
</sch:pattern>
25+
<sch:pattern>
26+
<sch:rule context="example:child/@attribute">
27+
<sch:assert test="* or normalize-space()" subject="..">
28+
Attribute must not be empty
2229
</sch:assert>
2330
</sch:rule>
2431
</sch:pattern>
2532
</appinfo>
2633
</annotation>
34+
<complexType>
35+
<simpleContent>
36+
<extension base="string">
37+
<attribute name="attribute" type="string"/>
38+
</extension>
39+
</simpleContent>
40+
</complexType>
2741
</element>
2842
</sequence>
2943
</complexType>

0 commit comments

Comments
 (0)