68 lines
3.0 KiB
PHP
68 lines
3.0 KiB
PHP
<?php
|
|
/**
|
|
* Tests du plugin THALIM Newsletter.
|
|
*
|
|
* Exécution (environnement Docker de dev) :
|
|
* docker exec wordpress php /var/www/html/wp-content/plugins/thalim-newsletter/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";
|
|
}
|
|
}
|
|
|
|
echo "== constantes de catégories (résolution par slug) ==\n";
|
|
check('APPELS = 8', THALIM_NL_CAT_APPELS, 8);
|
|
check('COLLOQUES = 10', THALIM_NL_CAT_COLLOQUES, 10);
|
|
check('SEMINAIRES = 11', THALIM_NL_CAT_SEMINAIRES, 11);
|
|
check('COMMS = 13', THALIM_NL_CAT_COMMS, 13);
|
|
check('SOUTENANCES = 14', THALIM_NL_CAT_SOUTENANCES, 14);
|
|
check('OUVRAGES = 15', THALIM_NL_CAT_OUVRAGES, 15);
|
|
check('ARTICLES = 16', THALIM_NL_CAT_ARTICLES, 16);
|
|
check('NEWSLETTER = 20', THALIM_NL_CAT_NEWSLETTER, 20);
|
|
|
|
echo "== fenêtres de dates par catégorie ==\n";
|
|
check('appels → datetime_to_fin', Thalim_NL_Post_Query::get_window_type(THALIM_NL_CAT_APPELS), 'datetime_to_fin');
|
|
check('colloques → debut_minus35_to_fin', Thalim_NL_Post_Query::get_window_type(THALIM_NL_CAT_COLLOQUES), 'debut_minus35_to_fin');
|
|
check('comms → debut_minus35_to_fin', Thalim_NL_Post_Query::get_window_type(THALIM_NL_CAT_COMMS), 'debut_minus35_to_fin');
|
|
check('soutenances → datetime_to_fin', Thalim_NL_Post_Query::get_window_type(THALIM_NL_CAT_SOUTENANCES), 'datetime_to_fin');
|
|
check('ouvrages → datetime_plus3m', Thalim_NL_Post_Query::get_window_type(THALIM_NL_CAT_OUVRAGES), 'datetime_plus3m');
|
|
check('articles → datetime_plus3m', Thalim_NL_Post_Query::get_window_type(THALIM_NL_CAT_ARTICLES), 'datetime_plus3m');
|
|
check('autre cat → datetime_plus35d', Thalim_NL_Post_Query::get_window_type(99999), 'datetime_plus35d');
|
|
|
|
echo "== catégories éligibles ==\n";
|
|
$eligible = Thalim_NL_Post_Query::get_all_eligible_cat_ids();
|
|
check('exclut séances (12)', in_array(12, $eligible, true), false);
|
|
check('exclut vie du labo (9)', in_array(9, $eligible, true), false);
|
|
check('exclut newsletter (20)', in_array(20, $eligible, true), false);
|
|
check('exclut non classé (31)', in_array(31, $eligible, true), false);
|
|
check('inclut séminaires (11)', in_array(11, $eligible, true), true);
|
|
|
|
echo "== get_posts_for_month (sanity) ==\n";
|
|
$q = new Thalim_NL_Post_Query();
|
|
check('mois invalide → []', $q->get_posts_for_month('garbage'), []);
|
|
$month = $q->get_posts_for_month(date('Y-m'));
|
|
check('mois courant → array', is_array($month), true);
|
|
|
|
echo "\n$count tests, $failures échec(s)\n";
|
|
exit($failures ? 1 : 0);
|