seboettg / citeproc-php

Full-featured CSL 1.0.1 processor for PHP
MIT License
75 stars 39 forks source link

Unit tests fails #76

Closed AS-adci closed 4 years ago

AS-adci commented 4 years ago

Please follow the general troubleshooting steps first:

Bug reports:

Unit test has 3 fails.

Used CSL stylesheet:

apa

Used CSL metadata

   [{
            "author": [
              {
                "family": "Doe",
                "given": "John",
                "id": "doe"
              },
              {
                "family": "Müller",
                "given": "Alexander"
              }
            ],
            "id": "item-1",
            "issued": {
              "date-parts": [
                [
                  "2001"
                ]
              ]
            },
            "title": "My Anonymous Heritage",
            "type": "book"
        }]

Test results

PHPUnit 6.0.13 by Sebastian Bergmann and contributors.

There were 3 failures:

1) Seboettg\CiteProc\Rendering\Name\NameTest::testEnrichMarkupNames
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 '<div class="csl-bib-body">\n
-  <div class="csl-entry"><a href="https://example.org/author/doe" title="Doe, J.">Doe, J.</a>, &#38; Müller, A. (2001). <i>My Anonymous Heritage</i>.</div>\n
+  <div class="csl-entry"><a href="https://example.org/author/doe" title="Doe, J.">Doe, J.</a>, &#38; Müller, A.. (2001). <i>My Anonymous Heritage</i>.</div>\n
 </div>'

/app/drupal/vendor/seboettg/citeproc-php/tests/src/Rendering/Name/NameTest.php:247

2) Seboettg\CiteProc\Rendering\Name\NameTest::testEnrichMarkupNamesCitationsAndBibliography
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 '<div class="csl-bib-body">\n
-  <div class="csl-entry"><a id="item-1"></a><a href="https://example.org/author/doe" title="Doe, J.">Doe, J.</a>, &#38; Müller, A. (2001). <i>My Anonymous Heritage</i>.</div>\n
+  <div class="csl-entry"><a id="item-1"></a><a href="https://example.org/author/doe" title="Doe, J.">Doe, J.</a>, &#38; Müller, A.. (2001). <i>My Anonymous Heritage</i>.</div>\n
 </div>'

/app/drupal/vendor/seboettg/citeproc-php/tests/src/Rendering/Name/NameTest.php:302

3) Seboettg\CiteProc\Rendering\TextTest::testEnrichMarkupURL
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 '<div class="csl-bib-body">\n
-  <div class="csl-entry">Doe, J., &#38; Müller, A. (2001). My Anonymous Heritage. In <i>Heritages and taxes. How to avoid responsibility.</i> (pp. 123-127). Retrieved from <a href="https://example.org/publication/item-1">https://example.org/publication/item-1</a></div>\n
+  <div class="csl-entry">Doe, J., &#38; Müller, A. (2001). My Anonymous Heritage. In <i>Heritages and taxes. How to avoid responsibility.</i> (pp. 123-127). Initiative Neue Soziale Marktwirtschaft (INSM). <a href="https://example.org/publication/item-1">https://example.org/publication/item-1</a></div>\n
 </div>'

/app/drupal/vendor/seboettg/citeproc-php/tests/src/Rendering/TextTest.php:180

FAILURES!
Tests: 185, Assertions: 415, Failures: 3.

Comment

I don't sure about 1 and 2. But it looks like something wrong with delimiter processing. 3 looks like it needed to update test case.

It would be great if it will be fixed. Thank you.

AS-adci commented 4 years ago

Ok. I've found place which make tests failed.

\Seboettg\CiteProc\Rendering\Group::render lines 114-123

if ($delimiter && ($elementCount < count($this->children))) {
//check to see if the delimiter is already the last character of the text string
//if so, remove it so we don't have two of them when the group will be merged
$stext = strip_tags(trim($text));
if ((strrpos($stext, $delimiter[0]) + 1) == strlen($stext) && strlen($stext) > 1) {
$text = str_replace($stext, '----REPLACE----', $text);
$stext = substr($stext, 0, -1);
$text = str_replace('----REPLACE----', $stext, $text);
}
}

In test we have next string: <a href="https://example.org/author/doe" title="Doe, J.">Doe, J.</a>, &#38; Müller, A. In the first action(after condition) we strip tags. Then try to replace string and it doesn't work because original string has tags. So it doesn't trim delimiter in the end in the result.

seboettg commented 4 years ago

Hi @AS-adci ! please check if this issue is solved with the latest commit https://github.com/seboettg/citeproc-php/commit/6258cd9c49264a5bc1b357211a5c670b7da9d937 Thank you in advance!

seboettg commented 4 years ago

Version 2.2.0 has been released. Please update citeproc-php and check if the issue is solved. If yes, please close this ticket.