@@ -15,51 +15,51 @@ |
||
| 15 | 15 | |
| 16 | 16 | class ChevronOuvrantTest extends TestCase |
| 17 | 17 | { |
| 18 | - public static function setUpBeforeClass(): void { |
|
| 19 | - find_in_path('inc/texte.php', '', true); |
|
| 20 | - } |
|
| 18 | + public static function setUpBeforeClass(): void { |
|
| 19 | + find_in_path('inc/texte.php', '', true); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - protected function setUp(): void { |
|
| 23 | - $GLOBALS['meta']['type_urls'] = 'page'; |
|
| 24 | - $GLOBALS['type_urls'] = 'page'; |
|
| 25 | - // initialiser les plugins qui changent les intertitre (Z), et les restaurer juste apres |
|
| 26 | - $mem = [$GLOBALS['debut_intertitre'] ?? null, $GLOBALS['spip_raccourcis_typo'] ?? null]; |
|
| 27 | - propre('rien du tout'); |
|
| 28 | - [$GLOBALS['debut_intertitre'], $GLOBALS['spip_raccourcis_typo']] = $mem; |
|
| 29 | - } |
|
| 22 | + protected function setUp(): void { |
|
| 23 | + $GLOBALS['meta']['type_urls'] = 'page'; |
|
| 24 | + $GLOBALS['type_urls'] = 'page'; |
|
| 25 | + // initialiser les plugins qui changent les intertitre (Z), et les restaurer juste apres |
|
| 26 | + $mem = [$GLOBALS['debut_intertitre'] ?? null, $GLOBALS['spip_raccourcis_typo'] ?? null]; |
|
| 27 | + propre('rien du tout'); |
|
| 28 | + [$GLOBALS['debut_intertitre'], $GLOBALS['spip_raccourcis_typo']] = $mem; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - #[DataProvider('providerPropreChevronOuvrant')] |
|
| 32 | - public function testPropreChevronOuvrant($expected, ...$args): void { |
|
| 33 | - $actual = propre(...$args); |
|
| 34 | - $this->assertSame($expected, $actual); |
|
| 35 | - } |
|
| 31 | + #[DataProvider('providerPropreChevronOuvrant')] |
|
| 32 | + public function testPropreChevronOuvrant($expected, ...$args): void { |
|
| 33 | + $actual = propre(...$args); |
|
| 34 | + $this->assertSame($expected, $actual); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - public static function providerPropreChevronOuvrant(): array { |
|
| 38 | - return [ |
|
| 39 | - 0 => [ |
|
| 40 | - 0 => '<p>a<b</p>', |
|
| 41 | - 1 => 'a<b', |
|
| 42 | - ], |
|
| 43 | - 1 => [ |
|
| 44 | - 0 => '<p><i>a<b</i></p>', |
|
| 45 | - 1 => '{a<b}', |
|
| 46 | - ], |
|
| 47 | - 2 => [ |
|
| 48 | - 0 => '<p><strong>a<b</strong></p>', |
|
| 49 | - 1 => '{{a<b}}', |
|
| 50 | - ], |
|
| 51 | - 3 => [ |
|
| 52 | - 0 => '<h2 class="spip">a<b</h2>', |
|
| 53 | - 1 => '{{{a<b}}}', |
|
| 54 | - ], |
|
| 55 | - 4 => [ |
|
| 56 | - 0 => '<p><i>0 < a < 1</i> et <i>a > 5</i></p>', |
|
| 57 | - 1 => '{0 < a < 1} et {a > 5}', |
|
| 58 | - ], |
|
| 59 | - 5 => [ |
|
| 60 | - 0 => '<p><i>0 < a < 1.0</i> et <i>a > 5</i></p>', |
|
| 61 | - 1 => '{0 < a < 1.0} et {a > 5}', |
|
| 62 | - ], |
|
| 63 | - ]; |
|
| 64 | - } |
|
| 37 | + public static function providerPropreChevronOuvrant(): array { |
|
| 38 | + return [ |
|
| 39 | + 0 => [ |
|
| 40 | + 0 => '<p>a<b</p>', |
|
| 41 | + 1 => 'a<b', |
|
| 42 | + ], |
|
| 43 | + 1 => [ |
|
| 44 | + 0 => '<p><i>a<b</i></p>', |
|
| 45 | + 1 => '{a<b}', |
|
| 46 | + ], |
|
| 47 | + 2 => [ |
|
| 48 | + 0 => '<p><strong>a<b</strong></p>', |
|
| 49 | + 1 => '{{a<b}}', |
|
| 50 | + ], |
|
| 51 | + 3 => [ |
|
| 52 | + 0 => '<h2 class="spip">a<b</h2>', |
|
| 53 | + 1 => '{{{a<b}}}', |
|
| 54 | + ], |
|
| 55 | + 4 => [ |
|
| 56 | + 0 => '<p><i>0 < a < 1</i> et <i>a > 5</i></p>', |
|
| 57 | + 1 => '{0 < a < 1} et {a > 5}', |
|
| 58 | + ], |
|
| 59 | + 5 => [ |
|
| 60 | + 0 => '<p><i>0 < a < 1.0</i> et <i>a > 5</i></p>', |
|
| 61 | + 1 => '{0 < a < 1.0} et {a > 5}', |
|
| 62 | + ], |
|
| 63 | + ]; |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -8,31 +8,31 @@ |
||
| 8 | 8 | |
| 9 | 9 | final class IsOk extends Constraint |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * Returns a string representation of the constraint. |
|
| 13 | - */ |
|
| 14 | - public function toString(): string { |
|
| 15 | - return 'is OK'; |
|
| 16 | - } |
|
| 11 | + /** |
|
| 12 | + * Returns a string representation of the constraint. |
|
| 13 | + */ |
|
| 14 | + public function toString(): string { |
|
| 15 | + return 'is OK'; |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Evaluates the constraint for parameter $other. Returns true if the constraint is met, false otherwise. |
|
| 20 | - * |
|
| 21 | - * @param mixed $other value or object to evaluate |
|
| 22 | - */ |
|
| 23 | - protected function matches($other): bool { |
|
| 24 | - return str_starts_with(strtolower(trim($other)), 'ok'); |
|
| 25 | - } |
|
| 18 | + /** |
|
| 19 | + * Evaluates the constraint for parameter $other. Returns true if the constraint is met, false otherwise. |
|
| 20 | + * |
|
| 21 | + * @param mixed $other value or object to evaluate |
|
| 22 | + */ |
|
| 23 | + protected function matches($other): bool { |
|
| 24 | + return str_starts_with(strtolower(trim($other)), 'ok'); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Returns the description of the failure. |
|
| 29 | - * |
|
| 30 | - * The beginning of failure messages is "Failed asserting that" in most cases. This method should return the second |
|
| 31 | - * part of that sentence. |
|
| 32 | - * |
|
| 33 | - * @param mixed $other evaluated value or object |
|
| 34 | - */ |
|
| 35 | - protected function failureDescription($other): string { |
|
| 36 | - return sprintf('"%s" is OK', $other); |
|
| 37 | - } |
|
| 27 | + /** |
|
| 28 | + * Returns the description of the failure. |
|
| 29 | + * |
|
| 30 | + * The beginning of failure messages is "Failed asserting that" in most cases. This method should return the second |
|
| 31 | + * part of that sentence. |
|
| 32 | + * |
|
| 33 | + * @param mixed $other evaluated value or object |
|
| 34 | + */ |
|
| 35 | + protected function failureDescription($other): string { |
|
| 36 | + return sprintf('"%s" is OK', $other); |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -8,30 +8,30 @@ |
||
| 8 | 8 | |
| 9 | 9 | class FileLoader implements LoaderInterface |
| 10 | 10 | { |
| 11 | - private readonly int $rootLen; |
|
| 11 | + private readonly int $rootLen; |
|
| 12 | 12 | |
| 13 | - public function __construct() { |
|
| 14 | - $this->rootLen = strlen(_SPIP_TEST_CHDIR) + 1; |
|
| 15 | - } |
|
| 13 | + public function __construct() { |
|
| 14 | + $this->rootLen = strlen(_SPIP_TEST_CHDIR) + 1; |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | - public function exists(string $name): bool { |
|
| 18 | - $filepath = realpath($name); |
|
| 19 | - return ($filepath !== false) && file_exists($filepath); |
|
| 20 | - } |
|
| 17 | + public function exists(string $name): bool { |
|
| 18 | + $filepath = realpath($name); |
|
| 19 | + return ($filepath !== false) && file_exists($filepath); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - public function getCacheKey(string $name): string { |
|
| 23 | - return $this->getSourceFile($name); |
|
| 24 | - } |
|
| 22 | + public function getCacheKey(string $name): string { |
|
| 23 | + return $this->getSourceFile($name); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function getSourceFile(string $name): string { |
|
| 27 | - $filepath = realpath($name); |
|
| 28 | - if (!$filepath || !file_exists($filepath)) { |
|
| 29 | - throw new TemplateNotFoundException($name); |
|
| 30 | - } |
|
| 26 | + public function getSourceFile(string $name): string { |
|
| 27 | + $filepath = realpath($name); |
|
| 28 | + if (!$filepath || !file_exists($filepath)) { |
|
| 29 | + throw new TemplateNotFoundException($name); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - $desc = pathinfo($name); |
|
| 33 | - $fond = $desc['dirname'] . '/' . $desc['filename']; |
|
| 32 | + $desc = pathinfo($name); |
|
| 33 | + $fond = $desc['dirname'] . '/' . $desc['filename']; |
|
| 34 | 34 | |
| 35 | - return substr($fond, $this->rootLen); |
|
| 36 | - } |
|
| 35 | + return substr($fond, $this->rootLen); |
|
| 36 | + } |
|
| 37 | 37 | } |
@@ -30,7 +30,7 @@ |
||
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | $desc = pathinfo($name); |
| 33 | - $fond = $desc['dirname'] . '/' . $desc['filename']; |
|
| 33 | + $fond = $desc['dirname'].'/'.$desc['filename']; |
|
| 34 | 34 | |
| 35 | 35 | return substr($fond, $this->rootLen); |
| 36 | 36 | } |
@@ -6,94 +6,94 @@ |
||
| 6 | 6 | |
| 7 | 7 | class StringLoader implements LoaderInterface |
| 8 | 8 | { |
| 9 | - private string $adresse_dernier_fichier_pour_code = ''; |
|
| 10 | - |
|
| 11 | - private string $cacheDirectory = ''; |
|
| 12 | - |
|
| 13 | - private array $options = []; |
|
| 14 | - |
|
| 15 | - public function __construct(array $options = []) { |
|
| 16 | - include_spip('inc/flock'); |
|
| 17 | - $this->cacheDirectory = sous_repertoire(_DIR_CACHE, 'Tests'); |
|
| 18 | - $this->setOptions($options); |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - public function exists(string $name): bool { |
|
| 22 | - return true; |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - public function getCacheKey(string $name): string { |
|
| 26 | - return md5($name . serialize($this->options)); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Écrit le code du squelette dans un fichier temporaire de cache |
|
| 31 | - */ |
|
| 32 | - public function getSourceFile(string $name): string { |
|
| 33 | - $fond = $this->cacheDirectory . $this->getCacheKey($name); |
|
| 34 | - $options = $this->options; |
|
| 35 | - $code = $name; |
|
| 36 | - |
|
| 37 | - if (isset($options['avant_code'])) { |
|
| 38 | - $code = $options['avant_code'] . $code; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - if (isset($options['apres_code'])) { |
|
| 42 | - $code .= $options['apres_code']; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - $this->ecrire_fichier($fond . '.html', $code); |
|
| 46 | - |
|
| 47 | - if (!empty($options['fonctions'])) { |
|
| 48 | - // un fichier unique pour ces fonctions |
|
| 49 | - $func = $this->cacheDirectory . 'func_' . md5($options['fonctions']) . '.php'; |
|
| 50 | - $this->ecrire_fichier($func, $this->php($options['fonctions'])); |
|
| 51 | - // une inclusion unique de ces fichiers |
|
| 52 | - $this->ecrire_fichier($fond . '_fonctions.php', $this->php(sprintf('include_once(\'%s\');', $func))); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - return $fond; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Définit des options de compilation du code, |
|
| 60 | - * |
|
| 61 | - * Notamment permet de déclarer des filtres (fonctions) pour le code à compiler |
|
| 62 | - * |
|
| 63 | - * Stocke des options : |
|
| 64 | - * - fonctions : pour ajouter un fichier de fonction au squelette cree (on passe le contenu du fichier) |
|
| 65 | - * - avant_code : pour inserer du contenu avant le code |
|
| 66 | - * - apres_code : pour inserer du contenu apres le code |
|
| 67 | - * |
|
| 68 | - * @param array $options : param->valeur des options |
|
| 69 | - */ |
|
| 70 | - private function setOptions(array $options = []): void { |
|
| 71 | - $this->options = $options; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Retourne "<?php $code ?>" |
|
| 76 | - * |
|
| 77 | - * @param string $code Code php |
|
| 78 | - * @return string Code php complet |
|
| 79 | - */ |
|
| 80 | - private function php(string $code): string { |
|
| 81 | - return '<' . "?php\n" . $code . "\n?" . '>'; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Ecrire un fichier à l'endroit indique |
|
| 86 | - * |
|
| 87 | - * Le réécrit systématiquement. |
|
| 88 | - * |
|
| 89 | - * @param string $filename Adresse du fichier a ecrire |
|
| 90 | - * @param string $content Contenu du fichier |
|
| 91 | - */ |
|
| 92 | - private function ecrire_fichier(string $filename, string $content): void { |
|
| 93 | - if (file_exists($filename)) { |
|
| 94 | - supprimer_fichier($filename); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - ecrire_fichier($filename, $content); |
|
| 98 | - } |
|
| 9 | + private string $adresse_dernier_fichier_pour_code = ''; |
|
| 10 | + |
|
| 11 | + private string $cacheDirectory = ''; |
|
| 12 | + |
|
| 13 | + private array $options = []; |
|
| 14 | + |
|
| 15 | + public function __construct(array $options = []) { |
|
| 16 | + include_spip('inc/flock'); |
|
| 17 | + $this->cacheDirectory = sous_repertoire(_DIR_CACHE, 'Tests'); |
|
| 18 | + $this->setOptions($options); |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + public function exists(string $name): bool { |
|
| 22 | + return true; |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + public function getCacheKey(string $name): string { |
|
| 26 | + return md5($name . serialize($this->options)); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Écrit le code du squelette dans un fichier temporaire de cache |
|
| 31 | + */ |
|
| 32 | + public function getSourceFile(string $name): string { |
|
| 33 | + $fond = $this->cacheDirectory . $this->getCacheKey($name); |
|
| 34 | + $options = $this->options; |
|
| 35 | + $code = $name; |
|
| 36 | + |
|
| 37 | + if (isset($options['avant_code'])) { |
|
| 38 | + $code = $options['avant_code'] . $code; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + if (isset($options['apres_code'])) { |
|
| 42 | + $code .= $options['apres_code']; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + $this->ecrire_fichier($fond . '.html', $code); |
|
| 46 | + |
|
| 47 | + if (!empty($options['fonctions'])) { |
|
| 48 | + // un fichier unique pour ces fonctions |
|
| 49 | + $func = $this->cacheDirectory . 'func_' . md5($options['fonctions']) . '.php'; |
|
| 50 | + $this->ecrire_fichier($func, $this->php($options['fonctions'])); |
|
| 51 | + // une inclusion unique de ces fichiers |
|
| 52 | + $this->ecrire_fichier($fond . '_fonctions.php', $this->php(sprintf('include_once(\'%s\');', $func))); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + return $fond; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Définit des options de compilation du code, |
|
| 60 | + * |
|
| 61 | + * Notamment permet de déclarer des filtres (fonctions) pour le code à compiler |
|
| 62 | + * |
|
| 63 | + * Stocke des options : |
|
| 64 | + * - fonctions : pour ajouter un fichier de fonction au squelette cree (on passe le contenu du fichier) |
|
| 65 | + * - avant_code : pour inserer du contenu avant le code |
|
| 66 | + * - apres_code : pour inserer du contenu apres le code |
|
| 67 | + * |
|
| 68 | + * @param array $options : param->valeur des options |
|
| 69 | + */ |
|
| 70 | + private function setOptions(array $options = []): void { |
|
| 71 | + $this->options = $options; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Retourne "<?php $code ?>" |
|
| 76 | + * |
|
| 77 | + * @param string $code Code php |
|
| 78 | + * @return string Code php complet |
|
| 79 | + */ |
|
| 80 | + private function php(string $code): string { |
|
| 81 | + return '<' . "?php\n" . $code . "\n?" . '>'; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Ecrire un fichier à l'endroit indique |
|
| 86 | + * |
|
| 87 | + * Le réécrit systématiquement. |
|
| 88 | + * |
|
| 89 | + * @param string $filename Adresse du fichier a ecrire |
|
| 90 | + * @param string $content Contenu du fichier |
|
| 91 | + */ |
|
| 92 | + private function ecrire_fichier(string $filename, string $content): void { |
|
| 93 | + if (file_exists($filename)) { |
|
| 94 | + supprimer_fichier($filename); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + ecrire_fichier($filename, $content); |
|
| 98 | + } |
|
| 99 | 99 | } |
@@ -23,33 +23,33 @@ discard block |
||
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public function getCacheKey(string $name): string { |
| 26 | - return md5($name . serialize($this->options)); |
|
| 26 | + return md5($name.serialize($this->options)); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Écrit le code du squelette dans un fichier temporaire de cache |
| 31 | 31 | */ |
| 32 | 32 | public function getSourceFile(string $name): string { |
| 33 | - $fond = $this->cacheDirectory . $this->getCacheKey($name); |
|
| 33 | + $fond = $this->cacheDirectory.$this->getCacheKey($name); |
|
| 34 | 34 | $options = $this->options; |
| 35 | 35 | $code = $name; |
| 36 | 36 | |
| 37 | 37 | if (isset($options['avant_code'])) { |
| 38 | - $code = $options['avant_code'] . $code; |
|
| 38 | + $code = $options['avant_code'].$code; |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | if (isset($options['apres_code'])) { |
| 42 | 42 | $code .= $options['apres_code']; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - $this->ecrire_fichier($fond . '.html', $code); |
|
| 45 | + $this->ecrire_fichier($fond.'.html', $code); |
|
| 46 | 46 | |
| 47 | 47 | if (!empty($options['fonctions'])) { |
| 48 | 48 | // un fichier unique pour ces fonctions |
| 49 | - $func = $this->cacheDirectory . 'func_' . md5($options['fonctions']) . '.php'; |
|
| 49 | + $func = $this->cacheDirectory.'func_'.md5($options['fonctions']).'.php'; |
|
| 50 | 50 | $this->ecrire_fichier($func, $this->php($options['fonctions'])); |
| 51 | 51 | // une inclusion unique de ces fichiers |
| 52 | - $this->ecrire_fichier($fond . '_fonctions.php', $this->php(sprintf('include_once(\'%s\');', $func))); |
|
| 52 | + $this->ecrire_fichier($fond.'_fonctions.php', $this->php(sprintf('include_once(\'%s\');', $func))); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | return $fond; |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * @return string Code php complet |
| 79 | 79 | */ |
| 80 | 80 | private function php(string $code): string { |
| 81 | - return '<' . "?php\n" . $code . "\n?" . '>'; |
|
| 81 | + return '<'."?php\n".$code."\n?".'>'; |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -8,59 +8,59 @@ |
||
| 8 | 8 | |
| 9 | 9 | class ChainLoader implements LoaderInterface |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * @var LoaderInterface[] |
|
| 13 | - */ |
|
| 14 | - private array $loaders = []; |
|
| 15 | - |
|
| 16 | - private array $cache = []; |
|
| 17 | - |
|
| 18 | - public function __construct(array $loaders) { |
|
| 19 | - foreach ($loaders as $loader) { |
|
| 20 | - $this->addLoader($loader); |
|
| 21 | - } |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - public function exists(string $name): bool { |
|
| 25 | - if (isset($this->cache[$name])) { |
|
| 26 | - return $this->cache[$name]; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - foreach ($this->loaders as $loader) { |
|
| 30 | - if ($loader->exists($name)) { |
|
| 31 | - return $this->cache[$name] = true; |
|
| 32 | - } |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - return $this->cache[$name] = false; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - public function getCacheKey(string $name): string { |
|
| 39 | - foreach ($this->loaders as $loader) { |
|
| 40 | - if (!$loader->exists($name)) { |
|
| 41 | - continue; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - return $loader->getCacheKey($name); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - throw new TemplateNotFoundException($name); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - public function getSourceFile(string $name): string { |
|
| 51 | - foreach ($this->loaders as $loader) { |
|
| 52 | - if (!$loader->exists($name)) { |
|
| 53 | - continue; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - return $loader->getSourceFile($name); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - throw new TemplateNotFoundException($name); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - private function addLoader(LoaderInterface $loader) { |
|
| 63 | - $this->loaders[] = $loader; |
|
| 64 | - $this->cache = []; |
|
| 65 | - } |
|
| 11 | + /** |
|
| 12 | + * @var LoaderInterface[] |
|
| 13 | + */ |
|
| 14 | + private array $loaders = []; |
|
| 15 | + |
|
| 16 | + private array $cache = []; |
|
| 17 | + |
|
| 18 | + public function __construct(array $loaders) { |
|
| 19 | + foreach ($loaders as $loader) { |
|
| 20 | + $this->addLoader($loader); |
|
| 21 | + } |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + public function exists(string $name): bool { |
|
| 25 | + if (isset($this->cache[$name])) { |
|
| 26 | + return $this->cache[$name]; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + foreach ($this->loaders as $loader) { |
|
| 30 | + if ($loader->exists($name)) { |
|
| 31 | + return $this->cache[$name] = true; |
|
| 32 | + } |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + return $this->cache[$name] = false; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + public function getCacheKey(string $name): string { |
|
| 39 | + foreach ($this->loaders as $loader) { |
|
| 40 | + if (!$loader->exists($name)) { |
|
| 41 | + continue; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + return $loader->getCacheKey($name); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + throw new TemplateNotFoundException($name); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + public function getSourceFile(string $name): string { |
|
| 51 | + foreach ($this->loaders as $loader) { |
|
| 52 | + if (!$loader->exists($name)) { |
|
| 53 | + continue; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + return $loader->getSourceFile($name); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + throw new TemplateNotFoundException($name); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + private function addLoader(LoaderInterface $loader) { |
|
| 63 | + $this->loaders[] = $loader; |
|
| 64 | + $this->cache = []; |
|
| 65 | + } |
|
| 66 | 66 | } |
@@ -6,9 +6,9 @@ |
||
| 6 | 6 | |
| 7 | 7 | interface LoaderInterface |
| 8 | 8 | { |
| 9 | - public function exists(string $name): bool; |
|
| 9 | + public function exists(string $name): bool; |
|
| 10 | 10 | |
| 11 | - public function getSourceFile(string $name): string; |
|
| 11 | + public function getSourceFile(string $name): string; |
|
| 12 | 12 | |
| 13 | - public function getCacheKey(string $name): string; |
|
| 13 | + public function getCacheKey(string $name): string; |
|
| 14 | 14 | } |
@@ -16,9 +16,9 @@ |
||
| 16 | 16 | |
| 17 | 17 | class FrTextwheelTest extends FrTest |
| 18 | 18 | { |
| 19 | - protected static $lang = 'fr'; |
|
| 19 | + protected static $lang = 'fr'; |
|
| 20 | 20 | |
| 21 | - protected static $root = ''; |
|
| 21 | + protected static $root = ''; |
|
| 22 | 22 | |
| 23 | - protected static $fnTypographie = 'typographie_fr'; |
|
| 23 | + protected static $fnTypographie = 'typographie_fr'; |
|
| 24 | 24 | } |
@@ -19,139 +19,139 @@ |
||
| 19 | 19 | |
| 20 | 20 | class FrTest extends TestCase |
| 21 | 21 | { |
| 22 | - protected static $lang = 'fr'; |
|
| 23 | - |
|
| 24 | - protected static $root = 'ecrire/'; |
|
| 25 | - |
|
| 26 | - protected static $fnTypographie = 'typographie_fr_dist'; |
|
| 27 | - |
|
| 28 | - public static function setUpBeforeClass(): void { |
|
| 29 | - include_spip('inc/texte'); |
|
| 30 | - changer_langue(static::$lang); |
|
| 31 | - include_spip(static::$root . 'typographie/' . static::$lang); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - public static function providerBase() { |
|
| 35 | - $list = [ |
|
| 36 | - 'bonjour' => 'bonjour', |
|
| 37 | - 'bonjour ' => 'bonjour ', |
|
| 38 | - 'bonjour à toutes et tous' => 'bonjour à toutes et tous', |
|
| 39 | - ]; |
|
| 40 | - return array_map(null, array_keys($list), array_values($list)); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - #[DataProvider('providerBase')] |
|
| 44 | - public function testBase($source, $expected) { |
|
| 45 | - $typographie = static::$fnTypographie; |
|
| 46 | - $this->assertEquals($expected, $typographie($source)); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - public static function providerAddsSpaceOnPonctuation() { |
|
| 50 | - $list = [ |
|
| 51 | - 'bonjour:' => 'bonjour :', |
|
| 52 | - 'bonjour;' => 'bonjour ;', |
|
| 53 | - 'bonjour!' => 'bonjour !', |
|
| 54 | - 'bonjour?' => 'bonjour ?', |
|
| 55 | - ]; |
|
| 56 | - return array_map(null, array_keys($list), array_values($list)); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - #[DataProvider('providerAddsSpaceOnPonctuation')] |
|
| 60 | - public function testAddsSpaceOnPonctuation($source, $expected) { |
|
| 61 | - $typographie = static::$fnTypographie; |
|
| 62 | - $this->assertEquals($expected, $typographie($source)); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - public static function providerChangeSpaceToNonBreakingSpaceOnPonctuation() { |
|
| 66 | - $list = [ |
|
| 67 | - 'bonjour :' => 'bonjour :', |
|
| 68 | - 'bonjour ;' => 'bonjour ;', |
|
| 69 | - 'bonjour !' => 'bonjour !', |
|
| 70 | - 'bonjour ?' => 'bonjour ?', |
|
| 71 | - ]; |
|
| 72 | - return array_map(null, array_keys($list), array_values($list)); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - #[DataProvider('providerChangeSpaceToNonBreakingSpaceOnPonctuation')] |
|
| 76 | - public function testChangeSpaceToNonBreakingSpaceOnPonctuation($source, $expected) { |
|
| 77 | - $typographie = static::$fnTypographie; |
|
| 78 | - $this->assertEquals($expected, $typographie($source)); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - public static function providerChangeTildeToNonBreakingSpace() { |
|
| 82 | - $list = [ |
|
| 83 | - 'bonjour~toi' => 'bonjour toi', |
|
| 84 | - 'bonjour~le~monde' => 'bonjour le monde', |
|
| 85 | - ]; |
|
| 86 | - return array_map(null, array_keys($list), array_values($list)); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - #[DataProvider('providerChangeTildeToNonBreakingSpace')] |
|
| 90 | - public function testChangeTildeToNonBreakingSpace($source, $expected) { |
|
| 91 | - $typographie = static::$fnTypographie; |
|
| 92 | - $this->assertEquals($expected, $typographie($source)); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - public static function providerChangeTildeToNonBreakingSpaceOnPonctuation() { |
|
| 96 | - $list = [ |
|
| 97 | - 'bonjour~:' => 'bonjour :', |
|
| 98 | - 'bonjour~;' => 'bonjour ;', |
|
| 99 | - 'bonjour~!' => 'bonjour !', |
|
| 100 | - 'bonjour~?' => 'bonjour ?', |
|
| 101 | - ]; |
|
| 102 | - return array_map(null, array_keys($list), array_values($list)); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - #[DataProvider('providerChangeTildeToNonBreakingSpaceOnPonctuation')] |
|
| 106 | - public function testChangeTildeToNonBreakingSpaceOnPonctuation($source, $expected) { |
|
| 107 | - $typographie = static::$fnTypographie; |
|
| 108 | - $this->assertEquals($expected, $typographie($source)); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - public static function providerKeepNonBreakingSpaceEntity() { |
|
| 112 | - $list = [ |
|
| 113 | - 'bonjour toi' => 'bonjour toi', |
|
| 114 | - 'bonjour toi !' => 'bonjour toi !', |
|
| 115 | - ]; |
|
| 116 | - return array_map(null, array_keys($list), array_values($list)); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - #[DataProvider('providerKeepNonBreakingSpaceEntity')] |
|
| 120 | - public function testKeepNonBreakingSpaceEntity($source, $expected) { |
|
| 121 | - $typographie = static::$fnTypographie; |
|
| 122 | - $this->assertEquals($expected, $typographie($source)); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - public static function providerKeepNonBreakingSpaceUtf() { |
|
| 126 | - $list = [ |
|
| 127 | - 'bonjour toi' => 'bonjour toi', |
|
| 128 | - 'bonjour toi !' => 'bonjour toi !', |
|
| 129 | - ]; |
|
| 130 | - return array_map(null, array_keys($list), array_values($list)); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - #[DataProvider('providerKeepNonBreakingSpaceUtf')] |
|
| 134 | - public function testKeepNonBreakingSpaceUtf($source, $expected): never { |
|
| 135 | - $typographie = static::$fnTypographie; |
|
| 136 | - // TODO |
|
| 137 | - $this->markTestSkipped('NIY'); |
|
| 138 | - $this->assertEquals($expected, $typographie($source)); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - public static function providerKeepDoubleTwoPoints() { |
|
| 142 | - $list = [ |
|
| 143 | - 'bonjour::' => 'bonjour::', |
|
| 144 | - '::1/128' => '::1/128', |
|
| 145 | - 'ff00::/8' => 'ff00::/8', |
|
| 146 | - ]; |
|
| 147 | - return array_map(null, array_keys($list), array_values($list)); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - #[DataProvider('providerKeepDoubleTwoPoints')] |
|
| 151 | - public function testKeepDoubleTwoPoints($source, $expected): never { |
|
| 152 | - $typographie = static::$fnTypographie; |
|
| 153 | - // TODO |
|
| 154 | - $this->markTestSkipped('NIY'); |
|
| 155 | - $this->assertEquals($expected, $typographie($source)); |
|
| 156 | - } |
|
| 22 | + protected static $lang = 'fr'; |
|
| 23 | + |
|
| 24 | + protected static $root = 'ecrire/'; |
|
| 25 | + |
|
| 26 | + protected static $fnTypographie = 'typographie_fr_dist'; |
|
| 27 | + |
|
| 28 | + public static function setUpBeforeClass(): void { |
|
| 29 | + include_spip('inc/texte'); |
|
| 30 | + changer_langue(static::$lang); |
|
| 31 | + include_spip(static::$root . 'typographie/' . static::$lang); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + public static function providerBase() { |
|
| 35 | + $list = [ |
|
| 36 | + 'bonjour' => 'bonjour', |
|
| 37 | + 'bonjour ' => 'bonjour ', |
|
| 38 | + 'bonjour à toutes et tous' => 'bonjour à toutes et tous', |
|
| 39 | + ]; |
|
| 40 | + return array_map(null, array_keys($list), array_values($list)); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + #[DataProvider('providerBase')] |
|
| 44 | + public function testBase($source, $expected) { |
|
| 45 | + $typographie = static::$fnTypographie; |
|
| 46 | + $this->assertEquals($expected, $typographie($source)); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + public static function providerAddsSpaceOnPonctuation() { |
|
| 50 | + $list = [ |
|
| 51 | + 'bonjour:' => 'bonjour :', |
|
| 52 | + 'bonjour;' => 'bonjour ;', |
|
| 53 | + 'bonjour!' => 'bonjour !', |
|
| 54 | + 'bonjour?' => 'bonjour ?', |
|
| 55 | + ]; |
|
| 56 | + return array_map(null, array_keys($list), array_values($list)); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + #[DataProvider('providerAddsSpaceOnPonctuation')] |
|
| 60 | + public function testAddsSpaceOnPonctuation($source, $expected) { |
|
| 61 | + $typographie = static::$fnTypographie; |
|
| 62 | + $this->assertEquals($expected, $typographie($source)); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + public static function providerChangeSpaceToNonBreakingSpaceOnPonctuation() { |
|
| 66 | + $list = [ |
|
| 67 | + 'bonjour :' => 'bonjour :', |
|
| 68 | + 'bonjour ;' => 'bonjour ;', |
|
| 69 | + 'bonjour !' => 'bonjour !', |
|
| 70 | + 'bonjour ?' => 'bonjour ?', |
|
| 71 | + ]; |
|
| 72 | + return array_map(null, array_keys($list), array_values($list)); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + #[DataProvider('providerChangeSpaceToNonBreakingSpaceOnPonctuation')] |
|
| 76 | + public function testChangeSpaceToNonBreakingSpaceOnPonctuation($source, $expected) { |
|
| 77 | + $typographie = static::$fnTypographie; |
|
| 78 | + $this->assertEquals($expected, $typographie($source)); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + public static function providerChangeTildeToNonBreakingSpace() { |
|
| 82 | + $list = [ |
|
| 83 | + 'bonjour~toi' => 'bonjour toi', |
|
| 84 | + 'bonjour~le~monde' => 'bonjour le monde', |
|
| 85 | + ]; |
|
| 86 | + return array_map(null, array_keys($list), array_values($list)); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + #[DataProvider('providerChangeTildeToNonBreakingSpace')] |
|
| 90 | + public function testChangeTildeToNonBreakingSpace($source, $expected) { |
|
| 91 | + $typographie = static::$fnTypographie; |
|
| 92 | + $this->assertEquals($expected, $typographie($source)); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + public static function providerChangeTildeToNonBreakingSpaceOnPonctuation() { |
|
| 96 | + $list = [ |
|
| 97 | + 'bonjour~:' => 'bonjour :', |
|
| 98 | + 'bonjour~;' => 'bonjour ;', |
|
| 99 | + 'bonjour~!' => 'bonjour !', |
|
| 100 | + 'bonjour~?' => 'bonjour ?', |
|
| 101 | + ]; |
|
| 102 | + return array_map(null, array_keys($list), array_values($list)); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + #[DataProvider('providerChangeTildeToNonBreakingSpaceOnPonctuation')] |
|
| 106 | + public function testChangeTildeToNonBreakingSpaceOnPonctuation($source, $expected) { |
|
| 107 | + $typographie = static::$fnTypographie; |
|
| 108 | + $this->assertEquals($expected, $typographie($source)); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + public static function providerKeepNonBreakingSpaceEntity() { |
|
| 112 | + $list = [ |
|
| 113 | + 'bonjour toi' => 'bonjour toi', |
|
| 114 | + 'bonjour toi !' => 'bonjour toi !', |
|
| 115 | + ]; |
|
| 116 | + return array_map(null, array_keys($list), array_values($list)); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + #[DataProvider('providerKeepNonBreakingSpaceEntity')] |
|
| 120 | + public function testKeepNonBreakingSpaceEntity($source, $expected) { |
|
| 121 | + $typographie = static::$fnTypographie; |
|
| 122 | + $this->assertEquals($expected, $typographie($source)); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + public static function providerKeepNonBreakingSpaceUtf() { |
|
| 126 | + $list = [ |
|
| 127 | + 'bonjour toi' => 'bonjour toi', |
|
| 128 | + 'bonjour toi !' => 'bonjour toi !', |
|
| 129 | + ]; |
|
| 130 | + return array_map(null, array_keys($list), array_values($list)); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + #[DataProvider('providerKeepNonBreakingSpaceUtf')] |
|
| 134 | + public function testKeepNonBreakingSpaceUtf($source, $expected): never { |
|
| 135 | + $typographie = static::$fnTypographie; |
|
| 136 | + // TODO |
|
| 137 | + $this->markTestSkipped('NIY'); |
|
| 138 | + $this->assertEquals($expected, $typographie($source)); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + public static function providerKeepDoubleTwoPoints() { |
|
| 142 | + $list = [ |
|
| 143 | + 'bonjour::' => 'bonjour::', |
|
| 144 | + '::1/128' => '::1/128', |
|
| 145 | + 'ff00::/8' => 'ff00::/8', |
|
| 146 | + ]; |
|
| 147 | + return array_map(null, array_keys($list), array_values($list)); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + #[DataProvider('providerKeepDoubleTwoPoints')] |
|
| 151 | + public function testKeepDoubleTwoPoints($source, $expected): never { |
|
| 152 | + $typographie = static::$fnTypographie; |
|
| 153 | + // TODO |
|
| 154 | + $this->markTestSkipped('NIY'); |
|
| 155 | + $this->assertEquals($expected, $typographie($source)); |
|
| 156 | + } |
|
| 157 | 157 | } |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | public static function setUpBeforeClass(): void { |
| 29 | 29 | include_spip('inc/texte'); |
| 30 | 30 | changer_langue(static::$lang); |
| 31 | - include_spip(static::$root . 'typographie/' . static::$lang); |
|
| 31 | + include_spip(static::$root.'typographie/'.static::$lang); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | public static function providerBase() { |
@@ -8,114 +8,114 @@ |
||
| 8 | 8 | |
| 9 | 9 | class NotesTest extends TestCase |
| 10 | 10 | { |
| 11 | - public static function setUpBeforeClass(): void { |
|
| 12 | - include_spip('public/composer'); |
|
| 13 | - include_spip('inc/notes'); |
|
| 14 | - } |
|
| 15 | - |
|
| 16 | - protected function setUp(): void { |
|
| 17 | - $this->viderNotes(); |
|
| 18 | - } |
|
| 19 | - |
|
| 20 | - public function testNoteSimple(): void { |
|
| 21 | - $expected = '<p>a<span class="spip_note_ref"> [<a href="#nb1" class="spip_note" rel="appendix" title="b" id="nh1">1</a>]</span></p>'; |
|
| 22 | - $this->assertEquals($expected, propre('a[[b]]')); |
|
| 23 | - |
|
| 24 | - $expected = "<div id=\"nb1\">\n<p><span class=\"spip_note_ref\">[<a href=\"#nh1\" class=\"spip_note\" title=\"" . _T('info_notes') . " 1\" rev=\"appendix\">1</a>] </span>b</p>\n</div>"; |
|
| 25 | - $this->assertEquals($expected, calculer_notes()); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - public function testNoteSeule(): void { |
|
| 29 | - $texte = propre('[[Note en bas de page]]'); |
|
| 30 | - // id de la note en pied de page |
|
| 31 | - $this->assertMatchesRegularExpression('/#nb1/', $texte); |
|
| 32 | - // classe sur le lien vers le pied |
|
| 33 | - $this->assertMatchesRegularExpression('/spip_note/', $texte); |
|
| 34 | - // id du lien pour remonter ici |
|
| 35 | - $this->assertMatchesRegularExpression('/nh1/', $texte); |
|
| 36 | - |
|
| 37 | - // calculer les notes |
|
| 38 | - $note = calculer_notes(); |
|
| 39 | - $this->assertMatchesRegularExpression('/nb1/', $note); |
|
| 40 | - $this->assertMatchesRegularExpression('/#nh1/', $note); |
|
| 41 | - $this->assertMatchesRegularExpression('/Note en bas de page/', $note); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - public function testNoteSeuleEtTexte(): void { |
|
| 45 | - $texte = propre('Texte avant [[Note en bas de page]] texte apres'); |
|
| 46 | - $this->assertMatchesRegularExpression('/#nb1/', $texte); |
|
| 47 | - $this->assertMatchesRegularExpression('/nh1/', $texte); |
|
| 48 | - $this->assertMatchesRegularExpression('/spip_note/', $texte); |
|
| 49 | - $this->assertMatchesRegularExpression('/Texte avant/', $texte); |
|
| 50 | - $this->assertMatchesRegularExpression('/texte apres/', $texte); |
|
| 51 | - $note = calculer_notes(); |
|
| 52 | - $this->assertMatchesRegularExpression('/nb1/', $note); |
|
| 53 | - $this->assertMatchesRegularExpression('/#nh1/', $note); |
|
| 54 | - $this->assertMatchesRegularExpression('/Note en bas de page/', $note); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - public function testNoteDoubleEtTexte(): void { |
|
| 58 | - $texte = propre('Texte avant [[Note en bas de page]] texte apres [[Seconde note en bas de page]]'); |
|
| 59 | - $this->assertMatchesRegularExpression('/#nb1/', $texte); |
|
| 60 | - $this->assertMatchesRegularExpression('/#nb2/', $texte); |
|
| 61 | - $this->assertMatchesRegularExpression('/texte apres/', $texte); |
|
| 62 | - $note = calculer_notes(); |
|
| 63 | - $this->assertMatchesRegularExpression('/Note en bas de page/', $note); |
|
| 64 | - $this->assertMatchesRegularExpression('/Seconde note en bas de page/', $note); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * En ne vidant pas les notes les identifiant des renvois changent |
|
| 69 | - */ |
|
| 70 | - public function testNoteDoubleDeuxFoisEtDeuxCalculs(): void { |
|
| 71 | - $texte = propre('Texte avant [[Note en bas de page]] texte apres [[Seconde note en bas de page]]'); |
|
| 72 | - $note = calculer_notes(); |
|
| 73 | - $texte2 = propre('Autre avant [[Pinguin en bas de page]] autre apres [[Marmotte en bas de page]]'); |
|
| 74 | - $note2 = calculer_notes(); |
|
| 75 | - |
|
| 76 | - $this->assertMatchesRegularExpression('/#nb1/', $texte); |
|
| 77 | - $this->assertMatchesRegularExpression('/#nb2/', $texte); |
|
| 78 | - $this->assertMatchesRegularExpression('/#nb2-1/', $texte2); |
|
| 79 | - $this->assertMatchesRegularExpression('/#nb2-2/', $texte2); |
|
| 80 | - |
|
| 81 | - $this->assertMatchesRegularExpression('/Note en bas de page/', $note); |
|
| 82 | - $this->assertMatchesRegularExpression('/Seconde note en bas de page/', $note); |
|
| 83 | - $this->assertMatchesRegularExpression('/Pinguin en bas de page/', $note2); |
|
| 84 | - $this->assertMatchesRegularExpression('/Marmotte en bas de page/', $note2); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * En ne vidant pas les notes les identifiant des renvois changent |
|
| 89 | - */ |
|
| 90 | - public function testNoteDoubleDeuxFoisEtUnCalcul(): void { |
|
| 91 | - $texte = propre('Texte avant [[Note en bas de page]] texte apres [[Seconde note en bas de page]]'); |
|
| 92 | - $texte2 = propre('Autre avant [[Pinguin en bas de page]] autre apres [[Marmotte en bas de page]]'); |
|
| 93 | - $note = calculer_notes(); |
|
| 94 | - |
|
| 95 | - $this->assertMatchesRegularExpression('/#nb1/', $texte); |
|
| 96 | - $this->assertMatchesRegularExpression('/#nb2/', $texte); |
|
| 97 | - $this->assertMatchesRegularExpression('/#nb3/', $texte2); |
|
| 98 | - $this->assertMatchesRegularExpression('/#nb4/', $texte2); |
|
| 99 | - |
|
| 100 | - $this->assertMatchesRegularExpression('/Note en bas de page/', $note); |
|
| 101 | - $this->assertMatchesRegularExpression('/Seconde note en bas de page/', $note); |
|
| 102 | - $this->assertMatchesRegularExpression('/Pinguin en bas de page/', $note); |
|
| 103 | - $this->assertMatchesRegularExpression('/Marmotte en bas de page/', $note); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - public function testNoteDoubleCoupeParModele(): void { |
|
| 107 | - $texte = propre('Texte avant [[Note en bas de page]] <img1> [[Seconde note en bas de page]]'); |
|
| 108 | - $this->assertMatchesRegularExpression('/#nb1/', $texte); |
|
| 109 | - $this->assertMatchesRegularExpression('/#nb2/', $texte); |
|
| 110 | - |
|
| 111 | - $note = calculer_notes(); |
|
| 112 | - $this->assertMatchesRegularExpression('/Note en bas de page/', $note); |
|
| 113 | - $this->assertMatchesRegularExpression('/Seconde note en bas de page/', $note); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - private function viderNotes(): void { |
|
| 117 | - // attention a cette globale qui pourrait changer dans le temps |
|
| 118 | - $notes = charger_fonction('notes', 'inc'); |
|
| 119 | - $notes('', 'reset_all'); |
|
| 120 | - } |
|
| 11 | + public static function setUpBeforeClass(): void { |
|
| 12 | + include_spip('public/composer'); |
|
| 13 | + include_spip('inc/notes'); |
|
| 14 | + } |
|
| 15 | + |
|
| 16 | + protected function setUp(): void { |
|
| 17 | + $this->viderNotes(); |
|
| 18 | + } |
|
| 19 | + |
|
| 20 | + public function testNoteSimple(): void { |
|
| 21 | + $expected = '<p>a<span class="spip_note_ref"> [<a href="#nb1" class="spip_note" rel="appendix" title="b" id="nh1">1</a>]</span></p>'; |
|
| 22 | + $this->assertEquals($expected, propre('a[[b]]')); |
|
| 23 | + |
|
| 24 | + $expected = "<div id=\"nb1\">\n<p><span class=\"spip_note_ref\">[<a href=\"#nh1\" class=\"spip_note\" title=\"" . _T('info_notes') . " 1\" rev=\"appendix\">1</a>] </span>b</p>\n</div>"; |
|
| 25 | + $this->assertEquals($expected, calculer_notes()); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + public function testNoteSeule(): void { |
|
| 29 | + $texte = propre('[[Note en bas de page]]'); |
|
| 30 | + // id de la note en pied de page |
|
| 31 | + $this->assertMatchesRegularExpression('/#nb1/', $texte); |
|
| 32 | + // classe sur le lien vers le pied |
|
| 33 | + $this->assertMatchesRegularExpression('/spip_note/', $texte); |
|
| 34 | + // id du lien pour remonter ici |
|
| 35 | + $this->assertMatchesRegularExpression('/nh1/', $texte); |
|
| 36 | + |
|
| 37 | + // calculer les notes |
|
| 38 | + $note = calculer_notes(); |
|
| 39 | + $this->assertMatchesRegularExpression('/nb1/', $note); |
|
| 40 | + $this->assertMatchesRegularExpression('/#nh1/', $note); |
|
| 41 | + $this->assertMatchesRegularExpression('/Note en bas de page/', $note); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + public function testNoteSeuleEtTexte(): void { |
|
| 45 | + $texte = propre('Texte avant [[Note en bas de page]] texte apres'); |
|
| 46 | + $this->assertMatchesRegularExpression('/#nb1/', $texte); |
|
| 47 | + $this->assertMatchesRegularExpression('/nh1/', $texte); |
|
| 48 | + $this->assertMatchesRegularExpression('/spip_note/', $texte); |
|
| 49 | + $this->assertMatchesRegularExpression('/Texte avant/', $texte); |
|
| 50 | + $this->assertMatchesRegularExpression('/texte apres/', $texte); |
|
| 51 | + $note = calculer_notes(); |
|
| 52 | + $this->assertMatchesRegularExpression('/nb1/', $note); |
|
| 53 | + $this->assertMatchesRegularExpression('/#nh1/', $note); |
|
| 54 | + $this->assertMatchesRegularExpression('/Note en bas de page/', $note); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + public function testNoteDoubleEtTexte(): void { |
|
| 58 | + $texte = propre('Texte avant [[Note en bas de page]] texte apres [[Seconde note en bas de page]]'); |
|
| 59 | + $this->assertMatchesRegularExpression('/#nb1/', $texte); |
|
| 60 | + $this->assertMatchesRegularExpression('/#nb2/', $texte); |
|
| 61 | + $this->assertMatchesRegularExpression('/texte apres/', $texte); |
|
| 62 | + $note = calculer_notes(); |
|
| 63 | + $this->assertMatchesRegularExpression('/Note en bas de page/', $note); |
|
| 64 | + $this->assertMatchesRegularExpression('/Seconde note en bas de page/', $note); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * En ne vidant pas les notes les identifiant des renvois changent |
|
| 69 | + */ |
|
| 70 | + public function testNoteDoubleDeuxFoisEtDeuxCalculs(): void { |
|
| 71 | + $texte = propre('Texte avant [[Note en bas de page]] texte apres [[Seconde note en bas de page]]'); |
|
| 72 | + $note = calculer_notes(); |
|
| 73 | + $texte2 = propre('Autre avant [[Pinguin en bas de page]] autre apres [[Marmotte en bas de page]]'); |
|
| 74 | + $note2 = calculer_notes(); |
|
| 75 | + |
|
| 76 | + $this->assertMatchesRegularExpression('/#nb1/', $texte); |
|
| 77 | + $this->assertMatchesRegularExpression('/#nb2/', $texte); |
|
| 78 | + $this->assertMatchesRegularExpression('/#nb2-1/', $texte2); |
|
| 79 | + $this->assertMatchesRegularExpression('/#nb2-2/', $texte2); |
|
| 80 | + |
|
| 81 | + $this->assertMatchesRegularExpression('/Note en bas de page/', $note); |
|
| 82 | + $this->assertMatchesRegularExpression('/Seconde note en bas de page/', $note); |
|
| 83 | + $this->assertMatchesRegularExpression('/Pinguin en bas de page/', $note2); |
|
| 84 | + $this->assertMatchesRegularExpression('/Marmotte en bas de page/', $note2); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * En ne vidant pas les notes les identifiant des renvois changent |
|
| 89 | + */ |
|
| 90 | + public function testNoteDoubleDeuxFoisEtUnCalcul(): void { |
|
| 91 | + $texte = propre('Texte avant [[Note en bas de page]] texte apres [[Seconde note en bas de page]]'); |
|
| 92 | + $texte2 = propre('Autre avant [[Pinguin en bas de page]] autre apres [[Marmotte en bas de page]]'); |
|
| 93 | + $note = calculer_notes(); |
|
| 94 | + |
|
| 95 | + $this->assertMatchesRegularExpression('/#nb1/', $texte); |
|
| 96 | + $this->assertMatchesRegularExpression('/#nb2/', $texte); |
|
| 97 | + $this->assertMatchesRegularExpression('/#nb3/', $texte2); |
|
| 98 | + $this->assertMatchesRegularExpression('/#nb4/', $texte2); |
|
| 99 | + |
|
| 100 | + $this->assertMatchesRegularExpression('/Note en bas de page/', $note); |
|
| 101 | + $this->assertMatchesRegularExpression('/Seconde note en bas de page/', $note); |
|
| 102 | + $this->assertMatchesRegularExpression('/Pinguin en bas de page/', $note); |
|
| 103 | + $this->assertMatchesRegularExpression('/Marmotte en bas de page/', $note); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + public function testNoteDoubleCoupeParModele(): void { |
|
| 107 | + $texte = propre('Texte avant [[Note en bas de page]] <img1> [[Seconde note en bas de page]]'); |
|
| 108 | + $this->assertMatchesRegularExpression('/#nb1/', $texte); |
|
| 109 | + $this->assertMatchesRegularExpression('/#nb2/', $texte); |
|
| 110 | + |
|
| 111 | + $note = calculer_notes(); |
|
| 112 | + $this->assertMatchesRegularExpression('/Note en bas de page/', $note); |
|
| 113 | + $this->assertMatchesRegularExpression('/Seconde note en bas de page/', $note); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + private function viderNotes(): void { |
|
| 117 | + // attention a cette globale qui pourrait changer dans le temps |
|
| 118 | + $notes = charger_fonction('notes', 'inc'); |
|
| 119 | + $notes('', 'reset_all'); |
|
| 120 | + } |
|
| 121 | 121 | } |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | $expected = '<p>a<span class="spip_note_ref"> [<a href="#nb1" class="spip_note" rel="appendix" title="b" id="nh1">1</a>]</span></p>'; |
| 22 | 22 | $this->assertEquals($expected, propre('a[[b]]')); |
| 23 | 23 | |
| 24 | - $expected = "<div id=\"nb1\">\n<p><span class=\"spip_note_ref\">[<a href=\"#nh1\" class=\"spip_note\" title=\"" . _T('info_notes') . " 1\" rev=\"appendix\">1</a>] </span>b</p>\n</div>"; |
|
| 24 | + $expected = "<div id=\"nb1\">\n<p><span class=\"spip_note_ref\">[<a href=\"#nh1\" class=\"spip_note\" title=\""._T('info_notes')." 1\" rev=\"appendix\">1</a>] </span>b</p>\n</div>"; |
|
| 25 | 25 | $this->assertEquals($expected, calculer_notes()); |
| 26 | 26 | } |
| 27 | 27 | |