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
|
|
|
declare(strict_types=1); |
8
|
|
|
|
9
|
|
|
namespace eZ\Publish\Core\REST\Server\Tests\Output\ValueObjectVisitor; |
10
|
|
|
|
11
|
|
|
use DOMDocument; |
12
|
|
|
use DOMXPath; |
13
|
|
|
use eZ\Publish\API\Repository\Values\Content\Location; |
14
|
|
|
use eZ\Publish\Core\REST\Common\Tests\Output\ValueObjectVisitorBaseTest; |
15
|
|
|
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor; |
16
|
|
|
use eZ\Publish\Core\REST\Server\Values\BookmarkList; |
17
|
|
|
use eZ\Publish\Core\REST\Server\Values\RestLocation; |
18
|
|
|
|
19
|
|
|
class BookmarkListTest extends ValueObjectVisitorBaseTest |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var \eZ\Publish\Core\REST\Server\Values\BookmarkList |
23
|
|
|
*/ |
24
|
|
|
private $data; |
|
|
|
|
25
|
|
|
|
26
|
|
|
protected function setUp() |
27
|
|
|
{ |
28
|
|
|
$this->data = new BookmarkList(10, [ |
29
|
|
|
new RestLocation($this->createMock(Location::class), 0), |
30
|
|
|
new RestLocation($this->createMock(Location::class), 0), |
31
|
|
|
new RestLocation($this->createMock(Location::class), 0), |
32
|
|
|
]); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
View Code Duplication |
public function testVisit(): string |
36
|
|
|
{ |
37
|
|
|
$visitor = $this->getVisitor(); |
38
|
|
|
$generator = $this->getGenerator(); |
39
|
|
|
|
40
|
|
|
$generator->startDocument(null); |
41
|
|
|
|
42
|
|
|
$visitor->visit( |
43
|
|
|
$this->getVisitorMock(), |
|
|
|
|
44
|
|
|
$generator, |
45
|
|
|
$this->data |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$result = $generator->endDocument(null); |
49
|
|
|
|
50
|
|
|
$this->assertNotNull($result); |
51
|
|
|
|
52
|
|
|
return $result; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @depends testVisit |
57
|
|
|
*/ |
58
|
|
|
public function testResultContainsBookmarkListElement(string $result): void |
59
|
|
|
{ |
60
|
|
|
$this->assertXMLTag( |
61
|
|
|
[ |
62
|
|
|
'tag' => 'BookmarkList', |
63
|
|
|
'attributes' => [ |
64
|
|
|
'media-type' => 'application/vnd.ez.api.BookmarkList+xml', |
65
|
|
|
], |
66
|
|
|
], |
67
|
|
|
$result, |
68
|
|
|
'Invalid <BookmarkList> attributes.' |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @depends testVisit |
74
|
|
|
*/ |
75
|
|
|
public function testResultContainsCountElement(string $result): void |
76
|
|
|
{ |
77
|
|
|
$this->assertXMLTag( |
78
|
|
|
[ |
79
|
|
|
'tag' => 'count', |
80
|
|
|
'content' => $this->data->totalCount, |
81
|
|
|
], |
82
|
|
|
$result |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @depends testVisit |
88
|
|
|
*/ |
89
|
|
|
public function testResultContainsBookmarkElement(string $result): void |
90
|
|
|
{ |
91
|
|
|
$query = "//BookmarkList/Bookmark[@media-type='application/vnd.ez.api.Bookmark+xml']"; |
92
|
|
|
|
93
|
|
|
$document = new DOMDocument(); |
94
|
|
|
$document->loadXML($result); |
95
|
|
|
$xpath = new DOMXPath($document); |
96
|
|
|
|
97
|
|
|
$this->assertEquals(count($this->data->items), $xpath->query($query)->length); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* {@inheritdoc} |
102
|
|
|
*/ |
103
|
|
|
protected function internalGetVisitor() |
104
|
|
|
{ |
105
|
|
|
return new ValueObjectVisitor\BookmarkList(); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|