214 |
jpm |
1 |
<?php
|
|
|
2 |
require_once dirname(__FILE__).'/../ServicePhpUnit.php';
|
|
|
3 |
|
|
|
4 |
class ParametresTest extends ServicePhpUnit {
|
|
|
5 |
|
215 |
jpm |
6 |
private function initialiser($parametresUrl = array()) {
|
214 |
jpm |
7 |
$bdd = $this->getMock('Bdd');
|
|
|
8 |
|
|
|
9 |
$parametres = new Parametres($parametresUrl, $bdd);
|
215 |
jpm |
10 |
return $parametres;
|
|
|
11 |
}
|
214 |
jpm |
12 |
|
215 |
jpm |
13 |
public function testerParametreParDefaut() {
|
|
|
14 |
$parametres = $this->initialiser();
|
|
|
15 |
|
214 |
jpm |
16 |
$this->assertEquals('stricte', $parametres->get('recherche'));
|
215 |
jpm |
17 |
$this->assertEquals('txt', $parametres->get('ns.format'));
|
|
|
18 |
$this->assertEquals('application/json', $parametres->get('retour'));
|
|
|
19 |
$this->assertEquals('max', $parametres->get('retour.format'));
|
|
|
20 |
$this->assertEquals('fr', $parametres->get('retour.langue'));
|
|
|
21 |
$this->assertEquals('+', $parametres->get('version.projet'));
|
|
|
22 |
$this->assertSame(0, $parametres->get('navigation.depart'));
|
|
|
23 |
$this->assertSame(100, $parametres->get('navigation.limite'));
|
214 |
jpm |
24 |
}
|
|
|
25 |
|
215 |
jpm |
26 |
public function testerExisterRetourneBouleen() {
|
|
|
27 |
$parametresUrl = array('masque.id' => '12,15,18');
|
|
|
28 |
|
|
|
29 |
$parametres = $this->initialiser($parametresUrl);
|
|
|
30 |
|
|
|
31 |
$this->assertTrue($parametres->exister('masque.id'));
|
|
|
32 |
$this->assertFalse($parametres->exister('masque'));
|
|
|
33 |
$this->assertTrue($parametres->exister('recherche'));
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
public function testerGetRetourneValeur() {
|
|
|
37 |
$parametresUrl = array('masque.id' => '12,15,18');
|
|
|
38 |
|
|
|
39 |
$parametres = $this->initialiser($parametresUrl);
|
|
|
40 |
|
|
|
41 |
$this->assertEquals('12,15,18', $parametres->get('masque.id'));
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
public function testerGetListeRetourneTableau() {
|
|
|
45 |
$parametresUrl = array('masque.id' => '12,15,18');
|
|
|
46 |
|
|
|
47 |
$parametres = $this->initialiser($parametresUrl);
|
|
|
48 |
$liste = $parametres->getListe('masque.id');
|
|
|
49 |
|
|
|
50 |
$this->assertTrue(is_array($liste));
|
|
|
51 |
$this->assertCount(3, $liste);
|
|
|
52 |
$this->assertContains(12, $liste);
|
|
|
53 |
$this->assertContains(15, $liste);
|
|
|
54 |
$this->assertContains(18, $liste);
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
public function testerIterateur() {
|
|
|
58 |
$parametresUrl = array('code1' => 'val1', 'code2' => 'val2', 'code3' => 'val3');
|
|
|
59 |
|
|
|
60 |
$parametres = $this->initialiser($parametresUrl);
|
|
|
61 |
|
|
|
62 |
$parametres->rewind();
|
|
|
63 |
$code = $parametres->key();
|
|
|
64 |
$valeur = $parametres->current();
|
|
|
65 |
$this->assertEquals('code1', $code);
|
|
|
66 |
$this->assertEquals('val1', $valeur);
|
|
|
67 |
|
|
|
68 |
$parametres->next();
|
|
|
69 |
$code = $parametres->key();
|
|
|
70 |
$valeur = $parametres->current();
|
|
|
71 |
$this->assertEquals('code2', $code);
|
|
|
72 |
$this->assertEquals('val2', $valeur);
|
|
|
73 |
|
|
|
74 |
$parametres->next();
|
|
|
75 |
$code = $parametres->key();
|
|
|
76 |
$valeur = $parametres->current();
|
|
|
77 |
$this->assertEquals('code3', $code);
|
|
|
78 |
$this->assertEquals('val3', $valeur);
|
|
|
79 |
|
|
|
80 |
$parametres->next();
|
|
|
81 |
$this->assertFalse($parametres->valid());
|
|
|
82 |
|
|
|
83 |
$parametres->rewind();
|
|
|
84 |
$this->assertTrue($parametres->valid());
|
|
|
85 |
$code = $parametres->key();
|
|
|
86 |
$this->assertEquals('code1', $code);
|
|
|
87 |
}
|
|
|
88 |
|
214 |
jpm |
89 |
}
|