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..28696022 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" } ], @@ -23,7 +23,7 @@ }, "autoload-dev": { "psr-4": { - "Seboettg\\CiteProc\\": "tests/src/" + "Seboettg\\CiteProc\\Test\\": "tests/src/" } }, "require": { @@ -32,7 +32,8 @@ "ext-simplexml": "*", "ext-json": "*", "php": ">=7.3", - "ext-mbstring": "*" + "ext-mbstring": "*", + "ext-intl": "*" }, "require-dev": { "php-coveralls/php-coveralls": "^1", @@ -41,18 +42,17 @@ "phpmd/phpmd": "^2.8" }, "suggest": { - "ext-intl": "*", - "symfony/polyfill-mbstring": "^1.10" + "symfony/polyfill-mbstring": "^1.10" }, "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/Constraint/AbstractConstraint.php b/src/Constraint/AbstractConstraint.php index a3fa3aba..e1246011 100644 --- a/src/Constraint/AbstractConstraint.php +++ b/src/Constraint/AbstractConstraint.php @@ -1,19 +1,16 @@ - - * created at 26.10.19, 14:12 + * @link http://github.com/seboettg/citeproc-php for the source repository + * @copyright Copyright (c) 2019 Sebastian Böttger. + * @license https://opensource.org/licenses/MIT */ namespace Seboettg\CiteProc\Constraint; +use Seboettg\Collection\ArrayList; use stdClass; -/** - * Class AbstractConstraint - * @package Seboettg\CiteProc\Constraint - * @noinspection PhpUnused - */ abstract class AbstractConstraint implements Constraint { @@ -23,7 +20,7 @@ abstract class AbstractConstraint implements Constraint protected $match; /** - * @var array + * @var ArrayList\ArrayListInterface */ protected $conditionVariables; @@ -32,53 +29,70 @@ abstract class AbstractConstraint implements Constraint * @param stdClass $data; * @return bool */ - abstract protected function matchForVariable($variable, $data); + abstract protected function matchForVariable(string $variable, stdClass $data): bool; /** * Variable constructor. - * @param string $value + * @param string $variableValues * @param string $match */ - /** @noinspection PhpUnused */ - public function __construct($value, $match = "any") + public function __construct(string $variableValues, string $match = "any") { - $this->conditionVariables = explode(" ", $value); + $this->conditionVariables = new ArrayList(...explode(" ", $variableValues)); $this->match = $match; } /** - * @param $value + * @param stdClass $data * @param int|null $citationNumber * @return bool */ - public function validate($value, $citationNumber = null) + public function validate(stdClass $data, int $citationNumber = null): bool { switch ($this->match) { case Constraint::MATCH_ALL: - return $this->matchAll($value); + return $this->matchAll($data); case Constraint::MATCH_NONE: - return !$this->matchAny($value); //no match for any value + return $this->matchNone($data); //no match for any value case Constraint::MATCH_ANY: default: - return $this->matchAny($value); + return $this->matchAny($data); } } - private function matchAny($value) + private function matchAny(stdClass $data): bool { - $conditionMatched = false; - foreach ($this->conditionVariables as $variable) { - $conditionMatched |= $this->matchForVariable($variable, $value); - } - return (bool)$conditionMatched; + return $this->conditionVariables + ->map(function (string $conditionVariable) use ($data) { + return $this->matchForVariable($conditionVariable, $data); + }) + ->filter(function (bool $match) { + return $match === true; + }) + ->count() > 0; } - private function matchAll($value) + private function matchAll(stdClass $data): bool { - $conditionMatched = true; - foreach ($this->conditionVariables as $variable) { - $conditionMatched &= $this->matchForVariable($variable, $value); - } - return (bool)$conditionMatched; + return $this->conditionVariables + ->map(function (string $conditionVariable) use ($data) { + return $this->matchForVariable($conditionVariable, $data); + }) + ->filter(function (bool $match) { + return $match === true; + }) + ->count() === $this->conditionVariables->count(); + } + + private function matchNone(stdClass $data): bool + { + return $this->conditionVariables + ->map(function (string $conditionVariable) use ($data) { + return $this->matchForVariable($conditionVariable, $data); + }) + ->filter(function (bool $match) { + return $match === false; + }) + ->count() === $this->conditionVariables->count(); } } diff --git a/src/Constraint/Constraint.php b/src/Constraint/Constraint.php index 09ad72e3..bc9f3b02 100644 --- a/src/Constraint/Constraint.php +++ b/src/Constraint/Constraint.php @@ -1,4 +1,5 @@ - * */ -/** @noinspection PhpUnused */ class Disambiguate implements Constraint { /** - * @codeCoverageIgnore - * @param $value + * @param stdClass $data * @param int|null $citationNumber * @return bool */ - public function validate($value, $citationNumber = null) + public function validate(stdClass $data, $citationNumber = null): bool { return false; } diff --git a/src/Constraint/Factory.php b/src/Constraint/Factory.php index 58464181..b982f225 100644 --- a/src/Constraint/Factory.php +++ b/src/Constraint/Factory.php @@ -1,4 +1,5 @@ - */ class Factory extends \Seboettg\CiteProc\Util\Factory { const NAMESPACE_CONSTRAINTS = "Seboettg\\CiteProc\\Constraint\\"; /** - * @param string $name - * @param string $value - * @param string $match - * @return mixed * @throws ClassNotFoundException */ - public static function createConstraint(string $name, string $value, string $match) + public static function createConstraint(string $name, string $value, string $match): Constraint { $parts = explode("-", $name); $className = implode("", array_map(function ($part) { diff --git a/src/Constraint/IsNumeric.php b/src/Constraint/IsNumeric.php index 7d8cbd66..965f2c44 100644 --- a/src/Constraint/IsNumeric.php +++ b/src/Constraint/IsNumeric.php @@ -1,4 +1,5 @@ {$variable})) { return $this->parseValue($data->{$variable}); @@ -46,7 +47,7 @@ protected function matchForVariable($variable, $data) * @param $evalValue * @return bool */ - private function parseValue($evalValue) + private function parseValue($evalValue): bool { if (is_numeric($evalValue)) { return true; diff --git a/src/Constraint/IsUncertainDate.php b/src/Constraint/IsUncertainDate.php index b6698425..b40060f4 100644 --- a/src/Constraint/IsUncertainDate.php +++ b/src/Constraint/IsUncertainDate.php @@ -1,4 +1,5 @@ {$variable})) { if (isset($data->{$variable}->{'circa'})) { diff --git a/src/Constraint/Jurisdiction.php b/src/Constraint/Jurisdiction.php index 9368bd38..25b00dbe 100644 --- a/src/Constraint/Jurisdiction.php +++ b/src/Constraint/Jurisdiction.php @@ -1,4 +1,5 @@ */ -/** @noinspection PhpUnused */ class Jurisdiction implements Constraint { /** * @codeCoverageIgnore - * @param $value + * @param stdClass $data * @param int|null $citationNumber * @return bool */ - public function validate($value, $citationNumber = null) + public function validate(stdClass $data, int $citationNumber = null): bool { return false; } diff --git a/src/Constraint/Locator.php b/src/Constraint/Locator.php index 08325ad0..2ae8e665 100644 --- a/src/Constraint/Locator.php +++ b/src/Constraint/Locator.php @@ -1,4 +1,5 @@ */ -/** @noinspection PhpUnused */ class Locator extends AbstractConstraint { /** * @inheritDoc */ - protected function matchForVariable($variable, $data) + protected function matchForVariable(string $variable, stdClass $data): bool { if (!empty($data->id)) { $citationItem = CiteProc::getContext()->getCitationItemById($data->id); diff --git a/src/Constraint/Position.php b/src/Constraint/Position.php index 69a9a8b6..79e622eb 100644 --- a/src/Constraint/Position.php +++ b/src/Constraint/Position.php @@ -1,4 +1,5 @@ */ class Position implements Constraint { @@ -51,42 +49,42 @@ class Position implements Constraint const SUBSEQUENT = "subsequent"; const NEAR_NOTE = "near-note"; - private $value; + private $position; private $match; - public function __construct($value, $match = "all") + public function __construct(string $position, string $match = "all") { - $this->value = $value; + $this->position = $position; $this->match = $match; } /** * @codeCoverageIgnore - * @param stdClass $object + * @param stdClass $data * @param int|null $citationNumber * @return bool */ - public function validate($object, $citationNumber = null) + public function validate(stdClass $data, $citationNumber = null): bool { if (CiteProc::getContext()->isModeBibliography()) { return false; } - switch ($this->value) { + switch ($this->position) { case self::FIRST: - return $this->getPosition($object) === null; + return $this->getPosition($data) === null; case self::IBID: case self::IBID_WITH_LOCATOR: case self::SUBSEQUENT: - return $this->isOnLastPosition($object); + return $this->isOnLastPosition($data); } return true; } - private function getPosition($object) + private function getPosition(stdClass $data): ?string { foreach (CiteProc::getContext()->getCitedItems() as $key => $value) { - if (!empty($value->{'id'}) && $value->{'id'} === $object->{'id'}) { + if (!empty($value->{'id'}) && $value->{'id'} === $data->{'id'}) { return $key; } } @@ -94,12 +92,12 @@ private function getPosition($object) } /** - * @param stdClass $object + * @param stdClass $data * @return bool */ - private function isOnLastPosition($object): bool + private function isOnLastPosition(stdClass $data): bool { $lastCitedItem = CiteProc::getContext()->getCitedItems()->last(); - return !empty($lastCitedItem) ? $lastCitedItem->{'id'} === $object->{'id'} : false; + return !empty($lastCitedItem) && $lastCitedItem->{'id'} === $data->{'id'}; } } diff --git a/src/Constraint/Type.php b/src/Constraint/Type.php index d3c76883..1cd1b42e 100644 --- a/src/Constraint/Type.php +++ b/src/Constraint/Type.php @@ -1,4 +1,5 @@ - */ -/** @noinspection PhpUnused */ class Type extends AbstractConstraint { @@ -26,8 +20,8 @@ class Type extends AbstractConstraint * @param stdClass $data ; * @return bool */ - protected function matchForVariable($variable, $data) + protected function matchForVariable(string $variable, stdClass $data): bool { - return in_array($data->type, $this->conditionVariables); + return in_array($data->type, $this->conditionVariables->toArray()); } } diff --git a/src/Constraint/Variable.php b/src/Constraint/Variable.php index a310e5d6..7e5af880 100644 --- a/src/Constraint/Variable.php +++ b/src/Constraint/Variable.php @@ -1,4 +1,5 @@ - */ -/** @noinspection PhpUnused */ class Variable extends AbstractConstraint { /** @@ -26,15 +20,15 @@ class Variable extends AbstractConstraint * @param stdClass $data * @return bool */ - protected function matchForVariable($variable, $data) + protected function matchForVariable(string $variable, stdClass $data): bool { - $variableExistInCitationItem = false; + $variableExistsInCitationItem = false; if (CiteProc::getContext()->isModeCitation() && isset($data->id)) { $citationItem = CiteProc::getContext()->getCitationItemById($data->id); if (!empty($citationItem)) { - $variableExistInCitationItem = !empty($citationItem->{$variable}); + $variableExistsInCitationItem = !empty($citationItem->{$variable}); } } - return !empty($data->{$variable}) || $variableExistInCitationItem; + return !empty($data->{$variable}) || $variableExistsInCitationItem; } } diff --git a/src/Rendering/Choose/Choose.php b/src/Rendering/Choose/Choose.php index b87ee4f2..18c1506f 100644 --- a/src/Rendering/Choose/Choose.php +++ b/src/Rendering/Choose/Choose.php @@ -46,57 +46,65 @@ public function __construct(SimpleXMLElement $node, $parent) { $this->parent = $parent; $this->children = new ArrayList(); - $elseIf = []; + $elseIf = new ArrayList(); foreach ($node->children() as $child) { switch ($child->getName()) { case 'if': $this->children->add("if", new ChooseIf($child, $this)); break; case 'else-if': - $elseIf[] = new ChooseElseIf($child, $this); + $elseIf->append(new ChooseElseIf($child, $this)); break; case 'else': $this->children->add("else", new ChooseElse($child, $this)); break; } } - if (!empty($elseIf)) { + if ($elseIf->count() > 0) { $this->children->add("elseif", $elseIf); } } /** - * @param array|DataList $data - * @param null|int $citationNumber + * @param array|DataList $data + * @param null|int $citationNumber * @return string + * @throws ArrayList\NotConvertibleToStringException */ public function render($data, $citationNumber = null) { - $arr = []; + $result = new ArrayList(); + $matchedIfs = false; - // IF - if ($prevCondition = $this->children->get("if")->match($data)) { - $arr[] = $this->children->get("if")->render($data); - } elseif (!$prevCondition && $this->children->hasKey("elseif")) { // ELSEIF - /** - * @var ChooseElseIf $child - */ - foreach ($this->children->get("elseif") as $child) { - $condition = $child->match($data); - if ($condition && !$prevCondition) { - $arr[] = $child->render($data); - $prevCondition = true; - break; //break loop as soon as condition matches - } - $prevCondition = $condition; + $ifCondition = $this->children->get("if"); + + if ($ifCondition->match($data)) { //IF CONDITION + $matchedIfs = true; + $result->append($ifCondition->render($data)); + } elseif ($this->children->hasKey("elseif")) { // ELSEIF + $elseIfs = $this->children->get("elseif") + ->map(function (ChooseIf $elseIf) use ($data) { + return new Tuple($elseIf, $elseIf->match($data)); + }) + ->filter(function (Tuple $elseIfToMatch) { + return $elseIfToMatch->second === true; + }); + $matchedIfs = $elseIfs->count() > 0; + if ($matchedIfs) { + $result->append( + $elseIfs + ->first() //returns a Tuple + ->first + ->render($data) + ); } } - //ELSE - if (!$prevCondition && $this->children->hasKey("else")) { - $arr[] = $this->children->get("else")->render($data); + // !$matchedIfs ensures that each previous condition has not been met + if (!$matchedIfs && $this->children->hasKey("else")) { //ELSE + $result->append($this->children->get("else")->render($data)); } - return implode("", $arr); + return $result->collectToString(""); } /** diff --git a/src/Rendering/Choose/ChooseElse.php b/src/Rendering/Choose/ChooseElse.php index 3245c0ce..08c39aaa 100644 --- a/src/Rendering/Choose/ChooseElse.php +++ b/src/Rendering/Choose/ChooseElse.php @@ -1,4 +1,5 @@ - */ class ChooseElse extends ChooseIf { //render function is inherited from ChooseIf diff --git a/src/Rendering/Choose/ChooseElseIf.php b/src/Rendering/Choose/ChooseElseIf.php index 383ce2f3..10f2d668 100644 --- a/src/Rendering/Choose/ChooseElseIf.php +++ b/src/Rendering/Choose/ChooseElseIf.php @@ -1,5 +1,6 @@ - */ class ChooseElseIf extends ChooseElse { diff --git a/src/Rendering/Choose/ChooseIf.php b/src/Rendering/Choose/ChooseIf.php index a956fe89..ecaa78b2 100644 --- a/src/Rendering/Choose/ChooseIf.php +++ b/src/Rendering/Choose/ChooseIf.php @@ -1,4 +1,5 @@ - */ class ChooseIf implements Rendering, HasParent { /** - * @var ArrayList + * @var ArrayList|Constraint[] */ private $constraints; @@ -53,7 +48,7 @@ class ChooseIf implements Rendering, HasParent * @throws InvalidStylesheetException * @throws ClassNotFoundException */ - public function __construct(SimpleXMLElement $node, $parent) + public function __construct(SimpleXMLElement $node, Choose $parent) { $this->parent = $parent; $this->constraints = new ArrayList(); @@ -76,7 +71,7 @@ public function __construct(SimpleXMLElement $node, $parent) * @param null|int $citationNumber * @return string */ - public function render($data, $citationNumber = null) + public function render($data, $citationNumber = null): string { $ret = []; /** @var Rendering $child */ @@ -95,26 +90,40 @@ public function render($data, $citationNumber = null) * @param null|int $citationNumber * @return bool */ - public function match($data, $citationNumber = null) + public function match($data, int $citationNumber = null): bool { if ($this->constraints->count() === 1) { return $this->constraints->current()->validate($data); } - $result = true; - /** @var Constraint $constraint */ - foreach ($this->constraints as $constraint) { - if ($this->match === "any") { - if ($constraint->validate($data, $citationNumber)) { - return true; - } - } else { - $result &= $constraint->validate($data, $citationNumber); - } - } - if ($this->constraints->count() > 1 && $this->match === "all") { - return (bool) $result; - } elseif ($this->match === "none") { - return !((bool) $result); + + switch ($this->match) { + case Constraint::MATCH_ANY: + return $this->constraints + ->map(function (Constraint $constraint) use ($data) { + return $constraint->validate($data); + }) + ->filter(function (bool $match) { + return $match === true; + }) + ->count() > 0; + case Constraint::MATCH_ALL: + return $this->constraints + ->map(function (Constraint $constraint) use ($data) { + return $constraint->validate($data); + }) + ->filter(function (bool $match) { + return $match === true; + }) + ->count() === $this->constraints->count(); + case Constraint::MATCH_NONE: + return !$this->constraints + ->map(function (Constraint $constraint) use ($data) { + return $constraint->validate($data); + }) + ->filter(function (bool $match) { + return $match === false; + }) + ->count() === $this->constraints->count(); } return false; } @@ -124,7 +133,7 @@ public function match($data, $citationNumber = null) * @noinspection PhpUnused * @return Choose */ - public function getParent() + public function getParent(): Choose { return $this->parent; } diff --git a/src/Rendering/Choose/Tuple.php b/src/Rendering/Choose/Tuple.php new file mode 100644 index 00000000..8c811667 --- /dev/null +++ b/src/Rendering/Choose/Tuple.php @@ -0,0 +1,23 @@ +first = $first; + $this->second = $second; + } +} diff --git a/src/Rendering/Layout.php b/src/Rendering/Layout.php index 3f2c2d25..06dcbbc5 100644 --- a/src/Rendering/Layout.php +++ b/src/Rendering/Layout.php @@ -128,7 +128,7 @@ private function renderSingle($data, $citationNumber = null) $margin = []; foreach ($this->children as $key => $child) { $rendered = $child->render($data, $citationNumber); - $this->getChildsAffixesAndDelimiter($child); + $this->getChildrenAffixesAndDelimiter($child); if (CiteProc::getContext()->isModeBibliography() && $bibliographyOptions->getSecondFieldAlign() === "flush" ) { diff --git a/src/Rendering/Name/Names.php b/src/Rendering/Name/Names.php index 71d2e6a8..d8d34fd6 100644 --- a/src/Rendering/Name/Names.php +++ b/src/Rendering/Name/Names.php @@ -15,6 +15,7 @@ use Seboettg\CiteProc\Rendering\HasParent; use Seboettg\CiteProc\Rendering\Label; use Seboettg\CiteProc\Rendering\Rendering; +use Seboettg\CiteProc\Rendering\Term\Punctuation; use Seboettg\CiteProc\RenderingState; use Seboettg\CiteProc\Style\InheritableNameAttributesTrait; use Seboettg\CiteProc\Styles\AffixesTrait; @@ -110,6 +111,11 @@ class Names implements Rendering, HasParent private $parent; + /** + * @var bool + */ + private $renderLabelBeforeName = false; + /** * Names constructor. * @@ -124,10 +130,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,15 +256,27 @@ 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"])) { - $name = $this->label->render($data).$name; + $renderedLabel = trim($this->label->render($data)); + if (empty($renderedLabel)) { + return $name; + } + if ($this->renderLabelBeforeName) { + $delimiter = !in_array( + trim($this->label->renderSuffix()), + Punctuation::getAllPunctuations() + ) ? " " : ""; + $result = $renderedLabel . $delimiter . trim($name); } else { - $name .= $this->label->render($data); + $delimiter = !in_array( + trim($this->label->renderPrefix()), + Punctuation::getAllPunctuations() + ) ? " " : ""; + $result = trim($name) . $delimiter . $renderedLabel; } - return $name; + return $result; } /** @@ -381,4 +403,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/src/Rendering/Number.php b/src/Rendering/Number.php index 38279b12..3a229812 100644 --- a/src/Rendering/Number.php +++ b/src/Rendering/Number.php @@ -27,11 +27,19 @@ class Number implements Rendering { - const RANGE_DELIMITER_HYPHEN = "-"; + private const RANGE_DELIMITER_HYPHEN = "-"; - const RANGE_DELIMITER_AMPERSAND = "&"; + private const RANGE_DELIMITER_AMPERSAND = "&"; - const RANGE_DELIMITER_COMMA = ","; + private const RANGE_DELIMITER_COMMA = ","; + + private const PATTERN_ORDINAL = "/\s*(\d+)\s*([\-\–&,])\s*(\d+)\s*/"; + + private const PATTERN_LONG_ORDINAL = "/\s*(\d+)\s*([\-\–&,])\s*(\d+)\s*/"; + + private const PATTERN_ROMAN = "/\s*(\d+)\s*([\-\–&,])\s*(\d+)\s*/"; + + private const PATTERN_NUMERIC_DEFAULT = "/\s*(\d+)\s*([\-\–&,])\s*(\d+)\s*/"; use FormattingTrait, AffixesTrait, @@ -76,7 +84,7 @@ public function __construct(SimpleXMLElement $node) * @param int|null $citationNumber * @return string */ - public function render($data, $citationNumber = null) + public function render($data, $citationNumber = null): string { $lang = (isset($data->language) && $data->language != 'en') ? $data->language : 'en'; @@ -87,7 +95,7 @@ public function render($data, $citationNumber = null) $decimalNumber = $this->toDecimalNumber($number); switch ($this->form) { case 'ordinal': - if (preg_match("/\s*(\d+)\s*([\-\–&,])\s*(\d+)\s*/", $decimalNumber, $matches)) { + if (preg_match(self::PATTERN_ORDINAL, $decimalNumber, $matches)) { $num1 = self::ordinal($matches[1]); $num2 = self::ordinal($matches[3]); $text = $this->buildNumberRangeString($num1, $num2, $matches[2]); @@ -96,7 +104,7 @@ public function render($data, $citationNumber = null) } break; case 'long-ordinal': - if (preg_match("/\s*(\d+)\s*([\-\–&,])\s*(\d+)\s*/", $decimalNumber, $matches)) { + if (preg_match(self::PATTERN_LONG_ORDINAL, $decimalNumber, $matches)) { if ($this->textCase === "capitalize-first" || $this->textCase === "sentence") { $num1 = self::longOrdinal($matches[1]); $num2 = self::longOrdinal($matches[3]); @@ -110,7 +118,7 @@ public function render($data, $citationNumber = null) } break; case 'roman': - if (preg_match("/\s*(\d+)\s*([\-\–&,])\s*(\d+)\s*/", $decimalNumber, $matches)) { + if (preg_match(self::PATTERN_ROMAN, $decimalNumber, $matches)) { $num1 = Util\NumberHelper::dec2roman($matches[1]); $num2 = Util\NumberHelper::dec2roman($matches[3]); $text = $this->buildNumberRangeString($num1, $num2, $matches[2]); @@ -127,7 +135,7 @@ public function render($data, $citationNumber = null) ampersand (“2&3” becomes “2 & 3”). */ $decimalNumber = $data->{$this->variable}; - if (preg_match("/\s*(\d+)\s*([\-\–&,])\s*(\d+)\s*/", $decimalNumber, $matches)) { + if (preg_match(self::PATTERN_NUMERIC_DEFAULT, $decimalNumber, $matches)) { $text = $this->buildNumberRangeString($matches[1], $matches[3], $matches[2]); } else { $text = $decimalNumber; @@ -141,7 +149,7 @@ public function render($data, $citationNumber = null) * @param $num * @return string */ - public static function ordinal($num) + public static function ordinal($num): string { if (($num / 10) % 10 == 1) { $ordinalSuffix = CiteProc::getContext()->getLocale()->filter('terms', 'ordinal')->single; @@ -157,7 +165,7 @@ public static function ordinal($num) if (empty($ordinalSuffix)) { $ordinalSuffix = CiteProc::getContext()->getLocale()->filter('terms', 'ordinal')->single; } - return $num.$ordinalSuffix; + return $num . $ordinalSuffix; } /** diff --git a/src/Rendering/Term/Punctuation.php b/src/Rendering/Term/Punctuation.php new file mode 100644 index 00000000..d8110cca --- /dev/null +++ b/src/Rendering/Term/Punctuation.php @@ -0,0 +1,32 @@ +setArray(Punctuation::toArray()) + ->map(function (string $punctuation) { + return CiteProc::getContext()->getLocale()->filter("terms", $punctuation)->single; + }) + ->collect(function ($items) { + return array_values($items); + }); + } +} diff --git a/src/Rendering/Text.php b/src/Rendering/Text.php index 205bbcc6..37bdc99e 100644 --- a/src/Rendering/Text.php +++ b/src/Rendering/Text.php @@ -113,8 +113,8 @@ public function render($data, $citationNumber = null) unset($data->{$this->toRenderTypeValue}); } if (!CiteProcHelper::isUsingAffixesByMarkupExtentsion($data, $this->toRenderTypeValue)) { - $renderedText = $this->applyAdditionalMarkupFunction($data, $renderedText); - } + $renderedText = $this->applyAdditionalMarkupFunction($data, $renderedText); + } break; case 'macro': $renderedText = $this->renderMacro($data); @@ -241,17 +241,17 @@ private function renderVariable($data, $lang) } /** - * @param $data - * @param $renderedText + * @param $data + * @param $renderedText * @return string */ private function formatRenderedText($data, $renderedText) { $text = $this->format($renderedText); $res = $this->addAffixes($text); - if (CiteProcHelper::isUsingAffixesByMarkupExtentsion($data, $this->toRenderTypeValue)) { - $res = $this->applyAdditionalMarkupFunction($data, $res); - } + if (CiteProcHelper::isUsingAffixesByMarkupExtentsion($data, $this->toRenderTypeValue)) { + $res = $this->applyAdditionalMarkupFunction($data, $res); + } if (!empty($res)) { $res = $this->removeConsecutiveChars($res); } @@ -267,9 +267,9 @@ private function formatRenderedText($data, $renderedText) private function renderCitationNumber($data, $citationNumber) { $renderedText = $citationNumber + 1; - if (!CiteProcHelper::isUsingAffixesByMarkupExtentsion($data, $this->toRenderTypeValue)) { - $renderedText = $this->applyAdditionalMarkupFunction($data, $renderedText); - } + if (!CiteProcHelper::isUsingAffixesByMarkupExtentsion($data, $this->toRenderTypeValue)) { + $renderedText = $this->applyAdditionalMarkupFunction($data, $renderedText); + } return $renderedText; } diff --git a/src/Style/Macro.php b/src/Style/Macro.php index b7f53cd3..52e9646b 100644 --- a/src/Style/Macro.php +++ b/src/Style/Macro.php @@ -84,7 +84,7 @@ public function render($data, $citationNumber = null) /** @var Rendering $child */ foreach ($this->children as $child) { $res = $child->render($data, $citationNumber); - $this->getChildsAffixesAndDelimiter($child); + $this->getChildrenAffixesAndDelimiter($child); if (!empty($res)) { $ret[] = $res; } diff --git a/src/Style/Options/GlobalOptions.php b/src/Style/Options/GlobalOptions.php index b85f0bdb..dd0954fe 100644 --- a/src/Style/Options/GlobalOptions.php +++ b/src/Style/Options/GlobalOptions.php @@ -43,7 +43,7 @@ public function __construct(SimpleXMLElement $node) foreach ($node->attributes() as $attribute) { switch ($attribute->getName()) { case 'initialize-with-hyphen': - $this->initializeWithHyphen = "false" === (string) $attribute ? false : true; + $this->initializeWithHyphen = !("false" === (string) $attribute); break; case 'page-range-format': $this->pageRangeFormat = new PageRangeFormats((string) $attribute); @@ -59,7 +59,7 @@ public function __construct(SimpleXMLElement $node) * “true”, default) or without (“J.L.”, value “false”). * @return bool */ - public function isInitializeWithHyphen() + public function isInitializeWithHyphen(): bool { return $this->initializeWithHyphen; } @@ -71,7 +71,7 @@ public function isInitializeWithHyphen() * not set, page ranges are rendered without reformatting. * @return PageRangeFormats */ - public function getPageRangeFormat() + public function getPageRangeFormat(): ?PageRangeFormats { return $this->pageRangeFormat; } @@ -80,7 +80,7 @@ public function getPageRangeFormat() * Sets the display and sorting behavior of the non-dropping-particle in inverted names (e.g. “Koning, W. de”). * @return DemoteNonDroppingParticle */ - public function getDemoteNonDroppingParticles() + public function getDemoteNonDroppingParticles(): ?DemoteNonDroppingParticle { return $this->demoteNonDroppingParticles; } 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; } diff --git a/src/Styles/ConsecutivePunctuationCharacterTrait.php b/src/Styles/ConsecutivePunctuationCharacterTrait.php index deec6714..e542bf90 100644 --- a/src/Styles/ConsecutivePunctuationCharacterTrait.php +++ b/src/Styles/ConsecutivePunctuationCharacterTrait.php @@ -37,7 +37,7 @@ trait ConsecutivePunctuationCharacterTrait * @param $subject * @return string */ - public function removeConsecutivePunctuation($punctuationSign, $subject) + public function removeConsecutivePunctuation($punctuationSign, $subject): string { if (empty($punctuationSign) || preg_match("/^\s+$/", $punctuationSign)) { return $subject; @@ -52,7 +52,7 @@ public function removeConsecutivePunctuation($punctuationSign, $subject) /** * @param $child */ - protected function getChildsAffixesAndDelimiter($child) + protected function getChildrenAffixesAndDelimiter($child) { if (method_exists($child, "renderPrefix")) { if (!empty($child->renderPrefix()) && !in_array($child->renderPrefix(), $this->childrenPrefixes)) { diff --git a/src/Util/CiteProcHelper.php b/src/Util/CiteProcHelper.php index f2c8e536..b7f2034f 100644 --- a/src/Util/CiteProcHelper.php +++ b/src/Util/CiteProcHelper.php @@ -27,21 +27,21 @@ public static function applyAdditionMarkupFunction($dataItem, $valueToRender, $r { $markupExtension = CiteProc::getContext()->getMarkupExtension(); if (array_key_exists($valueToRender, $markupExtension)) { - if (is_array($markupExtension[$valueToRender]) && array_key_exists('function', $markupExtension[$valueToRender])) { - $function = $markupExtension[$valueToRender]['function']; - } else { - $function = $markupExtension[$valueToRender]; - } + if (is_array($markupExtension[$valueToRender]) && array_key_exists('function', $markupExtension[$valueToRender])) { + $function = $markupExtension[$valueToRender]['function']; + } else { + $function = $markupExtension[$valueToRender]; + } if (is_callable($function)) { $renderedText = $function($dataItem, $renderedText); } } elseif (array_key_exists($mode = CiteProc::getContext()->getMode(), $markupExtension)) { if (array_key_exists($valueToRender, $markupExtension[$mode])) { - if (is_array($markupExtension[$mode][$valueToRender]) && array_key_exists('function', $markupExtension[$mode][$valueToRender])) { - $function = CiteProc::getContext()->getMarkupExtension()[$mode][$valueToRender]['function']; - } else { - $function = CiteProc::getContext()->getMarkupExtension()[$mode][$valueToRender]; - } + if (is_array($markupExtension[$mode][$valueToRender]) && array_key_exists('function', $markupExtension[$mode][$valueToRender])) { + $function = CiteProc::getContext()->getMarkupExtension()[$mode][$valueToRender]['function']; + } else { + $function = CiteProc::getContext()->getMarkupExtension()[$mode][$valueToRender]; + } if (is_callable($function)) { $renderedText = $function($dataItem, $renderedText); } @@ -63,26 +63,26 @@ public static function cloneArray(array $array) return $newArray; } - /** - * @param stdClass $dataItem the actual item - * @param string $valueToRender value the has to apply on - * @return bool - */ + /** + * @param stdClass $dataItem the actual item + * @param string $valueToRender value the has to apply on + * @return bool + */ public static function isUsingAffixesByMarkupExtentsion($dataItem, $valueToRender) - { - $markupExtension = CiteProc::getContext()->getMarkupExtension(); - if (array_key_exists($valueToRender, $markupExtension)) { - if (is_array($markupExtension[$valueToRender]) && array_key_exists('affixes', $markupExtension[$valueToRender])) { - return $markupExtension[$valueToRender]['affixes']; - } - } elseif (array_key_exists($mode = CiteProc::getContext()->getMode(), $markupExtension)) { - if (array_key_exists($valueToRender, $markupExtension[$mode])) { - if (is_array($markupExtension[$mode][$valueToRender]) && array_key_exists('affixes', $markupExtension[$mode][$valueToRender])) { - return CiteProc::getContext()->getMarkupExtension()[$mode][$valueToRender]['affixes']; - } - } - } + { + $markupExtension = CiteProc::getContext()->getMarkupExtension(); + if (array_key_exists($valueToRender, $markupExtension)) { + if (is_array($markupExtension[$valueToRender]) && array_key_exists('affixes', $markupExtension[$valueToRender])) { + return $markupExtension[$valueToRender]['affixes']; + } + } elseif (array_key_exists($mode = CiteProc::getContext()->getMode(), $markupExtension)) { + if (array_key_exists($valueToRender, $markupExtension[$mode])) { + if (is_array($markupExtension[$mode][$valueToRender]) && array_key_exists('affixes', $markupExtension[$mode][$valueToRender])) { + return CiteProc::getContext()->getMarkupExtension()[$mode][$valueToRender]['affixes']; + } + } + } - return FALSE; - } + return false; + } } diff --git a/src/Util/NumberHelper.php b/src/Util/NumberHelper.php index a2ff3d6f..e791e8fb 100644 --- a/src/Util/NumberHelper.php +++ b/src/Util/NumberHelper.php @@ -20,7 +20,7 @@ class NumberHelper { - const PATTERN_ORDINAL = "/\d+(st|nd|rd|th)?\.?$/"; + const PATTERN_ORDINAL = "/\d+((st|nd|rd|th)\.?|\.)$/"; const PATTERN_ROMAN = "/^[ivxlcdm]+\.?$/i"; @@ -28,7 +28,7 @@ class NumberHelper const PATTERN_AFFIXES = "/^[a-z]?\d+[a-z]?$/i"; - const PATTERN_COMMA_AMPERSAND_RANGE = "/\d*([\s?\-&+,;\s])+\d+/"; + const PATTERN_COMMA_AMPERSAND_RANGE = "/\d+([\s?\-&+,;\s])+\d+/"; const ROMAN_NUMERALS = [ ["", "i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix"], diff --git a/src/functions.php b/src/functions.php index 9be4d45c..905116e5 100644 --- a/src/functions.php +++ b/src/functions.php @@ -1,4 +1,5 @@ >===== MODE =====>> +bibliography +<<===== MODE =====<< + +>>===== RESULT =====>> +
+
Abramson, Daniel. “Bank of England”. In John Soane Architect: Master of Space and Light, edited by Margaret Richardson and Mary Anne Stevens, 208-51. London: Royal Academy of Arts, 1999.
+
+<<===== RESULT =====<< + +>>===== CSL =====>> + + +<<===== CSL =====<< + +>>===== INPUT =====>> +[ + { + "author": [ + { + "family": "Abramson", + "given": "Daniel" + } + ], + "citation-label": "abramson_bank_1999", + "container-title": "John Soane Architect: Master of Space and Light", + "editor": [ + { + "family": "Richardson", + "given": "Margaret" + }, + { + "family": "Stevens", + "given": "Mary Anne" + } + ], + "id": "abramson_bank_1999", + "issued": { + "date-parts": [ + [ + 1999 + ] + ] + }, + "page": "208-251", + "publisher": "Royal Academy of Arts", + "publisher-place": "London", + "title": "Bank of England", + "type": "chapter" + } +] +<<===== INPUT =====<< diff --git a/tests/fixtures/basic-tests/processor-tests/humans/bugfix-github-117.txt b/tests/fixtures/basic-tests/processor-tests/humans/bugfix-github-117.txt new file mode 100644 index 00000000..64e57a17 --- /dev/null +++ b/tests/fixtures/basic-tests/processor-tests/humans/bugfix-github-117.txt @@ -0,0 +1,1281 @@ +>>===== MODE =====>> +bibliography +<<===== MODE =====<< + +>>===== RESULT =====>> +
+
Barbier, Frédéric. “L’industrialisation Des Techniques”. In Histoire De l’édition française: Le Temps Des éditeurs; Du Romantisme à La Belle Époque, Roger Chartier and Henri-Jean Martin, 51-66, 1st ed. 1985. Paris: Fayard/Cercle de la Librairie, 1990.
+
+<<===== RESULT =====<< + +>>===== CSL =====>> + + +<<===== CSL =====<< + +>>===== INPUT =====>> +[ + { + "author": [ + { + "family": "Barbier", + "given": "Frédéric" + } + ], + "citation-label": "barbier_lindustrialisation_1990", + "container-author": [ + { + "family": "Chartier", + "given": "Roger" + }, + { + "family": "Martin", + "given": "Henri-Jean" + } + ], + "container-title": "Histoire de l’édition française: Le temps des éditeurs; Du romantisme à la Belle Époque", + "edition": "1st ed. 1985", + "id": "barbier_lindustrialisation_1990", + "issued": { + "date-parts": [ + [ + 1990 + ] + ] + }, + "page": "51-66", + "publisher": "Fayard/Cercle de la Librairie", + "publisher-place": "Paris", + "title": "L’industrialisation des techniques", + "type": "chapter", + "volume": "3" + } +] +<<===== INPUT =====<< diff --git a/tests/src/BugfixTest.php b/tests/src/BugfixTest.php index 816aac93..95eb5457 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() { @@ -150,4 +148,14 @@ public function testBugfixGithub106() { $this->runTestSuite('bugfix-github-106'); } + + public function testBugfixGithub116() + { + $this->runTestSuite('bugfix-github-116'); + } + + public function testBugfixGithub117() + { + $this->runTestSuite('bugfix-github-117'); + } } 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/ChooseIfTest.php b/tests/src/Rendering/Choose/ChooseIfTest.php new file mode 100644 index 00000000..d18779c3 --- /dev/null +++ b/tests/src/Rendering/Choose/ChooseIfTest.php @@ -0,0 +1,73 @@ + + + + + + + + + EOT; + + $dataString = <<mockContext(); + $expectedResult = "false"; // since match="none" + $choose = new Choose(new SimpleXMLElement($csl), null); + $this->assertEquals($expectedResult, $choose->render(json_decode($dataString))); + } + + private function mockContext(): void + { + $mockedContext = $this->createMock(Context::class); + $mockedContext + ->method('isModeBibliography') + ->willReturn(true); + $mockedContext + ->method('isModeCitation') + ->willReturn(false); + $mockedContext + ->method('getMode') + ->willReturn('bibliography'); + $mockedContext + ->method('getMarkupExtension') + ->willReturn([]); + + CiteProc::setContext($mockedContext); + } +} 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..835e4342 100644 --- a/tests/src/Rendering/Name/NamesTest.php +++ b/tests/src/Rendering/Name/NamesTest.php @@ -7,10 +7,21 @@ * @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\Exception\CiteProcException; +use Seboettg\CiteProc\Exception\InvalidStylesheetException; +use Seboettg\CiteProc\Locale\Locale; +use Seboettg\CiteProc\Rendering\Name\Names; +use Seboettg\CiteProc\Style\Options\DemoteNonDroppingParticle; +use Seboettg\CiteProc\Style\Options\GlobalOptions; +use Seboettg\CiteProc\Style\Options\PageRangeFormats; +use Seboettg\CiteProc\Test\TestSuiteTestCaseTrait; +use SimpleXMLElement; class NamesTest extends TestCase { @@ -43,4 +54,145 @@ public function testEtAlWithCombined() //$this->_testRenderTestSuite("name_EtAlWithCombined"); } */ + + /** + * @throws Exception + */ + public function testRenderLabelBeforeNameShouldBeTrueIfLabelTagBeforeName() + { + $csl = << +