Skip to content
Extraits de code Groupes Projets
Valider 89f9e9af rédigé par JamesRezo's avatar JamesRezo
Parcourir les fichiers

Merge pull request 'import du git des tests et de son historique' (#5581) from...

Merge pull request 'import du git des tests et de son historique' (#5581) from import-tests-and-history into master

Reviewed-on: https://git.spip.net/spip/spip/pulls/5581


Reviewed-by: default avatarmarcimat <marcimat@noreply.git.spip.net>
Reviewed-by: default avatarb_b <b_b@noreply.git.spip.net>
parents 389913a4 726a08bd
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 3306 ajouts et 62 suppressions
...@@ -11,5 +11,5 @@ docker-compose.yml export-ignore ...@@ -11,5 +11,5 @@ docker-compose.yml export-ignore
/lib/ export-ignore /lib/ export-ignore
/mutualisation/ export-ignore /mutualisation/ export-ignore
/sites/ export-ignore /sites/ export-ignore
/tests/ export-ignore /ecrire/tests/ export-ignore
/themes/ export-ignore /themes/ export-ignore
...@@ -2,10 +2,12 @@ ...@@ -2,10 +2,12 @@
/vendor/ /vendor/
/composer.phar /composer.phar
/composer.local.* /composer.local.*
/phpunit.xml
/phpcs.xml /phpcs.xml
/phpstan.neon /phpstan.neon
/docker-compose.override.yml /docker-compose.override.yml
/docker-compose.yml /docker-compose.yml
/.phpunit.cache
# SPIP # SPIP
/IMG/ /IMG/
...@@ -28,7 +30,6 @@ ...@@ -28,7 +30,6 @@
/plugins/ /plugins/
/sites/ /sites/
/squelettes/ /squelettes/
/tests/
/themes/ /themes/
# IDE # IDE
......
...@@ -21,3 +21,40 @@ maintenu par sa communauté avec tendresse. ...@@ -21,3 +21,40 @@ maintenu par sa communauté avec tendresse.
- [Reporter une faille de sécurité](https://www.spip.net/fr_article6688.html) - [Reporter une faille de sécurité](https://www.spip.net/fr_article6688.html)
- [SECURITY.md](SECURITY.md) - [SECURITY.md](SECURITY.md)
## Tests pour SPIP
Suite de tests basée sur PHPUnit, avec un wrapper pour les tests historiques écrits en script PHP standalone ou en squelette HTML
### Commandes spécifiques
Lancer tous les tests
```bash
vendor/bin/phpunit
```
Voir le détail de tous les tests lancés (y compris leurs noms)
```bash
vendor/bin/phpunit --debug
```
Lister toutes les suites de tests :
```bash
vendor/bin/phpunit --list-suites
```
Lister tous les tests :
```bash
vendor/bin/phpunit --list-tests
```
Pour filtrer les tests et n'en executer que certains :
```bash
vendor/bin/phpunit --colors --debug --filter=unit/propre/
vendor/bin/phpunit --colors --debug --filter=testCouper
```
...@@ -35,13 +35,17 @@ ...@@ -35,13 +35,17 @@
}, },
"require-dev": { "require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^1.0", "dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"lolli42/finediff": "^1.0",
"phpcompatibility/php-compatibility": "10.x-dev", "phpcompatibility/php-compatibility": "10.x-dev",
"phpstan/phpstan": "^1.10", "phpstan/phpstan": "^1.10",
"spip/coding-standards": "^1.3" "phpunit/phpunit": "^10.1",
"spip/coding-standards": "^1.3",
"symplify/easy-coding-standard": "^11.3"
}, },
"suggest": { "suggest": {
"ext-curl": "*", "ext-curl": "*",
"ext-gd": "For image processing", "ext-gd": "For image processing",
"ext-iconv": "Can be used as fallback when ext-mbstring is not available",
"ext-mbstring": "Faster than the polyfill for string actions", "ext-mbstring": "Faster than the polyfill for string actions",
"ext-mysqli": "*", "ext-mysqli": "*",
"ext-pdo": "*", "ext-pdo": "*",
...@@ -58,9 +62,15 @@ ...@@ -58,9 +62,15 @@
"Spip\\": "ecrire/src/" "Spip\\": "ecrire/src/"
} }
}, },
"autoload-dev": {
"psr-4": {
"Spip\\Test\\": "ecrire/tests/"
}
},
"archive": { "archive": {
"exclude": [ "exclude": [
"!vendor", "!vendor",
"phpunit.xml.dist",
"phpcs.xml.dist", "phpcs.xml.dist",
"phpstan.neon.dist", "phpstan.neon.dist",
"phpstan-baseline.neon", "phpstan-baseline.neon",
......
Ce diff est replié.
<?php
declare(strict_types=1);
/***************************************************************************\
* SPIP, Système de publication pour l'internet *
* *
* Copyright © avec tendresse depuis 2001 *
* Arnaud Martin, Antoine Pitrou, Philippe Rivière, Emmanuel Saint-James *
* *
* Ce programme est un logiciel libre distribué sous licence GNU/GPL. *
* Pour plus de détails voir le fichier COPYING.txt ou l'aide en ligne. *
\***************************************************************************/
namespace Spip\Test\Action;
use PHPUnit\Framework\TestCase;
class EditerLiensTest extends TestCase
{
public static function setUpBeforeClass(): void
{
include_spip('action/editer_liens');
}
public static function tearDownAfterClass(): void
{
include_spip('base/abstract_sql');
sql_delete('spip_auteurs_liens', "objet='spirou'");
sql_delete('spip_auteurs_liens', "objet='zorglub'");
}
public function testObjetAssociable()
{
$essais = [
[
0 => false,
1 => 'article',
],
[
0 => ['id_auteur', 'spip_auteurs_liens'],
1 => 'auteur',
],
[
0 => ['id_mot', 'spip_mots_liens'],
1 => 'mot',
],
[
0 => ['id_document', 'spip_documents_liens'],
1 => 'document',
],
[
0 => false,
1 => "mot' OR 1=1'",
],
];
foreach ($essais as $k => $essai) {
$expected = array_shift($essai);
$this->assertEquals($expected, objet_associable(...$essai), "Echec {$k} : objet_associable " . end($essai));
}
}
/**
* @depends testObjetAssociable
*/
public function testObjetAssocier()
{
$essais = [
[
0 => false,
1 => [
'article' => 1,
],
2 => [
'spirou' => 1,
],
],
[
0 => 1,
1 => [
'auteur' => 1,
],
2 => [
'spirou' => 1,
],
],
[
0 => 0,
1 => [
'auteur' => 1,
],
2 => [
'spirou' => 1,
],
],
[
0 => 2,
1 => [
'auteur' => 1,
],
2 => [
'spirou' => [2, 3],
],
],
[
0 => 1,
1 => [
'auteur' => 1,
],
2 => [
'spirou' => [2, 3, 4],
],
],
[
10,
[
'auteur' => 1,
],
[
'zorglub' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
],
],
[
6,
[
'auteur' => 1,
],
[
'spirou' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
],
],
];
foreach ($essais as $k => $essai) {
$expected = array_shift($essai);
$this->assertEquals(
$expected,
objet_associer(...$essai),
"Echec {$k} : objet_associer " . json_encode($essai, JSON_THROW_ON_ERROR)
);
}
}
/**
* @depends testObjetAssocier
*/
public function testObjetQualifierLiens()
{
$essais = [
[
0 => false,
1 => [
'article' => 1,
],
2 => [
'zorglub' => 1,
],
3 => [
'vu' => 'oui',
],
],
[
0 => 1,
1 => [
'auteur' => 1,
],
2 => [
'zorglub' => 1,
],
3 => [
'vu' => 'oui',
],
],
[
0 => 1,
1 => [
'auteur' => 1,
],
2 => [
'zorglub' => 1,
],
3 => [
'vu' => 'oui',
],
],
[
0 => false,
1 => [
'auteur' => 1,
],
2 => [
'zorglub' => 1,
],
3 => [
'veraer' => 'oui',
],
],
[
0 => 2,
1 => [
'auteur' => 1,
],
2 => [
'zorglub' => [2, 3],
],
3 => [
'vu' => 'oui',
],
],
];
foreach ($essais as $k => $essai) {
$expected = array_shift($essai);
$this->assertEquals(
$expected,
objet_qualifier_liens(...$essai),
"Echec {$k} : objet_qualifier_liens " . json_encode($essai, JSON_THROW_ON_ERROR)
);
}
}
/**
* @depends testObjetQualifierLiens
*/
public function testObjetDissocier()
{
$essais = [
[
0 => false,
1 => [
'article' => 1,
],
2 => [
'zorglub' => 1,
],
],
[
0 => 1,
1 => [
'auteur' => 1,
],
2 => [
'zorglub' => 1,
],
],
[
0 => 0,
1 => [
'auteur' => 1,
],
2 => [
'zorglub' => 1,
],
],
[
0 => 2,
1 => [
'auteur' => 1,
],
2 => [
'zorglub' => [2, 3],
],
],
[
0 => 1,
1 => [
'auteur' => 1,
],
2 => [
'zorglub' => [2, 3, 4],
],
],
[
0 => 4,
1 => [
'auteur' => 1,
],
2 => [
'zorglub' => [5],
'spirou' => [2, 3, 4],
],
],
[
0 => 12,
1 => [
'auteur' => 1,
],
2 => [
'zorglub' => '*',
'spirou' => '*',
],
],
];
foreach ($essais as $k => $essai) {
$expected = array_shift($essai);
$this->assertEquals(
$expected,
objet_dissocier(...$essai),
"Echec {$k} : objet_dissocier " . json_encode($essai, JSON_THROW_ON_ERROR)
);
}
}
}
<?php
declare(strict_types=1);
namespace Spip\Test\Api;
use PHPUnit\Framework\TestCase;
class AutoriserTest extends TestCase
{
public static function setUpBeforeClass(): void
{
include_spip('inc/autoriser');
require_once(__DIR__ . '/data/autoriser.php');
}
public function testAutoriserOkNiet(): void
{
$this->assertFalse(autoriser('niet'));
$this->assertTrue(autoriser('ok'));
}
public function testAutoriserNouvelleFonction(): void
{
$this->assertTrue(autoriser('chaparder'));
$this->assertFalse(autoriser('paschaparder'));
$this->assertTrue(autoriser('chaparder', 'velo'));
$this->assertTrue(autoriser('velo', 'chaparder'));
$this->assertTrue(autoriser('chaparder', 'carottes'));
$this->assertTrue(autoriser('carottes', 'chaparder'));
}
public function testAutoriserIdentifiant(): void
{
$this->assertFalse(autoriser('unidentifiant'));
$this->assertTrue(autoriser('unidentifiant', '', 1));
$this->assertFalse(autoriser('unidentifiant', '', 2));
}
}
<?php
declare(strict_types=1);
function autoriser_chaparder(string $faire, string $type, $id, array $qui, array $opt): bool
{
return true;
}
function autoriser_paschaparder(string $faire, string $type, $id, array $qui, array $opt): bool
{
return false;
}
function autoriser_chaparder_velo(string $faire, string $type, $id, array $qui, array $opt): bool
{
return true;
}
function autoriser_chaparder_carottes_dist(string $faire, string $type, $id, array $qui, array $opt): bool
{
return false;
}
function autoriser_chaparder_carottes(string $faire, string $type, $id, array $qui, array $opt): bool
{
return true;
}
function autoriser_unidentifiant(string $faire, string $type, $id, array $qui, array $opt): bool
{
return $id === 1;
}
<?php
declare(strict_types=1);
/***************************************************************************\
* SPIP, Système de publication pour l'internet *
* *
* Copyright © avec tendresse depuis 2001 *
* Arnaud Martin, Antoine Pitrou, Philippe Rivière, Emmanuel Saint-James *
* *
* Ce programme est un logiciel libre distribué sous licence GNU/GPL. *
* Pour plus de détails voir le fichier COPYING.txt ou l'aide en ligne. *
\***************************************************************************/
namespace Spip\Test\Config;
use PHPUnit\Framework\TestCase;
class DepotMetaPackTest extends TestCase
{
protected static $savedMeta;
// les bases de test
protected static $assoc;
protected static $serassoc;
public static function setUpBeforeClass(): void
{
self::$savedMeta = $GLOBALS['meta'];
self::$assoc = [
'one' => 'element 1',
'two' => 'element 2',
'three' => [
'un' => 1,
'deux' => 2,
'troisc' => '3',
],
];
self::$serassoc = serialize(self::$assoc);
}
public static function tearDownAfterClass(): void
{
$GLOBALS['meta'] = self::$savedMeta;
}
/**
* lire_config meta
*/
public function testLireConfig1()
{
include_spip('inc/config');
$meta = $GLOBALS['meta'];
// on flingue meta a juste nos donnees
$GLOBALS['meta'] = [
'zero' => serialize(0),
'zeroc' => serialize('0'),
'chaine' => serialize('une chaine'),
'assoc' => serialize(self::$assoc),
'serie' => serialize(self::$serassoc),
];
$essais = [];
$essais[] = [$GLOBALS['meta'], 'metapack::'];
$essais[] = [serialize($GLOBALS['meta']), 'metapack::', '', false];
// racine
$essais[] = [0, 'metapack::zero'];
$essais[] = ['0', 'metapack::zeroc'];
$essais[] = ['une chaine', 'metapack::chaine'];
$essais[] = [self::$assoc, 'metapack::assoc'];
$essais[] = [self::$serassoc, 'metapack::serie'];
$essais[] = [null, 'metapack::rien'];
$essais[] = ['defaut', 'metapack::rien', 'defaut'];
// chemins
$essais[] = [self::$assoc, 'metapack::assoc/'];
$essais[] = ['element 1', 'metapack::assoc/one'];
$essais[] = [[
'un' => 1,
'deux' => 2,
'troisc' => '3',
], 'metapack::assoc/three'];
$essais[] = [1, 'metapack::assoc/three/un'];
$essais[] = ['3', 'metapack::assoc/three/troisc'];
// racourcis
$essais[] = [self::$assoc, 'assoc/'];
$essais[] = ['element 1', 'assoc/one'];
foreach ($essais as $k => $essai) {
$expected = array_shift($essai);
$this->assertEquals($expected, lire_config(...$essai), "Echec {$k} : lecture " . reset($essai));
}
$GLOBALS['meta'] = $meta;
}
/**
* ecrire_config meta
*
* @depends testLireConfig1
*/
public function testEcrireConfig()
{
/*
* Notes sur l'ecriture :
* - dans le tableau $GLOBALS['meta'], les valeurs transmises
* conservent effectivement leur type
* - si l'on applique un lire_metas() (reecriture du tableau $GLOBALS['meta']
* depuis les informations de la table spip_meta, les types de valeurs
* sont tous des types string (puisque la colonne 'valeur' de spip_meta est
* varchar (ou text).
* - 0 devient alors '0'
* - array(xxx) devient 'Array'
*
* Cela ne se produit pas avec le depot 'metapack' qui serialize systematiquement
* tout ce qu'on lui donne (et peut donc restituer le type de donnee correctement).
*
*/
$essais = [];
$essais[] = [true, 'metapack::test_cfg_zero', 0];
$essais[] = [true, 'metapack::test_cfg_zeroc', '0'];
$essais[] = [true, 'metapack::test_cfg_chaine', 'une chaine'];
$essais[] = [true, 'metapack::test_cfg_assoc', self::$assoc];
$essais[] = [true, 'metapack::test_cfg_serie', self::$serassoc];
// chemins
$essais[] = [true, 'metapack::test_cfg_chemin/casier', self::$assoc];
$essais[] = [true, 'metapack::test_cfg_chemin/casier/truc', 'trac'];
foreach ($essais as $k => $essai) {
$expected = array_shift($essai);
$this->assertEquals($expected, ecrire_config(...$essai), "Echec {$k} : ecriture " . reset($essai));
}
}
/**
* re lire_config meta
*
* @depends testEcrireConfig
*/
public function testLireConfig2()
{
$essais = [];
$essais[] = [0, 'metapack::test_cfg_zero'];
$essais[] = ['0', 'metapack::test_cfg_zeroc'];
$essais[] = ['une chaine', 'metapack::test_cfg_chaine'];
$essais[] = [self::$assoc, 'metapack::test_cfg_assoc'];
$essais[] = [self::$serassoc, 'metapack::test_cfg_serie'];
// chemins
$essais[] = [self::$assoc + [
'truc' => 'trac',
], 'metapack::test_cfg_chemin/casier'];
$essais[] = ['trac', 'metapack::test_cfg_chemin/casier/truc'];
$essais[] = [1, 'metapack::test_cfg_chemin/casier/three/un'];
// chemin pas la
$essais[] = [null, 'metapack::test_cfg_chemin/casier/three/huit'];
foreach ($essais as $k => $essai) {
$expected = array_shift($essai);
$this->assertEquals($expected, lire_config(...$essai), "Echec {$k} : lecture " . reset($essai));
}
}
/**
* effacer_config meta
*
* @depends testLireConfig2
*/
public function testEffacerConfig()
{
$essais = [];
$essais[] = [true, 'metapack::test_cfg_zero'];
$essais[] = [true, 'metapack::test_cfg_zeroc'];
$essais[] = [true, 'metapack::test_cfg_chaine'];
$essais[] = [true, 'metapack::test_cfg_assoc'];
$essais[] = [true, 'metapack::test_cfg_serie'];
// chemins
// on enleve finement tout test_cfg_chemin : il ne doit rien rester
$essais[] = [true, 'metapack::test_cfg_chemin/casier/three/huit']; // n'existe pas
$essais[] = [true, 'metapack::test_cfg_chemin/casier/three/troisc'];
$essais[] = [true, 'metapack::test_cfg_chemin/casier/three/deux'];
$essais[] = [true, 'metapack::test_cfg_chemin/casier/three/un']; // supprime three
$essais[] = [true, 'metapack::test_cfg_chemin/casier/one'];
$essais[] = [true, 'metapack::test_cfg_chemin/casier/two'];
$essais[] = [true, 'metapack::test_cfg_chemin/casier/truc']; // supprimer chemin/casier
// on essaye d'effacer une meta qui n'existe pas
$essais[] = [true, 'metapack::test_cfg_dummy/casier/truc'];
foreach ($essais as $k => $essai) {
$expected = array_shift($essai);
$this->assertEquals($expected, effacer_config(...$essai), "Echec {$k} : effacer " . reset($essai));
}
}
/**
* re lire_config meta
*
* @depends testEffacerConfig
*/
public function testLireConfig3()
{
$essais = [];
$essais[] = [null, 'metapack::test_cfg_zero'];
$essais[] = [null, 'metapack::test_cfg_zeroc'];
$essais[] = [null, 'metapack::test_cfg_chaine'];
$essais[] = [null, 'metapack::test_cfg_assoc'];
$essais[] = [null, 'metapack::test_cfg_serie'];
$essais[] = [null, 'metapack::test_cfg_chemin'];
$essais[] = [null, 'metapack::test_cfg_dummy'];
foreach ($essais as $k => $essai) {
$expected = array_shift($essai);
$this->assertEquals($expected, lire_config(...$essai), "Echec {$k} : lecture " . reset($essai));
}
}
}
<?php
declare(strict_types=1);
/***************************************************************************\
* SPIP, Système de publication pour l'internet *
* *
* Copyright © avec tendresse depuis 2001 *
* Arnaud Martin, Antoine Pitrou, Philippe Rivière, Emmanuel Saint-James *
* *
* Ce programme est un logiciel libre distribué sous licence GNU/GPL. *
* Pour plus de détails voir le fichier COPYING.txt ou l'aide en ligne. *
\***************************************************************************/
namespace Spip\Test\Config;
use PHPUnit\Framework\TestCase;
class DepotMetaPersoTest extends TestCase
{
protected static $savedMeta;
// les bases de test
protected static $assoc;
protected static $serassoc;
public static function setUpBeforeClass(): void
{
self::$savedMeta = $GLOBALS['meta'];
self::$assoc = [
'one' => 'element 1',
'two' => 'element 2',
];
self::$serassoc = serialize(self::$assoc);
}
public static function tearDownAfterClass(): void
{
$GLOBALS['meta'] = self::$savedMeta;
unset($GLOBALS['toto']);
}
/**
* lire_config meta
*/
public function testLireConfig1()
{
include_spip('inc/config');
$meta = $GLOBALS['meta'];
$trouver_table = charger_fonction('trouver_table', 'base');
$this->assertArrayNotHasKey('toto', $GLOBALS, 'Une table spip_toto existe deja !');
$this->assertEmpty($trouver_table('spip_toto'), 'Une table spip_toto existe deja !');
// on flingue meta a juste nos donnees
$GLOBALS['meta'] = [
'dummy' => '',
];
$GLOBALS['toto'] = [
'zero' => 0,
'zeroc' => '0',
'chaine' => 'une chaine',
'assoc' => self::$assoc,
'serie' => self::$serassoc,
];
$essais = [];
$essais[] = [0, '/toto/zero'];
$essais[] = ['0', '/toto/zeroc'];
$essais[] = ['une chaine', '/toto/chaine'];
$essais[] = [self::$assoc, '/toto/assoc'];
$essais[] = [self::$assoc, '/toto/serie'];
$essais[] = [self::$serassoc, '/toto/serie', '', 0];
$essais[] = [null, '/toto/rien'];
$essais[] = ['defaut', '/toto/rien', 'defaut'];
$essais[] = [null, '/meta/chaine'];
$essais[] = [null, 'chaine'];
foreach ($essais as $k => $essai) {
$expected = array_shift($essai);
$this->assertEquals($expected, lire_config(...$essai), "Echec {$k} : lecture " . reset($essai));
}
$GLOBALS['meta'] = $meta;
unset($GLOBALS['toto']);
}
/**
* ecrire_config meta
*
* @depends testLireConfig1
*/
public function testEcrireConfig()
{
/*
* Notes sur l'ecriture :
* - dans le tableau $GLOBALS['meta'], les valeurs transmises
* conservent effectivement leur type
* - si l'on applique un lire_metas() (reecriture du tableau $GLOBALS['meta']
* depuis les informations de la table spip_meta, les types de valeurs
* sont tous des types string (puisque la colonne 'valeur' de spip_meta est
* varchar (ou text).
* - 0 devient alors '0'
* - array(xxx) devient 'Array'
*
* Cela ne se produit pas avec le depot 'metapack' qui serialize systematiquement
* tout ce qu'on lui donne (et peut donc restituer le type de donnee correctement).
*
*/
$essais = [];
$essais[] = [true, '/toto/test_cfg_zero', 0];
$essais[] = [true, '/toto/test_cfg_zeroc', '0'];
$essais[] = [true, '/toto/test_cfg_chaine', 'une chaine'];
$essais[] = [true, '/toto/test_cfg_assoc', self::$assoc];
$essais[] = [true, '/toto/test_cfg_serie', self::$serassoc];
foreach ($essais as $k => $essai) {
$expected = array_shift($essai);
$this->assertEquals($expected, ecrire_config(...$essai), "Echec {$k} : ecriture " . reset($essai));
}
$trouver_table = charger_fonction('trouver_table', 'base');
$this->assertNotEmpty($GLOBALS['toto'], "La table spip_toto n'a pas ete cree !");
$this->assertNotEmpty($trouver_table('spip_toto'), "La table spip_toto n'a pas ete cree !");
}
/**
* re lire_config meta
*
* @depends testEcrireConfig
*/
public function testLireConfig2()
{
$essais = [];
$essais[] = [0, '/toto/test_cfg_zero'];
$essais[] = ['0', '/toto/test_cfg_zeroc'];
$essais[] = ['une chaine', '/toto/test_cfg_chaine'];
$essais[] = [self::$assoc, '/toto/test_cfg_assoc'];
$essais[] = [self::$serassoc, '/toto/test_cfg_serie', '', 0];
foreach ($essais as $k => $essai) {
$expected = array_shift($essai);
$this->assertEquals($expected, lire_config(...$essai), "Echec {$k} : lecture " . reset($essai));
}
}
/**
* effacer_config meta
*
* @depends testLireConfig2
*/
public function testEffacerConfig()
{
$essais = [];
$essais[] = [true, '/toto/test_cfg_zero'];
$essais[] = [true, '/toto/test_cfg_zeroc'];
$essais[] = [true, '/toto/test_cfg_chaine'];
$essais[] = [true, '/toto/test_cfg_assoc'];
$essais[] = [true, '/toto/test_cfg_serie'];
foreach ($essais as $k => $essai) {
$expected = array_shift($essai);
$this->assertEquals($expected, effacer_config(...$essai), "Echec {$k} : effacer " . reset($essai));
}
}
/**
* re lire_config meta
*
* @depends testEffacerConfig
*/
public function testLireConfig3()
{
$essais = [];
$essais[] = [null, '/toto/test_cfg_zero'];
$essais[] = [null, '/toto/test_cfg_zeroc'];
$essais[] = [null, '/toto/test_cfg_chaine'];
$essais[] = [null, '/toto/test_cfg_assoc'];
$essais[] = [null, '/toto/test_cfg_serie'];
foreach ($essais as $k => $essai) {
$expected = array_shift($essai);
$this->assertEquals($expected, lire_config(...$essai), "Echec {$k} : lecture " . reset($essai));
}
$trouver_table = charger_fonction('trouver_table', 'base');
$this->assertArrayNotHasKey(
'toto',
$GLOBALS,
"La table spip_toto n'a pas ete supprimee par le dernier effacement de config !"
);
$this->assertEmpty(
$trouver_table('spip_toto'),
"La table spip_toto n'a pas ete supprimee par le dernier effacement de config !"
);
}
}
<?php
declare(strict_types=1);
/***************************************************************************\
* SPIP, Système de publication pour l'internet *
* *
* Copyright © avec tendresse depuis 2001 *
* Arnaud Martin, Antoine Pitrou, Philippe Rivière, Emmanuel Saint-James *
* *
* Ce programme est un logiciel libre distribué sous licence GNU/GPL. *
* Pour plus de détails voir le fichier COPYING.txt ou l'aide en ligne. *
\***************************************************************************/
namespace Spip\Test\Config;
use PHPUnit\Framework\TestCase;
class DepotMetaTest extends TestCase
{
protected static $savedMeta;
// les bases de test
protected static $assoc;
protected static $serassoc;
public static function setUpBeforeClass(): void
{
self::$savedMeta = $GLOBALS['meta'];
self::$assoc = [
'one' => 'element 1',
'two' => 'element 2',
];
self::$serassoc = serialize(self::$assoc);
include_spip('inc/config');
}
public static function tearDownAfterClass(): void
{
$GLOBALS['meta'] = self::$savedMeta;
}
/**
* expliquer_config
*/
public function testExpliquerConfig()
{
$essais = [];
$essais[] = [['meta', null, []], ''];
$essais[] = [['meta', '0', []], '0'];
$essais[] = [['meta', 'casier', []], 'casier'];
$essais[] = [['meta', 'casier', ['sous']], 'casier/sous'];
$essais[] = [['meta', 'casier', ['sous', 'plus', 'bas', 'encore']], 'casier/sous/plus/bas/encore'];
$essais[] = [['meta', null, []], '/meta'];
$essais[] = [['meta', 'casier', []], '/meta/casier'];
$essais[] = [['meta', 'casier', ['sous']], '/meta/casier/sous'];
$essais[] = [['meta', 'casier', ['sous', 'plus', 'bas', 'encore']], '/meta/casier/sous/plus/bas/encore'];
$essais[] = [['toto', null, []], '/toto'];
$essais[] = [['toto', 'casier', []], '/toto/casier'];
$essais[] = [['toto', 'casier', ['sous']], '/toto/casier/sous'];
$essais[] = [['toto', 'casier', ['sous', 'plus', 'bas', 'encore']], '/toto/casier/sous/plus/bas/encore'];
foreach ($essais as $k => $essai) {
$expected = array_shift($essai);
$this->assertEquals($expected, expliquer_config(...$essai), "Echec {$k} : lecture " . end($essai));
}
}
/**
* lire_config meta
*
* @depends testExpliquerConfig
*/
public function testLireConfig1()
{
$meta = $GLOBALS['meta'];
// on flingue meta a juste nos donnees
$GLOBALS['meta'] = [
'zero' => 0,
'zeroc' => '0',
'chaine' => 'une chaine',
'assoc' => self::$assoc,
'serie' => self::$serassoc,
];
$essais = [];
$essais[] = [$GLOBALS['meta'], ''];
$essais[] = [0, 'zero'];
$essais[] = ['0', 'zeroc'];
$essais[] = ['une chaine', 'chaine'];
$essais[] = [self::$assoc, 'assoc'];
$essais[] = [self::$assoc, 'serie'];
$essais[] = [self::$serassoc, 'serie', '', 0];
$essais[] = [null, 'rien'];
$essais[] = ['defaut', 'rien', 'defaut'];
foreach ($essais as $k => $essai) {
$expected = array_shift($essai);
$this->assertEquals($expected, lire_config(...$essai), "Echec {$k} : lecture " . reset($essai));
}
$GLOBALS['meta'] = $meta;
}
/**
* ecrire_config meta
*
* @depends testLireConfig1
*/
public function testEcrireConfig()
{
/*
* Notes sur l'ecriture :
* - dans le tableau $GLOBALS['meta'], les valeurs transmises
* conservent effectivement leur type
* - si l'on applique un lire_metas() (reecriture du tableau $GLOBALS['meta']
* depuis les informations de la table spip_meta, les types de valeurs
* sont tous des types string (puisque la colonne 'valeur' de spip_meta est
* varchar (ou text).
* - 0 devient alors '0'
* - array(xxx) devient 'Array'
*
* Cela ne se produit pas avec le depot 'metapack' qui serialize systematiquement
* tout ce qu'on lui donne (et peut donc restituer le type de donnee correctement).
*
*/
$essais = [];
$essais[] = [true, 'test_cfg_zero', 0];
$essais[] = [true, 'test_cfg_zeroc', '0'];
$essais[] = [true, 'test_cfg_chaine', 'une chaine'];
$essais[] = [true, 'test_cfg_assoc', self::$assoc];
$essais[] = [true, 'test_cfg_serie', self::$serassoc];
foreach ($essais as $k => $essai) {
$expected = array_shift($essai);
$this->assertEquals($expected, ecrire_config(...$essai), "Echec {$k} : ecriture " . reset($essai));
}
}
/**
* re lire_config meta
*
* @depends testEcrireConfig
*/
public function testLireConfig2()
{
$essais = [];
$essais[] = [0, 'test_cfg_zero'];
$essais[] = ['0', 'test_cfg_zeroc'];
$essais[] = ['une chaine', 'test_cfg_chaine'];
$essais[] = [self::$assoc, 'test_cfg_assoc'];
$essais[] = [self::$serassoc, 'test_cfg_serie', '', 0];
foreach ($essais as $k => $essai) {
$expected = array_shift($essai);
$this->assertEquals($expected, lire_config(...$essai), "Echec {$k} : lecture " . reset($essai));
}
}
/**
* effacer_config meta
*
* @depends testLireConfig2
*/
public function testEffacerConfig()
{
$essais = [];
$essais[] = [true, 'test_cfg_zero'];
$essais[] = [true, 'test_cfg_zeroc'];
$essais[] = [true, 'test_cfg_chaine'];
$essais[] = [true, 'test_cfg_assoc'];
$essais[] = [true, 'test_cfg_serie'];
$essais[] = [true, 'test_cfg_dummy'];
foreach ($essais as $k => $essai) {
$expected = array_shift($essai);
$this->assertEquals($expected, effacer_config(...$essai), "Echec {$k} : effacer " . reset($essai));
}
}
/**
* re lire_config meta
*
* @depends testEffacerConfig
*/
public function testLireConfig3()
{
$essais = [];
$essais[] = [null, 'test_cfg_zero'];
$essais[] = [null, 'test_cfg_zeroc'];
$essais[] = [null, 'test_cfg_chaine'];
$essais[] = [null, 'test_cfg_assoc'];
$essais[] = [null, 'test_cfg_serie'];
$essais[] = [null, 'test_cfg_dummy'];
foreach ($essais as $k => $essai) {
$expected = array_shift($essai);
$this->assertEquals($expected, lire_config(...$essai), "Echec {$k} : lecture " . reset($essai));
}
}
}
<?php
declare(strict_types=1);
namespace Spip\Test\Constraint;
use PHPUnit\Framework\Constraint\Constraint;
final class IsOk extends Constraint
{
/**
* Returns a string representation of the constraint.
*/
public function toString(): string
{
return 'is OK';
}
/**
* Evaluates the constraint for parameter $other. Returns true if the constraint is met, false otherwise.
*
* @param mixed $other value or object to evaluate
*/
protected function matches($other): bool
{
return substr(strtolower(trim($other)), 0, 2) === 'ok';
}
/**
* Returns the description of the failure.
*
* The beginning of failure messages is "Failed asserting that" in most cases. This method should return the second
* part of that sentence.
*
* @param mixed $other evaluated value or object
*/
protected function failureDescription($other): string
{
return sprintf('"%s" is OK', $other);
}
}
<?php
declare(strict_types=1);
/**
* Test unitaire de la fonction need_proxy du fichier ./inc/distant.php
*/
namespace Spip\Test\Distant;
use PHPUnit\Framework\TestCase;
class NeedProxyTest extends TestCase
{
public static function setUpBeforeClass(): void
{
find_in_path('./inc/distant.php', '', true);
}
/**
* @dataProvider providerDistantNeedProxy
*/
public function testDistantNeedProxy($expected, ...$args): void
{
$actual = need_proxy(...$args);
$this->assertSame($expected, $actual);
}
public static function providerDistantNeedProxy(): array
{
return [
0 => [
0 => 'http://monproxy.example.org',
1 => 'sous.domaine.spip.net',
2 => 'http://monproxy.example.org',
3 => 'spip.net',
],
1 => [
0 => '',
1 => 'sous.domaine.spip.net',
2 => 'http://monproxy.example.org',
3 => '.spip.net',
],
2 => [
0 => '',
1 => 'sous.domaine.spip.net',
2 => 'http://monproxy.example.org',
3 => '.spip.net
.net',
],
3 => [
0 => '',
1 => 'sous.domaine.spip.net',
2 => 'http://monproxy.example.org',
3 => 'sous.domaine.spip.net',
],
4 => [
0 => 'http://monproxy.example.org',
1 => 'sous.domaine.spip.net',
2 => 'http://monproxy.example.org',
3 => '.sous.domaine.spip.net',
],
];
}
}
<?php
declare(strict_types=1);
/**
* Test unitaire de la fonction url_to_ascii du fichier ./inc/distant.php
*/
namespace Spip\Test\Distant;
use PHPUnit\Framework\TestCase;
class UrlToAsciiTest extends TestCase
{
public static function setUpBeforeClass(): void
{
find_in_path('./inc/distant.php', '', true);
}
/**
* @dataProvider providerDistantUrlToAscii
*/
public function testDistantUrlToAscii($expected, ...$args): void
{
$actual = url_to_ascii(...$args);
$this->assertSame($expected, $actual);
}
public static function providerDistantUrlToAscii(): array
{
return [
0 => [
0 => 'http://www.spip.net/',
1 => 'http://www.spip.net/',
],
1 => [
0 => 'http://www.spip.net/fr_article879.html#BOUCLE-ARTICLES-',
1 => 'http://www.spip.net/fr_article879.html#BOUCLE-ARTICLES-',
],
2 => [
0 => 'http://user:pass@www.spip.net:80/fr_article879.html#BOUCLE-ARTICLES-',
1 => 'http://user:pass@www.spip.net:80/fr_article879.html#BOUCLE-ARTICLES-',
],
3 => [
0 => 'http://www.xn--spap-7pa.net/',
1 => 'http://www.spaïp.net/',
],
4 => [
0 => 'http://www.xn--spap-7pa.net/fr_article879.html#BOUCLE-ARTICLES-',
1 => 'http://www.spaïp.net/fr_article879.html#BOUCLE-ARTICLES-',
],
5 => [
0 => 'http://user:pass@www.xn--spap-7pa.net:80/fr_article879.html#BOUCLE-ARTICLES-',
1 => 'http://user:pass@www.spaïp.net:80/fr_article879.html#BOUCLE-ARTICLES-',
],
];
}
}
<?php
declare(strict_types=1);
/**
* Test unitaire de la fonction valider_url_distante du fichier ./inc/distant.php
*/
namespace Spip\Test\Distant;
use PHPUnit\Framework\TestCase;
class ValiderUrlDistanteTest extends TestCase
{
public static function setUpBeforeClass(): void
{
find_in_path('./inc/distant.php', '', true);
}
/**
* @dataProvider providerDistantValiderUrlDistante
*/
public function testDistantValiderUrlDistante($expected, ...$args): void
{
$actual = valider_url_distante(...$args);
$this->assertSame($expected, $actual);
}
public static function providerDistantValiderUrlDistante(): array
{
return [
0 => [
0 => 'http://www.spip.net',
1 => 'http://www.spip.net',
],
1 => [
0 => 'https://www.spip.net',
1 => 'https://www.spip.net',
],
2 => [
0 => false,
1 => 'ftp://www.spip.net',
],
3 => [
0 => false,
1 => 'http://user@www.spip.net',
],
4 => [
0 => false,
1 => 'https://user:password@www.spip.net',
],
5 => [
0 => false,
1 => 'http://127.0.0.1/munin/graph.png',
],
6 => [
0 => false,
1 => 'http://localhost:8765',
],
7 => [
0 => 'http://localhost:8765/test.png',
1 => 'http://localhost:8765/test.png',
2 => [
0 => 'localhost:8765',
],
],
8 => [
0 => false,
1 => 'http://localhost:9100/test.png',
],
9 => [
0 => false,
1 => 'http://user@password:localhost:8765/test.png',
2 => [
0 => 'localhost:8765',
],
],
10 => [
0 => false,
1 => 'http://user@password:localhost:8765/test.png',
2 => [
0 => 'http://user@password:localhost:8765',
],
],
];
}
}
<?php
declare(strict_types=1);
namespace Spip\Test\Exception;
class TemplateCompilationErrorException extends \Exception
{
public function __construct($message = '', $code = 0, \Throwable $previous = null)
{
$message = sprintf("Compilation error '%s'", $message);
parent::__construct($message, $code, $previous);
}
}
<?php
declare(strict_types=1);
namespace Spip\Test\Exception;
class TemplateNotFoundException extends \Exception
{
public function __construct($message = '', $code = 0, \Throwable $previous = null)
{
$message = sprintf("'%s' template not found", $message);
parent::__construct($message, $code, $previous);
}
}
<?php
declare(strict_types=1);
/**
* Test unitaire de la fonction ajouter_class du fichier ./inc/filtres.php
*/
namespace Spip\Test\Filtre;
use PHPUnit\Framework\TestCase;
class AjouterClassTest extends TestCase
{
public static function setUpBeforeClass(): void
{
find_in_path('./inc/filtres.php', '', true);
}
/**
* @dataProvider providerFiltresAjouterClass
*/
public function testFiltresAjouterClass($expected, ...$args): void
{
$actual = ajouter_class(...$args);
$this->assertSame($expected, $actual);
}
public static function providerFiltresAjouterClass(): array
{
return [
0 => [
0 => "<span class='maclasse maclasse-prefixe suffixe-maclasse maclasse--bem autreclass'>toto</span>",
1 => '<span class="maclasse maclasse-prefixe suffixe-maclasse maclasse--bem">toto</span>',
2 => 'autreclass',
],
1 => [
0 => '<span class="maclasse maclasse-prefixe suffixe-maclasse maclasse--bem">toto</span>',
1 => '<span class="maclasse maclasse-prefixe suffixe-maclasse maclasse--bem">toto</span>',
2 => 'maclasse',
],
2 => [
0 => "<span class='maclasse-prefixe suffixe-maclasse maclasse--bem maclasse'>toto</span>",
1 => '<span class="maclasse-prefixe suffixe-maclasse maclasse--bem">toto</span>',
2 => 'maclasse',
],
3 => [
0 => "<span class='maclasse maclasse-prefixe suffixe-maclasse maclasse--bem maclasse1 maclasse2'>toto</span>",
1 => '<span class="maclasse maclasse-prefixe suffixe-maclasse maclasse--bem">toto</span>',
2 => 'maclasse1 maclasse maclasse2',
],
];
}
}
<?php
declare(strict_types=1);
/**
* Test unitaire de la fonction antispam du fichier inc/filtres.php
*/
namespace Spip\Test\Filtre;
use PHPUnit\Framework\TestCase;
class AntispamTest extends TestCase
{
public static function setUpBeforeClass(): void
{
find_in_path('inc/filtres.php', '', true);
}
public function testFiltresAntispam(): void
{
$actual = antispam('email@domain.tld');
$this->assertStringNotContainsString('@', $actual);
}
}
<?php
declare(strict_types=1);
/**
* Test unitaire de la fonction appliquer_filtre du fichier inc/filtres.php
*/
namespace Spip\Test\Filtre;
use PHPUnit\Framework\TestCase;
class AppliquerFiltreTest extends TestCase
{
public static function setUpBeforeClass(): void
{
find_in_path('inc/filtres.php', '', true);
}
/**
* @dataProvider providerFiltresAppliquerFiltre
*/
public function testFiltresAppliquerFiltre($expected, ...$args): void
{
$actual = appliquer_filtre(...$args);
$this->assertSame($expected, $actual);
}
public static function providerFiltresAppliquerFiltre(): array
{
return [
0 => [
0 => '&lt;&gt;&quot;&#039;&amp;',
1 => '<>"\'&',
2 => 'entites_html',
],
1 => [
0 => '&amp;',
1 => '&amp;',
2 => 'entites_html',
],
];
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter