From b864a4b7b706a5bdaf55af1c87ec400e2c7185ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ttger?= Date: Thu, 19 May 2022 23:19:00 +0200 Subject: [PATCH 01/11] #123 changed to new repository for stylesheets --- README.md | 6 +++--- composer.json | 6 +++--- src/StyleSheet.php | 41 +++++++++++++++++++++++++---------------- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index f3ec3098..bc371341 100644 --- a/README.md +++ b/README.md @@ -54,11 +54,11 @@ Add the following lines to your `composer.json` file in order to add required pr { "type": "package", "package": { - "name": "citation-style-language/styles-distribution", + "name": "citation-style-language/styles", "version":"1.0.0", "source": { "type": "git", - "url": "https://github.com/citation-style-language/styles-distribution.git", + "url": "https://github.com/citation-style-language/styles.git", "reference": "master" } } @@ -66,7 +66,7 @@ Add the following lines to your `composer.json` file in order to add required pr ], "require": { "citation-style-language/locales":"@dev", - "citation-style-language/styles-distribution":"@dev", + "citation-style-language/styles":"@dev", "seboettg/citeproc-php": "^2" } } diff --git a/composer.json b/composer.json index fb4969ed..5459ebc6 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ { "name": "Sebastian Böttger", "email": "seboettg@gmail.com", - "homepage": "http://sebastianboettger.net", + "homepage": "https://sebastianboettger.net", "role": "Developer" } ], @@ -46,13 +46,13 @@ }, "scripts": { "post-install-cmd": [ - "./install.sh styles-distribution", + "./install.sh styles", "./install.sh locales", "@compile-test-cases", "chmod +x vendor/bin/phpunit" ], "post-update-cmd": [ - "./install.sh styles-distribution", + "./install.sh styles", "./install.sh locales", "@compile-test-cases", "chmod +x vendor/bin/phpunit" diff --git a/src/StyleSheet.php b/src/StyleSheet.php index b42d5530..4126e503 100644 --- a/src/StyleSheet.php +++ b/src/StyleSheet.php @@ -1,4 +1,5 @@ {'primary-dialects'}->{$langKey})) { - $data = file_get_contents( - $localesPath."locales-".$metadata->{'primary-dialects'}->{$langKey}.'.xml' + return self::readFileContentsOrThrowException( + sprintf("%s/locales-%s.xml", $localesPath, $metadata->{'primary-dialects'}->{$langKey}) ); } } + throw new CiteProcException("No Locale file found for $langKey"); + } - return $data; + /** + * @throws CiteProcException + */ + private static function readFileContentsOrThrowException($path): string + { + $fileContent = file_get_contents($path); + if (false === $fileContent) { + throw new CiteProcException("Couldn't read $path"); + } + return $fileContent; } /** @@ -70,8 +81,8 @@ public static function loadLocales($langKey) */ public static function loadLocalesMetadata() { - $localesMetadataPath = self::vendorPath()."/citation-style-language/locales/locales.json"; - return json_decode(file_get_contents($localesMetadataPath)); + $localesMetadataPath = self::vendorPath() . "/citation-style-language/locales/locales.json"; + return json_decode(self::readFileContentsOrThrowException($localesMetadataPath)); } /** @@ -80,11 +91,9 @@ public static function loadLocalesMetadata() */ private static function vendorPath() { - include_once realpath(__DIR__.'/../').'/vendorPath.php'; + include_once realpath(__DIR__ . '/../') . '/vendorPath.php'; if (!($vendorPath = vendorPath())) { - // @codeCoverageIgnoreStart throw new CiteProcException('vendor path not found. Use composer to initialize your project'); - // @codeCoverageIgnoreEnd } return $vendorPath; } From 58001c9b05215daae144959bb10cbfb075043f54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ttger?= Date: Fri, 20 May 2022 10:56:38 +0200 Subject: [PATCH 02/11] #125 refactored namespaces of unit tests --- composer.json | 2 +- tests/src/BugfixTest.php | 14 +++++------ tests/src/CiteProcTest.php | 23 +++++++++++++++++- tests/src/ContextTest.php | 9 ++++++- tests/src/Locale/LocaleTest.php | 6 ++--- tests/src/LocatorTest.php | 2 +- tests/src/Rendering/Choose/ChooseTest.php | 4 ++-- tests/src/Rendering/Date/DateTest.php | 6 ++--- tests/src/Rendering/GroupTest.php | 26 +++++++++++++++++---- tests/src/Rendering/LabelTest.php | 7 +++--- tests/src/Rendering/Name/NameTest.php | 4 ++-- tests/src/Rendering/Name/NameorderTest.php | 9 ++----- tests/src/Rendering/Name/NamesTest.php | 9 +++++-- tests/src/Rendering/Name/SubstituteTest.php | 4 ++-- tests/src/Rendering/NumberTest.php | 5 ++-- tests/src/Rendering/TextTest.php | 4 ++-- tests/src/Style/MacroTest.php | 2 +- tests/src/Style/Sort/SortTest.php | 4 ++-- tests/src/StyleSheetTest.php | 14 ++++++++--- tests/src/Styles/AffixesTest.php | 4 ++-- tests/src/Styles/DisplayTest.php | 6 ++--- tests/src/TestSuiteTestCaseTrait.php | 3 ++- tests/src/Util/NumberHelperTest.php | 3 ++- tests/src/Util/PageHelperTest.php | 5 ++-- tests/src/Util/StringHelperTest.php | 9 ++----- 25 files changed, 116 insertions(+), 68 deletions(-) diff --git a/composer.json b/composer.json index 5459ebc6..c6137792 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ }, "autoload-dev": { "psr-4": { - "Seboettg\\CiteProc\\": "tests/src/" + "Seboettg\\CiteProc\\Test\\": "tests/src/" } }, "require": { diff --git a/tests/src/BugfixTest.php b/tests/src/BugfixTest.php index 816aac93..1fa8f012 100644 --- a/tests/src/BugfixTest.php +++ b/tests/src/BugfixTest.php @@ -7,15 +7,13 @@ * @license https://opensource.org/licenses/MIT */ -namespace Seboettg\CiteProc; +namespace Seboettg\CiteProc\Test; use PHPUnit\Framework\TestCase; +use Seboettg\CiteProc\CiteProc; +use Seboettg\CiteProc\Exception\CiteProcException; +use Seboettg\CiteProc\StyleSheet; -/** - * Class BugfixTest - * @package Seboettg\CiteProc - * @author Sebastian Böttger - */ class BugfixTest extends TestCase { @@ -57,7 +55,7 @@ public function testBugfixGithub50() } /** - * @throws Exception\CiteProcException + * @throws CiteProcException */ public function testBugfixGithub58() { @@ -72,7 +70,7 @@ public function testBugfixGithub58() } /** - * @throws Exception\CiteProcException + * @throws CiteProcException */ public function testBugfixGithub59() { diff --git a/tests/src/CiteProcTest.php b/tests/src/CiteProcTest.php index e0d0be64..b0fd1564 100644 --- a/tests/src/CiteProcTest.php +++ b/tests/src/CiteProcTest.php @@ -7,9 +7,12 @@ * @license https://opensource.org/licenses/MIT */ -namespace Seboettg\CiteProc; +namespace Seboettg\CiteProc\Test; use PHPUnit\Framework\TestCase; +use Seboettg\CiteProc\CiteProc; +use Seboettg\CiteProc\Exception\CiteProcException; +use Seboettg\CiteProc\StyleSheet; class CiteProcTest extends TestCase { @@ -61,6 +64,9 @@ public function testRenderCitationNumber() $this->runTestSuite("text_renderCitationNumber"); } + /** + * @throws CiteProcException + */ public function testRenderCssStyle() { $style = StyleSheet::loadStyleSheet("international-journal-of-humanoid-robotics"); @@ -71,6 +77,9 @@ public function testRenderCssStyle() $this->assertTrue(strpos($cssStyles, "csl-right-inline") !== false); } + /** + * @throws CiteProcException + */ public function testRenderCssStyleHangingIndent() { $style = StyleSheet::loadStyleSheet("din-1505-2"); @@ -80,6 +89,9 @@ public function testRenderCssStyleHangingIndent() $this->assertTrue(strpos($cssStyles, "text-indent: -2em") !== false); } + /** + * @throws CiteProcException + */ public function testRenderCssStyleLineAndEntrySpacing() { $style = StyleSheet::loadStyleSheet("harvard-north-west-university"); @@ -90,6 +102,9 @@ public function testRenderCssStyleLineAndEntrySpacing() $this->assertTrue(strpos($cssStyles, "padding-left: 2em") !== false); } + /** + * @throws CiteProcException + */ public function testGetInfo() { $style = StyleSheet::loadStyleSheet("harvard-north-west-university"); @@ -100,6 +115,9 @@ public function testGetInfo() $this->assertEquals("North-West University - Harvard", $info->getTitle()); } + /** + * @throws CiteProcException + */ public function testFilterCitations() { $style = StyleSheet::loadStyleSheet("harvard-north-west-university"); @@ -167,6 +185,9 @@ public function testFilterCitations() } + /** + * @throws CiteProcException + */ public function testRenderCitationNumberResultAsArray() { $style = StyleSheet::loadStyleSheet("elsevier-vancouver"); diff --git a/tests/src/ContextTest.php b/tests/src/ContextTest.php index 758eff48..5fb96268 100644 --- a/tests/src/ContextTest.php +++ b/tests/src/ContextTest.php @@ -7,10 +7,14 @@ * @license https://opensource.org/licenses/MIT */ -namespace Seboettg\CiteProc; +namespace Seboettg\CiteProc\Test; use PHPUnit\Framework\TestCase; +use Seboettg\CiteProc\CiteProc; +use Seboettg\CiteProc\Context; use Seboettg\CiteProc\Data\DataList; +use Seboettg\CiteProc\Exception\CiteProcException; +use Seboettg\CiteProc\StyleSheet; class ContextTest extends TestCase { @@ -28,6 +32,9 @@ class ContextTest extends TestCase */ private $context; + /** + * @throws CiteProcException + */ public function setUp(): void { $style = StyleSheet::loadStyleSheet("din-1505-2"); diff --git a/tests/src/Locale/LocaleTest.php b/tests/src/Locale/LocaleTest.php index d17febfe..27d3fac3 100644 --- a/tests/src/Locale/LocaleTest.php +++ b/tests/src/Locale/LocaleTest.php @@ -7,13 +7,11 @@ * @license https://opensource.org/licenses/MIT */ -namespace Seboettg\CiteProc\Locale; +namespace Seboettg\CiteProc\Test\Locale; use PHPUnit\Framework\TestCase; +use Seboettg\CiteProc\Locale\Locale; -/** - * Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2012-12-02 at 13:29:49. - */ class LocaleTest extends TestCase { /** diff --git a/tests/src/LocatorTest.php b/tests/src/LocatorTest.php index 8ed37e01..b26da3f9 100644 --- a/tests/src/LocatorTest.php +++ b/tests/src/LocatorTest.php @@ -5,7 +5,7 @@ * created at 07.04.20, 18:49 */ -namespace Seboettg\CiteProc; +namespace Seboettg\CiteProc\Test; use PHPUnit\Framework\TestCase; diff --git a/tests/src/Rendering/Choose/ChooseTest.php b/tests/src/Rendering/Choose/ChooseTest.php index 95b673c7..941ea8a8 100644 --- a/tests/src/Rendering/Choose/ChooseTest.php +++ b/tests/src/Rendering/Choose/ChooseTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT */ -namespace Seboettg\CiteProc\Node\Choose\Choose; +namespace Seboettg\CiteProc\Test\Rendering\Choose; use PHPUnit\Framework\TestCase; use Seboettg\CiteProc\CiteProc; @@ -15,7 +15,7 @@ use Seboettg\CiteProc\Exception\ClassNotFoundException; use Seboettg\CiteProc\Exception\InvalidStylesheetException; use Seboettg\CiteProc\Rendering\Choose\Choose; -use Seboettg\CiteProc\TestSuiteTestCaseTrait; +use Seboettg\CiteProc\Test\TestSuiteTestCaseTrait; use SimpleXMLElement; class ChooseTest extends TestCase diff --git a/tests/src/Rendering/Date/DateTest.php b/tests/src/Rendering/Date/DateTest.php index fb7681b8..717b14b7 100644 --- a/tests/src/Rendering/Date/DateTest.php +++ b/tests/src/Rendering/Date/DateTest.php @@ -1,5 +1,5 @@ '; - $group = new Group(new \SimpleXMLElement($str), null); + $group = new Group(new SimpleXMLElement($str), null); $this->assertEquals("abgerufen von http://foo.bar", $group->render(json_decode($this->data))); } + /** + * @throws InvalidStylesheetException + * @throws Exception + */ public function testRenderAffixes() { $str = ''; - $group = new Group(new \SimpleXMLElement($str), null); + $group = new Group(new SimpleXMLElement($str), null); $this->assertEquals("[abgerufen von http://foo.bar]", $group->render(json_decode($this->data))); } + /** + * @throws InvalidStylesheetException + * @throws Exception + */ public function testRenderDisplay() { $str = ''; - $group = new Group(new \SimpleXMLElement($str), null); + $group = new Group(new SimpleXMLElement($str), null); $this->assertEquals("
[abgerufen von http://foo.bar]
", $group->render(json_decode($this->data))); } diff --git a/tests/src/Rendering/LabelTest.php b/tests/src/Rendering/LabelTest.php index 25e77872..d736efa6 100644 --- a/tests/src/Rendering/LabelTest.php +++ b/tests/src/Rendering/LabelTest.php @@ -1,5 +1,5 @@ - */ class NameorderTest extends TestCase { use TestSuiteTestCaseTrait; diff --git a/tests/src/Rendering/Name/NamesTest.php b/tests/src/Rendering/Name/NamesTest.php index d4c10533..6c57f810 100644 --- a/tests/src/Rendering/Name/NamesTest.php +++ b/tests/src/Rendering/Name/NamesTest.php @@ -7,10 +7,15 @@ * @license https://opensource.org/licenses/MIT */ -namespace Seboettg\CiteProc\Rendering\Names; +namespace Seboettg\CiteProc\Test\Rendering\Name; +use Exception; use PHPUnit\Framework\TestCase; -use Seboettg\CiteProc\TestSuiteTestCaseTrait; +use Seboettg\CiteProc\CiteProc; +use Seboettg\CiteProc\Context; +use Seboettg\CiteProc\Rendering\Name\Names; +use Seboettg\CiteProc\Test\TestSuiteTestCaseTrait; +use SimpleXMLElement; class NamesTest extends TestCase { diff --git a/tests/src/Rendering/Name/SubstituteTest.php b/tests/src/Rendering/Name/SubstituteTest.php index 99e59948..06de3282 100644 --- a/tests/src/Rendering/Name/SubstituteTest.php +++ b/tests/src/Rendering/Name/SubstituteTest.php @@ -7,10 +7,10 @@ * @license https://opensource.org/licenses/MIT */ -namespace Seboettg\CiteProc\Rendering\Name; +namespace Seboettg\CiteProc\Test\Rendering\Name; use PHPUnit\Framework\TestCase; -use Seboettg\CiteProc\TestSuiteTestCaseTrait; +use Seboettg\CiteProc\Test\TestSuiteTestCaseTrait; class SubstituteTest extends TestCase diff --git a/tests/src/Rendering/NumberTest.php b/tests/src/Rendering/NumberTest.php index a70d5329..5d2a79f3 100644 --- a/tests/src/Rendering/NumberTest.php +++ b/tests/src/Rendering/NumberTest.php @@ -7,13 +7,14 @@ * @license https://opensource.org/licenses/MIT */ -namespace Seboettg\CiteProc\Rendering; +namespace Seboettg\CiteProc\Test\Rendering; use PHPUnit\Framework\TestCase; use Seboettg\CiteProc\Locale\Locale; use Seboettg\CiteProc\CiteProc; use Seboettg\CiteProc\Context; -use Seboettg\CiteProc\TestSuiteTestCaseTrait; +use Seboettg\CiteProc\Rendering\Number; +use Seboettg\CiteProc\Test\TestSuiteTestCaseTrait; class NumberTest extends TestCase { diff --git a/tests/src/Rendering/TextTest.php b/tests/src/Rendering/TextTest.php index c407cfe4..16d70e04 100644 --- a/tests/src/Rendering/TextTest.php +++ b/tests/src/Rendering/TextTest.php @@ -7,12 +7,12 @@ * @license https://opensource.org/licenses/MIT */ -namespace Seboettg\CiteProc\Rendering; +namespace Seboettg\CiteProc\Test\Rendering; use PHPUnit\Framework\TestCase; use Seboettg\CiteProc\CiteProc; use Seboettg\CiteProc\StyleSheet; -use Seboettg\CiteProc\TestSuiteTestCaseTrait; +use Seboettg\CiteProc\Test\TestSuiteTestCaseTrait; class TextTest extends TestCase { diff --git a/tests/src/Style/MacroTest.php b/tests/src/Style/MacroTest.php index 410f2f23..eeb5a1ae 100644 --- a/tests/src/Style/MacroTest.php +++ b/tests/src/Style/MacroTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT */ -namespace Seboettg\CiteProc\Rendering; +namespace Seboettg\CiteProc\Test\Rendering; use PHPUnit\Framework\TestCase; use Seboettg\CiteProc\CiteProc; diff --git a/tests/src/Style/Sort/SortTest.php b/tests/src/Style/Sort/SortTest.php index 9d4b46fe..f046e768 100644 --- a/tests/src/Style/Sort/SortTest.php +++ b/tests/src/Style/Sort/SortTest.php @@ -7,11 +7,11 @@ * @license https://opensource.org/licenses/MIT */ -namespace Seboettg\CiteProc\Style\Sort; +namespace Seboettg\CiteProc\Test\Style\Sort; use PHPUnit\Framework\TestCase; use Seboettg\CiteProc\CiteProc; -use Seboettg\CiteProc\TestSuiteTestCaseTrait; +use Seboettg\CiteProc\Test\TestSuiteTestCaseTrait; class SortTest extends TestCase { diff --git a/tests/src/StyleSheetTest.php b/tests/src/StyleSheetTest.php index 5cd1073c..b1374254 100644 --- a/tests/src/StyleSheetTest.php +++ b/tests/src/StyleSheetTest.php @@ -7,9 +7,12 @@ * @license https://opensource.org/licenses/MIT */ -namespace Seboettg\CiteProc; +namespace Seboettg\CiteProc\Test; +use Exception; use PHPUnit\Framework\TestCase; +use Seboettg\CiteProc\Exception\CiteProcException; +use Seboettg\CiteProc\StyleSheet; use SimpleXMLElement; class StyleSheetTest extends TestCase @@ -17,7 +20,8 @@ class StyleSheetTest extends TestCase /** * @coversNothing - * @throws Exception\CiteProcException + * @throws CiteProcException + * @throws Exception */ public function testLoadStyleSheet() { @@ -39,7 +43,8 @@ public function testLoadStyleSheet() /** * @coversNothing - * @throws Exception\CiteProcException + * @throws CiteProcException + * @throws Exception */ public function testLoadLocales() { @@ -62,6 +67,7 @@ public function testLoadLocales() /** * @coversNothing + * @throws CiteProcException */ public function testLoadLocalesMetadata() { @@ -73,6 +79,8 @@ public function testLoadLocalesMetadata() /** * @coversNothing + * @throws CiteProcException + * @throws Exception */ public function testLoadPrimaryDialectLocale() { diff --git a/tests/src/Styles/AffixesTest.php b/tests/src/Styles/AffixesTest.php index 50209ebc..a72310f4 100644 --- a/tests/src/Styles/AffixesTest.php +++ b/tests/src/Styles/AffixesTest.php @@ -7,10 +7,10 @@ * @license https://opensource.org/licenses/MIT */ -namespace Seboettg\CiteProc\Styles; +namespace Seboettg\CiteProc\Test\Styles; use PHPUnit\Framework\TestCase; -use Seboettg\CiteProc\TestSuiteTestCaseTrait; +use Seboettg\CiteProc\Test\TestSuiteTestCaseTrait; class AffixesTest extends TestCase { diff --git a/tests/src/Styles/DisplayTest.php b/tests/src/Styles/DisplayTest.php index 41151e8e..5fa9fed0 100644 --- a/tests/src/Styles/DisplayTest.php +++ b/tests/src/Styles/DisplayTest.php @@ -1,5 +1,5 @@ - */ class StringHelperTest extends TestCase { public function testCamelCase2Hyphen() From aa910aff44c25454a841a821274ef95084df7846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ttger?= Date: Fri, 20 May 2022 11:19:48 +0200 Subject: [PATCH 03/11] #115 respecting cs:label position before or after cs:name --- src/Rendering/Name/Names.php | 27 ++++++++++++++++++- tests/src/Rendering/Name/NamesTest.php | 36 ++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/Rendering/Name/Names.php b/src/Rendering/Name/Names.php index 71d2e6a8..ae4c0089 100644 --- a/src/Rendering/Name/Names.php +++ b/src/Rendering/Name/Names.php @@ -110,6 +110,11 @@ class Names implements Rendering, HasParent private $parent; + /** + * @var bool + */ + private $renderLabelBeforeName = false; + /** * Names constructor. * @@ -124,10 +129,14 @@ public function __construct(SimpleXMLElement $node, $parent) /** * @var SimpleXMLElement $child */ + foreach ($node->children() as $child) { switch ($child->getName()) { case "name": $this->name = Factory::create($child, $this); + if ($this->label !== null) { + $this->renderLabelBeforeName = true; + } break; case "label": $this->label = Factory::create($child); @@ -246,7 +255,7 @@ public function render($data, $citationNumber = null) * @param $name * @return string */ - private function appendLabel($data, $var, $name) + private function appendLabel($data, $var, $name): string { $this->label->setVariable($var); if (in_array($this->label->getForm(), ["verb", "verb-short"])) { @@ -381,4 +390,20 @@ private function filterEmpty(array $results) return !empty($item); }); } + + /** + * @return bool + */ + public function isRenderLabelBeforeName(): bool + { + return $this->renderLabelBeforeName; + } + + /** + * @param bool $renderLabelBeforeName + */ + public function setRenderLabelBeforeName(bool $renderLabelBeforeName): void + { + $this->renderLabelBeforeName = $renderLabelBeforeName; + } } diff --git a/tests/src/Rendering/Name/NamesTest.php b/tests/src/Rendering/Name/NamesTest.php index 6c57f810..edfeb310 100644 --- a/tests/src/Rendering/Name/NamesTest.php +++ b/tests/src/Rendering/Name/NamesTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Seboettg\CiteProc\CiteProc; use Seboettg\CiteProc\Context; +use Seboettg\CiteProc\Exception\InvalidStylesheetException; use Seboettg\CiteProc\Rendering\Name\Names; use Seboettg\CiteProc\Test\TestSuiteTestCaseTrait; use SimpleXMLElement; @@ -48,4 +49,39 @@ public function testEtAlWithCombined() //$this->_testRenderTestSuite("name_EtAlWithCombined"); } */ + + /** + * @throws Exception + */ + public function testRenderLabelBeforeNameShouldBeTrueIfLabelTagBeforeName() + { + $csl = << +