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

Apply patch to fix Schematron attribute paths #11

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/phpcs.xml
/phpstan.neon
/phpunit.xml
/tmp/
/vendor/
40 changes: 34 additions & 6 deletions bin/update-schematron.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@

declare(strict_types=1);

use GitWrapper\GitWrapper;
use Symfony\Component\Filesystem\Filesystem;

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

$filesystem = new Filesystem();

$target = __DIR__.'/../lib/schematron';

$base = 'https://github.com/Schematron/schematron/raw/master';
$git = new GitWrapper();
$git->streamOutput();

$repoUri = 'https://github.com/Schematron/schematron';
$repoDir = __DIR__.'/../tmp/schematron';
$patchesDir = __DIR__.'/../tmp/patches';
$targetDir = __DIR__.'/../lib/schematron';
$patches = [
thewilkybarkid marked this conversation as resolved.
Show resolved Hide resolved
'https://github.com/Schematron/schematron/pull/81.patch', // Fixes attribute paths.
];
$files = [
'LICENSE',
'trunk/schematron/code/iso_schematron_skeleton_for_xslt1.xsl',
Expand All @@ -20,8 +27,29 @@
'trunk/converters/code/ToSchematron/ExtractSchFromXSD.xsl',
];

$filesystem->remove(new FilesystemIterator($target));
if (!$filesystem->exists($repoDir)) {
$filesystem->mkdir($repoDir);
$repo = $git->cloneRepository($repoUri, $repoDir, ['depth' => 1]);
} else {
$repo = $git->workingCopy($repoDir);
$repo->fetch('origin', 'master', ['depth' => 1]);
$repo->reset(['hard' => true], 'origin/master');
}

foreach ($patches as $patch) {
$patchTarget = "${patchesDir}/".md5($patch);

echo "Downloading {$patch} to {$patchTarget}\n";
$filesystem->copy($patch, $patchTarget);
$repo->apply($patchTarget, ['verbose' => true]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think by default the patches remain tracked in Git as a change not staged for commit. The interaction with updates should work because then a git reset --hard will be performed.

}

$filesystem->remove(new FilesystemIterator($targetDir));

foreach ($files as $file) {
$filesystem->copy("{$base}/${file}", "{$target}/".basename($file));
$origin = "${repoDir}/${file}";
$target = "${targetDir}/".basename($file);

echo "Copying {$origin} to {$target}\n";
$filesystem->copy($origin, $target);
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"require-dev": {
"ext-xsl": "*",
"cpliakas/git-wrapper": "^2.0",
"libero/coding-standard": "^0.3",
"phpstan/phpstan": "^0.10",
"phpstan/phpstan-phpunit": "^0.10",
Expand Down
1 change: 1 addition & 0 deletions lib/schematron/iso_schematron_skeleton_for_xslt1.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ THE SOFTWARE.


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

<!-- XSLT1 syntax -->
<axsl:text>/</axsl:text>
Expand Down
7 changes: 6 additions & 1 deletion tests/SchematronValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,15 @@ public function it_fails_on_invalid(string $format) : void
$this->assertEquals(
[
new Failure(
'Must not be empty',
'Element must not be empty',
6,
$xpath->query('/example:parent/example:child')->item(0)
),
new Failure(
'Attribute must not be empty',
6,
$xpath->query('/example:parent/example:child/@attribute')->item(0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this enough context? I guess the DOMNode contained in Failure has some information about what element it was on?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, since it's retrieved from the document.

),
],
$e->getFailures()
);
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/invalid-empty-child.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

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

<child> </child>
<child attribute=" "> </child>

</parent>
5 changes: 4 additions & 1 deletion tests/fixtures/schema.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
<!ATTLIST parent xmlns CDATA #FIXED 'http://example.com'>

<!ELEMENT child (#PCDATA)>
<!ATTLIST child xmlns CDATA #FIXED 'http://example.com'>
<!ATTLIST child
xmlns CDATA #FIXED 'http://example.com'
attribute CDATA #IMPLIED
>
12 changes: 11 additions & 1 deletion tests/fixtures/schema.rng
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@
<oneOrMore>
<element name="child">
<text/>
<optional>
<attribute name="attribute"/>
</optional>
<sch:pattern>
<sch:rule context="example:child">
<sch:assert test="* or normalize-space()">
Must not be empty
Element must not be empty
</sch:assert>
</sch:rule>
</sch:pattern>
<sch:pattern>
<sch:rule context="example:child/@attribute">
<sch:assert test="* or normalize-space()" subject="..">
Attribute must not be empty
</sch:assert>
</sch:rule>
</sch:pattern>
Expand Down
9 changes: 8 additions & 1 deletion tests/fixtures/schema.sch
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
<pattern>
<rule context="example:child">
<assert test="* or normalize-space()">
Must not be empty
Element must not be empty
</assert>
</rule>
</pattern>
<pattern>
<rule context="example:child/@attribute">
<assert test="* or normalize-space()">
Attribute must not be empty
</assert>
</rule>
</pattern>
Expand Down
18 changes: 16 additions & 2 deletions tests/fixtures/schema.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,32 @@
<element name="parent">
<complexType>
<sequence>
<element name="child" type="string">
<element name="child">
<annotation>
<appinfo>
<sch:pattern>
<sch:rule context="example:child">
<sch:assert test="* or normalize-space()">
Must not be empty
Element must not be empty
</sch:assert>
</sch:rule>
</sch:pattern>
<sch:pattern>
<sch:rule context="example:child/@attribute">
<sch:assert test="* or normalize-space()" subject="..">
Attribute must not be empty
</sch:assert>
</sch:rule>
</sch:pattern>
</appinfo>
</annotation>
<complexType>
<simpleContent>
<extension base="string">
<attribute name="attribute" type="string"/>
</extension>
</simpleContent>
</complexType>
</element>
</sequence>
</complexType>
Expand Down