|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace eZ\Publish\Core\Persistence\Legacy\Tests\URL; |
|
8
|
|
|
|
|
9
|
|
|
use eZ\Publish\Core\Persistence\Legacy\URL\Mapper; |
|
10
|
|
|
use eZ\Publish\SPI\Persistence\URL\URL; |
|
11
|
|
|
use eZ\Publish\SPI\Persistence\URL\URLUpdateStruct; |
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
|
13
|
|
|
|
|
14
|
|
|
class MapperTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\URL\Mapper |
|
18
|
|
|
*/ |
|
19
|
|
|
private $mapper; |
|
20
|
|
|
|
|
21
|
|
|
protected function setUp() |
|
22
|
|
|
{ |
|
23
|
|
|
parent::setUp(); |
|
24
|
|
|
$this->mapper = new Mapper(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testCreateURLFromUpdateStruct() |
|
28
|
|
|
{ |
|
29
|
|
|
$urlUpdateStruct = new URLUpdateStruct(); |
|
30
|
|
|
$urlUpdateStruct->url = 'https://ez.no'; |
|
31
|
|
|
$urlUpdateStruct->isValid = true; |
|
32
|
|
|
$urlUpdateStruct->lastChecked = 0; |
|
33
|
|
|
$urlUpdateStruct->modified = time(); |
|
34
|
|
|
|
|
35
|
|
|
$expected = new URL(); |
|
36
|
|
|
$expected->url = $urlUpdateStruct->url; |
|
37
|
|
|
$expected->originalUrlMd5 = md5($urlUpdateStruct->url); |
|
38
|
|
|
$expected->isValid = $urlUpdateStruct->isValid; |
|
39
|
|
|
$expected->lastChecked = $urlUpdateStruct->lastChecked; |
|
40
|
|
|
$expected->created = 0; |
|
41
|
|
|
$expected->modified = $urlUpdateStruct->modified; |
|
42
|
|
|
|
|
43
|
|
|
$this->assertEquals($expected, $this->mapper->createURLFromUpdateStruct($urlUpdateStruct)); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testExtractURLsFromRows() |
|
47
|
|
|
{ |
|
48
|
|
|
$rows = [ |
|
49
|
|
|
[ |
|
50
|
|
|
'id' => 12, |
|
51
|
|
|
'url' => 'https://ez.no', |
|
52
|
|
|
'original_url_md5' => 'd74110041197e107722d8821f5f4d89c', |
|
53
|
|
|
'is_valid' => 0, |
|
54
|
|
|
'last_checked' => 0, |
|
55
|
|
|
'created' => 1510770207, |
|
56
|
|
|
'modified' => 0, |
|
57
|
|
|
], |
|
58
|
|
|
[ |
|
59
|
|
|
'id' => 52, |
|
60
|
|
|
'url' => 'https://ezplatform.com', |
|
61
|
|
|
'original_url_md5' => '59697373afe0a059dc424ea2fc6946d5', |
|
62
|
|
|
'is_valid' => 1, |
|
63
|
|
|
'last_checked' => 0, |
|
64
|
|
|
'created' => 1510770293, |
|
65
|
|
|
'modified' => 0, |
|
66
|
|
|
], |
|
67
|
|
|
]; |
|
68
|
|
|
|
|
69
|
|
|
$urlEzNo = new URL(); |
|
70
|
|
|
$urlEzNo->id = (int)$rows[0]['id']; |
|
71
|
|
|
$urlEzNo->url = $rows[0]['url']; |
|
72
|
|
|
$urlEzNo->originalUrlMd5 = $rows[0]['original_url_md5']; |
|
73
|
|
|
$urlEzNo->isValid = (bool)$rows[0]['is_valid']; |
|
74
|
|
|
$urlEzNo->lastChecked = (int)$rows[0]['last_checked']; |
|
75
|
|
|
$urlEzNo->created = (int)$rows[0]['created']; |
|
76
|
|
|
$urlEzNo->modified = (int)$rows[0]['modified']; |
|
77
|
|
|
|
|
78
|
|
|
$urlEzplatformCom = new URL(); |
|
79
|
|
|
$urlEzplatformCom->id = (int)$rows[1]['id']; |
|
80
|
|
|
$urlEzplatformCom->url = $rows[1]['url']; |
|
81
|
|
|
$urlEzplatformCom->originalUrlMd5 = $rows[1]['original_url_md5']; |
|
82
|
|
|
$urlEzplatformCom->isValid = (bool)$rows[1]['is_valid']; |
|
83
|
|
|
$urlEzplatformCom->lastChecked = (int)$rows[1]['last_checked']; |
|
84
|
|
|
$urlEzplatformCom->created = (int)$rows[1]['created']; |
|
85
|
|
|
$urlEzplatformCom->modified = (int)$rows[1]['modified']; |
|
86
|
|
|
|
|
87
|
|
|
$this->assertEquals([$urlEzNo, $urlEzplatformCom], $this->mapper->extractURLsFromRows($rows)); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|