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\Bundle\EzPublishRestBundle\Tests\Functional; |
10
|
|
|
|
11
|
|
|
use eZ\Bundle\EzPublishRestBundle\Tests\Functional\TestCase as RESTFunctionalTestCase; |
12
|
|
|
use Symfony\Component\HttpFoundation\Response; |
13
|
|
|
|
14
|
|
|
class BookmarkTest extends RESTFunctionalTestCase |
15
|
|
|
{ |
16
|
|
|
public function testCreateBookmark(): int |
17
|
|
|
{ |
18
|
|
|
$content = $this->createFolder(__FUNCTION__, '/api/ezp/v2/content/locations/1/2'); |
19
|
|
|
$contentLocations = $this->getContentLocations($content['_href']); |
20
|
|
|
|
21
|
|
|
$locationPathParts = explode('/', $contentLocations['LocationList']['Location'][0]['_href']); |
22
|
|
|
$locationId = (int) array_pop($locationPathParts); |
23
|
|
|
|
24
|
|
|
$request = $this->createHttpRequest( |
25
|
|
|
'POST', '/api/ezp/v2/bookmark/' . $locationId |
26
|
|
|
); |
27
|
|
|
|
28
|
|
|
$response = $this->sendHttpRequest($request); |
29
|
|
|
|
30
|
|
|
self::assertHttpResponseCodeEquals($response, Response::HTTP_CREATED); |
31
|
|
|
|
32
|
|
|
return $locationId; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @depends testCreateBookmark |
37
|
|
|
*/ |
38
|
|
View Code Duplication |
public function testCreateBookmarkIfAlreadyExists(int $locationId): void |
39
|
|
|
{ |
40
|
|
|
$request = $this->createHttpRequest( |
41
|
|
|
'POST', '/api/ezp/v2/bookmark/' . $locationId |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
$response = $this->sendHttpRequest($request); |
45
|
|
|
|
46
|
|
|
self::assertHttpResponseCodeEquals($response, Response::HTTP_CONFLICT); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @depends testCreateBookmark |
51
|
|
|
*/ |
52
|
|
View Code Duplication |
public function testIsBookmarked(int $locationId): void |
53
|
|
|
{ |
54
|
|
|
$request = $this->createHttpRequest( |
55
|
|
|
'HEAD', '/api/ezp/v2/bookmark/' . $locationId |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
$response = $this->sendHttpRequest($request); |
59
|
|
|
|
60
|
|
|
self::assertHttpResponseCodeEquals($response, Response::HTTP_OK); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
View Code Duplication |
public function testIsBookmarkedReturnsNotFound(): void |
64
|
|
|
{ |
65
|
|
|
$locationId = 43; |
66
|
|
|
|
67
|
|
|
$request = $this->createHttpRequest( |
68
|
|
|
'HEAD', '/api/ezp/v2/bookmark/' . $locationId |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
$response = $this->sendHttpRequest($request); |
72
|
|
|
|
73
|
|
|
self::assertHttpResponseCodeEquals($response, Response::HTTP_NOT_FOUND); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @depends testCreateBookmark |
78
|
|
|
*/ |
79
|
|
View Code Duplication |
public function testDeleteBookmark(int $locationId): void |
80
|
|
|
{ |
81
|
|
|
$request = $this->createHttpRequest( |
82
|
|
|
'DELETE', '/api/ezp/v2/bookmark/' . $locationId |
83
|
|
|
); |
84
|
|
|
|
85
|
|
|
$response = $this->sendHttpRequest($request); |
86
|
|
|
|
87
|
|
|
self::assertHttpResponseCodeEquals($response, Response::HTTP_NO_CONTENT); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
View Code Duplication |
public function testLoadBookmarks(): void |
91
|
|
|
{ |
92
|
|
|
$request = $this->createHttpRequest( |
93
|
|
|
'GET', |
94
|
|
|
'/api/ezp/v2/bookmark?offset=1&limit=100', |
95
|
|
|
'BookmarkList+xml', |
96
|
|
|
'BookmarkList+xml' |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
$response = $this->sendHttpRequest($request); |
100
|
|
|
|
101
|
|
|
self::assertHttpResponseCodeEquals($response, Response::HTTP_OK); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
View Code Duplication |
public function testDeleteBookmarkReturnNotFound(): void |
105
|
|
|
{ |
106
|
|
|
$locationId = 43; |
107
|
|
|
|
108
|
|
|
$request = $this->createHttpRequest( |
109
|
|
|
'DELETE', '/api/ezp/v2/bookmark/' . $locationId |
110
|
|
|
); |
111
|
|
|
|
112
|
|
|
$response = $this->sendHttpRequest($request); |
113
|
|
|
|
114
|
|
|
self::assertHttpResponseCodeEquals($response, Response::HTTP_NOT_FOUND); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|