|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sportic\Timing\RaceTecClient\Tests\Parsers; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use Sportic\Timing\RaceTecClient\Models\Result; |
|
7
|
|
|
use Sportic\Timing\RaceTecClient\Scrapers\EventPage as EventPageScraper; |
|
8
|
|
|
use Sportic\Timing\RaceTecClient\Parsers\EventPage as EventPageParser; |
|
9
|
|
|
use Symfony\Component\DomCrawler\Crawler; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class EventPageTest |
|
13
|
|
|
* @package Sportic\Timing\RaceTecClient\Tests\Scrapers |
|
14
|
|
|
*/ |
|
15
|
|
|
class EventPageTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
protected static $parameters; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var EventPageParser |
|
21
|
|
|
*/ |
|
22
|
|
|
protected static $parser; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var array |
|
26
|
|
|
*/ |
|
27
|
|
|
protected static $parametersParsed; |
|
28
|
|
|
|
|
29
|
|
|
public function testGenerateContentRaces() |
|
30
|
|
|
{ |
|
31
|
|
|
self::assertCount(5, self::$parametersParsed['races']); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testGenerateContentResultHeader() |
|
35
|
|
|
{ |
|
36
|
|
|
self::assertCount(8, self::$parametersParsed['results']['header']); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testGenerateContentResultList() |
|
40
|
|
|
{ |
|
41
|
|
|
self::assertCount(50, self::$parametersParsed['results']['list']); |
|
42
|
|
|
self::assertInstanceOf(Result::class, self::$parametersParsed['results']['list'][5]); |
|
43
|
|
|
self::assertEquals( |
|
44
|
|
|
[ |
|
45
|
|
|
'posGen' => '6', |
|
46
|
|
|
'bib' => '247', |
|
47
|
|
|
'fullName' => 'Sorin Boriceanu', |
|
48
|
|
|
'href' => 'MyResults.aspx?uid=16648-2091-1-29984', |
|
49
|
|
|
'time' => '02:04:16', |
|
50
|
|
|
'category' => 'Masculin 35-39', |
|
51
|
|
|
'posCategory' => '3', |
|
52
|
|
|
'gender' => 'Male', |
|
53
|
|
|
'posGender' => '6', |
|
54
|
|
|
], |
|
55
|
|
|
self::$parametersParsed['results']['list'][5]->__toArray() |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testGenerateContentResultPagination() |
|
60
|
|
|
{ |
|
61
|
|
|
self::assertEquals( |
|
62
|
|
|
[ |
|
63
|
|
|
'current' => 1, |
|
64
|
|
|
'all' => 5, |
|
65
|
|
|
'items' => 222, |
|
66
|
|
|
], |
|
67
|
|
|
self::$parametersParsed['results']['pagination'] |
|
68
|
|
|
); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testGenerateContentAll() |
|
72
|
|
|
{ |
|
73
|
|
|
self::assertEquals(self::$parameters, self::$parametersParsed); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
View Code Duplication |
public static function setUpBeforeClass() |
|
|
|
|
|
|
77
|
|
|
{ |
|
78
|
|
|
self::$parameters = unserialize( |
|
79
|
|
|
file_get_contents(TEST_FIXTURE_PATH . DS . 'Parsers' . DS . 'event_page.serialized') |
|
80
|
|
|
); |
|
81
|
|
|
|
|
82
|
|
|
$scrapper = new EventPageScraper('16648', '2091', '1'); |
|
83
|
|
|
|
|
84
|
|
|
$crawler = new Crawler(null, $scrapper->getCrawlerUri()); |
|
85
|
|
|
$crawler->addContent( |
|
86
|
|
|
file_get_contents( |
|
87
|
|
|
TEST_FIXTURE_PATH . DS . 'Parsers' . DS . 'event_page.html' |
|
88
|
|
|
), |
|
89
|
|
|
'text/html;charset=utf-8' |
|
90
|
|
|
); |
|
91
|
|
|
|
|
92
|
|
|
self::$parser = new EventPageParser(); |
|
93
|
|
|
self::$parser->setScraper($scrapper); |
|
94
|
|
|
self::$parser->setCrawler($crawler); |
|
95
|
|
|
|
|
96
|
|
|
self::$parametersParsed = self::$parser->getContent(); |
|
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
// file_put_contents( |
|
99
|
|
|
// TEST_FIXTURE_PATH . DS . 'Parsers' . DS . 'event_page.serialized', |
|
100
|
|
|
// serialize(self::$parametersParsed) |
|
101
|
|
|
// ); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.