|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Cp\Parser; |
|
4
|
|
|
|
|
5
|
|
|
use Cp\Parser\PlanParser; |
|
6
|
|
|
use PHPHtmlParser\Dom; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class PlanParserTest |
|
10
|
|
|
*/ |
|
11
|
|
|
class PlanParserTest extends \PHPUnit_Framework_TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Test parse html to json object |
|
15
|
|
|
*/ |
|
16
|
|
|
public function testParseToJson() |
|
17
|
|
|
{ |
|
18
|
|
|
$url = __DIR__.'/../../fixtures/html/Plan-10km-3-seances-6semaines.htm'; |
|
19
|
|
|
$planParser = new PlanParser(new Dom()); |
|
20
|
|
|
|
|
21
|
|
|
$expected = [ |
|
22
|
|
|
'name' => 'Plans entrainement 10 km en 50 / 55 minutes', |
|
23
|
|
|
'type' => 'Plan 10 km avec 3 séances / 6 semaines', |
|
24
|
|
|
'weeks' => [ |
|
25
|
|
|
[ |
|
26
|
|
|
'name' => 'Semaine 1', |
|
27
|
|
|
'trainings' => [ |
|
28
|
|
|
[ |
|
29
|
|
|
'type' => 'EF', |
|
30
|
|
|
'content' => 'Footing de 45 minutes', |
|
31
|
|
|
], |
|
32
|
|
|
[ |
|
33
|
|
|
'type' => 'VMA-105', |
|
34
|
|
|
'content' => 'Footing de 20-30 minutes suivi de 2 séries de 30"-30" à 100-105%VMA avec 3 minutes de récupération entre chaque série.', |
|
35
|
|
|
], |
|
36
|
|
|
[ |
|
37
|
|
|
'type' => 'SL-80/85', |
|
38
|
|
|
'content' => 'Sortie longue de 1h20 dont 2 fois 10minutes à 80-85%FCM avec une récupération de 2 minutes entre chaque effort', |
|
39
|
|
|
], |
|
40
|
|
|
], |
|
41
|
|
|
], |
|
42
|
|
|
], |
|
43
|
|
|
]; |
|
44
|
|
|
|
|
45
|
|
|
$this->assertEquals(json_encode($expected), $planParser->parseToJson($url)); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @expectedException \Exception |
|
50
|
|
|
*/ |
|
51
|
|
|
public function testParseToJsonWithException() |
|
52
|
|
|
{ |
|
53
|
|
|
$url = __DIR__.'/../../fixtures/html/wrong-page.htm'; |
|
54
|
|
|
$planParser = new PlanParser(new Dom()); |
|
55
|
|
|
|
|
56
|
|
|
$planParser->parseToJson($url); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Test to parse plan on Html |
|
61
|
|
|
*/ |
|
62
|
|
|
public function testParseToHtml() |
|
63
|
|
|
{ |
|
64
|
|
|
$url = __DIR__.'/../../fixtures/html/Plan-10km-3-seances-6semaines.htm'; |
|
65
|
|
|
$planParser = new PlanParser(new Dom()); |
|
66
|
|
|
|
|
67
|
|
|
$htmlContent = '<table> |
|
68
|
|
|
<thead> |
|
69
|
|
|
<tr> |
|
70
|
|
|
<td> </td> |
|
71
|
|
|
<td class="semaine">Semaine 1</td> |
|
72
|
|
|
</tr> |
|
73
|
|
|
</thead> |
|
74
|
|
|
<tbody> |
|
75
|
|
|
<tr> |
|
76
|
|
|
<td class="fonce">EF</td> |
|
77
|
|
|
<td>Footing de <strong>45 minutes</strong></td> |
|
78
|
|
|
</tr> |
|
79
|
|
|
<tr> |
|
80
|
|
|
<td class="fonce">VMA-105</td> |
|
81
|
|
|
<td>Footing de 20-30 minutes suivi de <strong>2 séries de 30"-30" à 100-105%VMA</strong> avec 3 minutes de récupération entre chaque série.</td> |
|
82
|
|
|
</tr> |
|
83
|
|
|
<tr> |
|
84
|
|
|
<td class="fonce">SL-80/85</td> |
|
85
|
|
|
<td>Sortie longue de <strong>1h20</strong> dont <strong>2 fois 10minutes à 80-85%FCM</strong> avec une récupération de 2 minutes entre chaque effort</td> |
|
86
|
|
|
</tr> |
|
87
|
|
|
</tbody> |
|
88
|
|
|
</table>'; |
|
89
|
|
|
|
|
90
|
|
|
$expected = preg_replace('/>([\t|\s]+)</', '><', $htmlContent); |
|
91
|
|
|
$actual = preg_replace('/>([\t|\s]+)</', '><', $planParser->parseToHtml($url)); |
|
92
|
|
|
|
|
93
|
|
|
$this->assertEquals($expected, $actual); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|