Skip to content
Extraits de code Groupes Projets
Valider e8c815da rédigé par marcimat's avatar marcimat Validation de marcimat
Parcourir les fichiers

tests: tests de xml 'hack' en phpunit

parent 6a6ac6c3
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 44 ajouts et 92 suppressions
<?php
declare(strict_types=1);
namespace Spip\Test\Xml;
use PHPUnit\Framework\Attributes\DataProvider;
use Spip\Test\SquelettesTestCase;
/**
* Le hack xml repère dans le squelette la sequence "< ?xml"
* et évite de l'éxecuter en php
*/
class XmlHackTest extends SquelettesTestCase
{
#[DataProvider('providerXmlIsNotPhp')]
public function testXmlIsNotPhp(string $squelette): void {
$skel = $this->relativePath(__DIR__ . '/data/' . $squelette);
$out = recuperer_fond($skel, [], [
'raw' => true,
'trim' => true
]);
$this->assertEmpty($out['erreur'] ?? null);
$this->assertNotEmpty($out['texte']);
$xml = simplexml_load_string($out['texte']);
$this->assertOk((string) $xml[0]);
}
public static function providerXmlIsNotPhp(): array {
return [
['xmlhack'],
['xmlhack_php'],
['xmlhack_inclure'],
['xmlhack_inclure_php'],
['xmlhack_inclure_dyn'],
['xmlhack_inclure_dyn_php'],
];
}
}
<?xml version="1.0"[ encoding="(#CHARSET)"]?>
<tag>OK</tag>
[(#INCLURE{fond=#DOSSIER_SQUELETTE/xmlhack})]
<?xml version="1.0"[ encoding="(#CHARSET)"]?>
<tag><?php echo 'OK'; ?></tag>
[(#REM)
le hack xml repere dans le squelette la sequence "< ?xml"
et evite de l'executer en php
]
#CACHE{0}<!--
filtre:spip_xml_parse
filtre:reset
filtre:reset
-->
<?xml version="1.0"[ encoding="(#CHARSET)"]?>
<tag>OK</tag>
\ No newline at end of file
<?php
declare(strict_types=1);
include_spip('inc/xml');
[(#INCLURE{fond=#DOSSIER_SQUELETTE/xmlhack})]
\ No newline at end of file
[(#REM)
le hack xml repere dans le squelette la sequence "< ?xml"
et evite de l'executer en php
]
#CACHE{0}<!--
filtre:spip_xml_parse
filtre:reset
filtre:reset
-->
<?xml version="1.0"[ encoding="(#CHARSET)"]?>
<tag><?php echo 'OK'; ?></tag>
\ No newline at end of file
<?php
declare(strict_types=1);
include_spip('inc/xml');
<?php
declare(strict_types=1);
$test = 'xmlhack_recuperer_fond';
$remonte = __DIR__ . '/';
while (!is_file($remonte . 'test.inc')) {
$remonte .= '../';
}
require $remonte . 'test.inc';
include_spip('public/assembler');
$dir = substr(dirname(__DIR__, 2), strlen(_SPIP_TEST_CHDIR) + 1);
$out = recuperer_fond($dir . '/unit/xml/xmlhack');
// regarder si le hack a marche
include_spip('inc/xml');
$tree = spip_xml_parse($out);
$ok = reset($tree);
$ok = reset($ok);
if ($ok !== 'OK') {
echo '<dl> Erreur sur le xml produit (xmlhack) : ' . serialize($tree) . '</dl>';
}
$out = recuperer_fond($dir . '/unit/xml/xmlhack_php');
// regarder si le hack a marche
include_spip('inc/xml');
$tree = spip_xml_parse($out);
$ok1 = reset($tree);
$ok1 = reset($ok1);
if ($ok1 !== 'OK') {
echo '<dl> Erreur sur le xml produit (xmlhack_php) : ' . serialize($tree) . '</dl>';
}
if ($ok && $ok1) {
echo 'OK';
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter