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\API\Repository\Tests; |
8
|
|
|
|
9
|
|
|
use eZ\Publish\API\Repository\Values\URL\Query\Criterion as Criterion; |
10
|
|
|
use eZ\Publish\API\Repository\Values\URL\URLQuery; |
11
|
|
|
|
12
|
|
|
class URLServiceAuthorizationTest extends BaseURLServiceTest |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Test for the findUrls() method. |
16
|
|
|
* |
17
|
|
|
* @see \eZ\Publish\API\Repository\URLService::findUrls |
18
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
19
|
|
|
*/ |
20
|
|
|
public function testFindUrlsThrowsUnauthorizedException() |
21
|
|
|
{ |
22
|
|
|
$repository = $this->getRepository(); |
23
|
|
|
|
24
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
25
|
|
|
/* BEGIN: Use Case */ |
26
|
|
|
// $anonymousUserId is the ID of the "Anonymous" user in a eZ |
27
|
|
|
// Publish demo installation. |
28
|
|
|
|
29
|
|
|
$userService = $repository->getUserService(); |
30
|
|
|
$urlService = $repository->getURLService(); |
31
|
|
|
|
32
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
33
|
|
|
|
34
|
|
|
$query = new URLQuery(); |
35
|
|
|
$query->filter = new Criterion\MatchAll(); |
36
|
|
|
|
37
|
|
|
// This call will fail with an UnauthorizedException |
38
|
|
|
$urlService->findUrls($query); |
39
|
|
|
/* END: Use Case */ |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Test for the updateUrl() method. |
44
|
|
|
* |
45
|
|
|
* @see \eZ\Publish\API\Repository\URLService::updateUrl |
46
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
47
|
|
|
*/ |
48
|
|
View Code Duplication |
public function testUpdateUrlThrowsUnauthorizedException() |
49
|
|
|
{ |
50
|
|
|
$repository = $this->getRepository(); |
51
|
|
|
|
52
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
53
|
|
|
$urlId = $this->generateId('url', 23); |
54
|
|
|
/* BEGIN: Use Case */ |
55
|
|
|
// $anonymousUserId is the ID of the "Anonymous" user in a eZ |
56
|
|
|
// Publish demo installation. |
57
|
|
|
|
58
|
|
|
$userService = $repository->getUserService(); |
59
|
|
|
$urlService = $repository->getURLService(); |
60
|
|
|
|
61
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
62
|
|
|
|
63
|
|
|
$url = $urlService->loadById($urlId); |
64
|
|
|
$updateStruct = $urlService->createUpdateStruct(); |
65
|
|
|
$updateStruct->url = 'https://vimeo.com/'; |
66
|
|
|
|
67
|
|
|
// This call will fail with an UnauthorizedException |
68
|
|
|
$urlService->updateUrl($url, $updateStruct); |
69
|
|
|
/* END: Use Case */ |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Test for the loadById() method. |
74
|
|
|
* |
75
|
|
|
* @see \eZ\Publish\API\Repository\URLService::loadById |
76
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
77
|
|
|
*/ |
78
|
|
View Code Duplication |
public function testLoadByIdThrowsUnauthorizedException() |
79
|
|
|
{ |
80
|
|
|
$repository = $this->getRepository(); |
81
|
|
|
|
82
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
83
|
|
|
$urlId = $this->generateId('url', 23); |
84
|
|
|
/* BEGIN: Use Case */ |
85
|
|
|
// $anonymousUserId is the ID of the "Anonymous" user in a eZ |
86
|
|
|
// Publish demo installation. |
87
|
|
|
|
88
|
|
|
$userService = $repository->getUserService(); |
89
|
|
|
$urlService = $repository->getURLService(); |
90
|
|
|
|
91
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
92
|
|
|
|
93
|
|
|
// This call will fail with an UnauthorizedException |
94
|
|
|
$urlService->loadById($urlId); |
95
|
|
|
/* END: Use Case */ |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Test for the loadByUrl() method. |
100
|
|
|
* |
101
|
|
|
* @see \eZ\Publish\API\Repository\URLService::loadById |
102
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
103
|
|
|
*/ |
104
|
|
View Code Duplication |
public function testLoadByUrlThrowsUnauthorizedException() |
105
|
|
|
{ |
106
|
|
|
$repository = $this->getRepository(); |
107
|
|
|
|
108
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
109
|
|
|
$url = '/content/view/sitemap/2'; |
110
|
|
|
|
111
|
|
|
/* BEGIN: Use Case */ |
112
|
|
|
// $anonymousUserId is the ID of the "Anonymous" user in a eZ |
113
|
|
|
// Publish demo installation. |
114
|
|
|
|
115
|
|
|
$userService = $repository->getUserService(); |
116
|
|
|
$urlService = $repository->getURLService(); |
117
|
|
|
|
118
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
119
|
|
|
|
120
|
|
|
// This call will fail with an UnauthorizedException |
121
|
|
|
$urlService->loadByUrl($url); |
122
|
|
|
/* END: Use Case */ |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.