Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 137 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
137 jpm 1
<?php
2
require dirname(__FILE__).'/../../bibliotheque/Surligneur.php';
3
 
4
class SurligneurTest extends PHPUnit_Framework_TestCase {
5
 
6
	/**
7
	* @expectedException        InvalidArgumentException
8
	* @expectedExceptionMessage Surligneur::surlignerMots() n'accepte que les tableaux de mots en argument
9
	*/
10
	public function testerSurlignerMotsAvecChaineRetourneInvalidArgumentException() {
11
		$surligneur = new Surligneur();
12
		$surligneur->surlignerMots('test');
13
	}
14
 
15
	/**
16
	* @expectedException        LengthException
17
	* @expectedExceptionMessage Surligneur::surlignerMots() n'accepte que des tableaux contenant au moins un mot
18
	*/
19
	public function testerSurlignerMotsAvecTableauVideRetourneLengthException() {
20
		$surligneur = new Surligneur();
21
		$surligneur->surlignerMots(array());
22
	}
23
 
24
	public function testerSurlignerMotsRetournePremiereOccurenceMotSurlignee() {
25
		$surligneur = new Surligneur();
26
		$surligneur->setTexte('Viola alba subsp. alba');
27
		$txtSurligne = $surligneur->surlignerMots(array('viola', 'al'));
28
 
29
		$txtSurligneAttendu = '<span class="surlignage">Viola</span> <span class="surlignage">al</span>ba subsp. alba';
30
		$this->assertEquals($txtSurligneAttendu, $txtSurligne);
31
	}
32
 
33
	public function testerSurlignerMotsRetourneDeuxPremieresOccurencesMotSurlignees() {
34
		$surligneur = new Surligneur();
35
		$surligneur->setNbreMaxSurlignageParMot(2);
36
		$surligneur->setTexte('Viola alba subsp. alba');
37
 
38
		$txtSurligne = $surligneur->surlignerMots(array('viola', 'al'));
39
 
40
		$txtSurligneAttendu = '<span class="surlignage">Viola</span> <span class="surlignage">al</span>ba subsp. <span class="surlignage">al</span>ba';
41
		$this->assertEquals($txtSurligneAttendu, $txtSurligne);
42
	}
43
 
44
	public function testerSurlignerMotsParConstructeurRetourneDeuxPremieresOccurencesMotSurlignees() {
45
		$surligneur = new Surligneur('Viola alba subsp. alba', 2);
46
 
47
		$txtSurligne = $surligneur->surlignerMots(array('viola', 'al'));
48
 
49
		$txtSurligneAttendu = '<span class="surlignage">Viola</span> <span class="surlignage">al</span>ba subsp. <span class="surlignage">al</span>ba';
50
		$this->assertEquals($txtSurligneAttendu, $txtSurligne);
51
	}
52
}
53
?>