66 lines
2.7 KiB
PHP
66 lines
2.7 KiB
PHP
<?php
|
|
/**
|
|
* Tests du plugin THALIM HAL Importer.
|
|
*
|
|
* Exécution (environnement Docker de dev) :
|
|
* docker exec wordpress php /var/www/html/wp-content/plugins/thalim-hal-importer/tests/run-tests.php
|
|
*/
|
|
|
|
if (PHP_SAPI !== 'cli') {
|
|
exit("CLI only\n");
|
|
}
|
|
|
|
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_HOST'] ?? 'localhost';
|
|
$_SERVER['REQUEST_URI'] = $_SERVER['REQUEST_URI'] ?? '/';
|
|
|
|
require dirname(__DIR__, 4) . '/wp-load.php';
|
|
|
|
$failures = 0;
|
|
$count = 0;
|
|
|
|
function check(string $name, $actual, $expected): void {
|
|
global $failures, $count;
|
|
$count++;
|
|
if ($actual === $expected) {
|
|
echo " ok $name\n";
|
|
} else {
|
|
$failures++;
|
|
echo " FAIL $name\n attendu: " . var_export($expected, true)
|
|
. "\n obtenu : " . var_export($actual, true) . "\n";
|
|
}
|
|
}
|
|
|
|
$importer = new Thalim_HAL_Importer_Logic();
|
|
|
|
echo "== parse_hal_date (méthode privée, via Reflection) ==\n";
|
|
$parse = new ReflectionMethod(Thalim_HAL_Importer_Logic::class, 'parse_hal_date');
|
|
$parse->setAccessible(true);
|
|
$d = fn(string $raw): string => $parse->invoke($importer, $raw);
|
|
|
|
check('date complète', $d('2022-06-15'), '2022-06-15');
|
|
check('datetime ISO', $d('2022-06-15T10:30:00Z'), '2022-06-15');
|
|
check('année-mois', $d('2022-06'), '2022-06-01');
|
|
check('année seule', $d('2022'), '2022-01-01'); // strtotime("2022") = heure, pas année
|
|
check('chaîne vide', $d(''), '');
|
|
check('espaces', $d(' 2021 '), '2021-01-01');
|
|
check('invalide', $d('not-a-date'), '');
|
|
|
|
echo "== get_category_id (résolution par slug) ==\n";
|
|
check('ART → articles (16)', $importer->get_category_id('ART'), 16);
|
|
check('OUV → ouvrages (15)', $importer->get_category_id('OUV'), 15);
|
|
check('THESE → soutenances (14)', $importer->get_category_id('THESE'), 14);
|
|
check('SON → medias (19)', $importer->get_category_id('SON'), 19);
|
|
check('REPORT → publications (4)',$importer->get_category_id('REPORT'), 4);
|
|
check('type inconnu → null', $importer->get_category_id('XYZ'), null);
|
|
|
|
echo "== Thalim_HAL_Pods_Storage (résolution par nom) ==\n";
|
|
check('pod post = 8', Thalim_HAL_Pods_Storage::pod_id(), 8);
|
|
check('champ categorie = 16', Thalim_HAL_Pods_Storage::field_id('categorie'), 16);
|
|
check('champ membres = 178', Thalim_HAL_Pods_Storage::field_id('membres'), 178);
|
|
check('champ etiquettes = 652',Thalim_HAL_Pods_Storage::field_id('etiquettes'), 652);
|
|
check('champ axes = 270', Thalim_HAL_Pods_Storage::field_id('axes_thematiques'), 270);
|
|
check('champ inconnu = 0', Thalim_HAL_Pods_Storage::field_id('champ_bidon'), 0);
|
|
|
|
echo "\n$count tests, $failures échec(s)\n";
|
|
exit($failures ? 1 : 0);
|