diff --git a/doc/specifications/proposed/rest_resource_embedding.md b/doc/specifications/proposed/rest_resource_embedding.md
new file mode 100644
index 00000000000..677c732ebc7
--- /dev/null
+++ b/doc/specifications/proposed/rest_resource_embedding.md
@@ -0,0 +1,185 @@
+# REST resource embedding
+
+Rest embedding allows an API consumer to request references from the
+response to be embedded, in order to avoid extra REST calls.
+
+## Example
+
+A location response contains a reference to the content item's main location:
+
+```
+curl -X GET http://localhost:8000/api/ezp/v2/content/objects/1
+```
+
+```xml
+
+
+
+ eZ Platform
+
+
+
+
+
+
+ 2015-11-30T13:10:46+00:00
+ 2015-11-30T13:10:46+00:00
+ eng-GB
+ 9
+ true
+
+
+```
+
+By adding an `X-eZ-Embed-Value` header to the request, we can get the
+main location object embedded into the response:
+
+```
+curl -X GET http://localhost:8000/api/ezp/v2/content/objects/1 -H 'x-ez-embed-value: Content.MainLocation'
+```
+
+```xml
+
+
+
+ eZ Platform
+
+
+
+
+ 2
+ 0
+ false
+ false
+
+ /1/2/
+ 1
+ 8
+ f3e90596361e31d496d4026eb624c983
+
+
+ PRIORITY
+ ASC
+
+
+
+
+
+ 2015-11-30T13:10:46+00:00
+ 2015-11-30T13:10:46+00:00
+ eng-GB
+ 9
+ true
+
+
+```
+
+### The `X-eZ-Embed-Value` request header
+
+Which resources must be embedded is specified using this request header.
+It accepts several resources separated by commas:
+
+`X-eZ-Embed-Value: Content.MainLocation,Content.Owner.Groups`
+
+A resource is referenced by its "path" from the root of the response.
+Resources from an embedded resource can also be embedded:
+
+- `Content.MainLocation`
+- `Content.ContentType`
+- `Content.Owner.Groups`
+
+### Permissions
+If the user doesn't have the required permissions to load an embedded
+object, the response will be untouched, and no error will be thrown.
+
+### HTTP Caching
+Responses will vary based on the embedded responses.
+
+Thanks to HTTP cache multi-tagging, customized responses will expire as
+expected: each embedded object will tag the response with the HTTP cache
+tags it requires.
+
+### Implementation
+
+#### Resource links generation in value object visitors
+Value object visitors don't use the router directly anymore to generate
+links to resources. Instead, they build and visit a `ResourceRouteReference`
+object with the name of the route and the route's parameters:
+
+```php
+class LocationValueObjectVisitor extends ValueObjectVisitor
+{
+ public function visit($generator, $visitor, $location)
+ {
+ // ...
+
+ $generator->startObjectElement$generator->startObjectElement('Content');
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
+ 'ezpublish_rest_loadContent',
+ ['contentId' => $location->contentInfo->contentId]
+ );
+ $generator->endObjectElement('Content');
+ }
+}
+```
+
+#### The `ResourceRouteReference` value object visitor
+This object's visitor extends the `RestResourceLink` visitor.
+
+It uses the router to generate a link based on the `RestResourceLink`
+properties, and invokes the parent's `visit()` method.
+
+#### The `RestResourceLink` value object visitor
+It first generate an `href` attribute, respecting the REST output that
+existed before this feature.
+
+It then uses a `PathExpansionChecker` to test if the current generator path,
+returned by the `Generator::getStackPath()` method, is requested for expansion.
+A `RequestHeaderPathExpansionChecker` uses the request to test if expansion
+is needed.
+
+If it is, a `ValueReferenceLoader` loads the referenced
+value object. The returned value object it is visited and added to generated
+output, inside the current object element.
+
+#### The `ExpansionGenerator`
+The `RestResourceLink` visitor passes an `ExpansionGenerator` when visiting
+the loaded value object.
+
+This OutputGenerator decorates the actual (XML or JSON) generator. It will
+skip the first objectElement and its attributes generated for the embedded
+object, in order to avoid duplicate nodes. In the example above, the `LocationList`
+object is skipped:
+
+```
+
+
+
+
+
+
+
+
+
+
+```
+
+### Loading of references
+References are loaded by the `ControllerUriValueLoader`. Given a REST
+resource URI (`/api/ezp/v2/content/objects/1`), it will determine and call
+the REST controller action for that URI.
+
+This implementation ensures that any REST resource that has a controller
+can be embedded without requiring any extra development.
+
+Resources that have multiple representations, such as Content/ContentInfo,
+will use the optional media-type from the RestResourceReference to embed
+the expected representation.
+
+### HTTP caching
+- Requires HTTP cache multi-tagging
+- Response must vary on `x-ez-embed-value`
+- Response must be tagged with all of the included items
+ Since the controllers are used to expand objects, the required cache
+ headers should be included automatically (to check)
diff --git a/eZ/Bundle/EzPublishRestBundle/Resources/config/services.yml b/eZ/Bundle/EzPublishRestBundle/Resources/config/services.yml
index 53ace6f9069..0358194ec22 100644
--- a/eZ/Bundle/EzPublishRestBundle/Resources/config/services.yml
+++ b/eZ/Bundle/EzPublishRestBundle/Resources/config/services.yml
@@ -335,6 +335,7 @@ services:
arguments:
- "@ezpublish_rest.output.generator.json"
- "@ezpublish_rest.output.value_object_visitor.dispatcher"
+ - "@router"
tags:
- { name: ezpublish_rest.output.visitor, regexps: ezpublish_rest.output.visitor.json.regexps }
@@ -403,3 +404,14 @@ services:
parent: hautelook.router.template
calls:
- [ setOption, [ strict_requirements, ~ ] ]
+
+ ezpublish_rest.controller_uri_value_loader:
+ class: eZ\Publish\Core\REST\Server\Output\PathExpansion\ValueLoaders\ControllerUriValueLoader
+ arguments:
+ - '@router'
+ - '@controller_resolver'
+
+ ezpublish_rest.unique_controller_uri_value_loader:
+ class: eZ\Publish\Core\REST\Server\Output\PathExpansion\ValueLoaders\UniqueUriValueLoader
+ arguments:
+ - '@ezpublish_rest.controller_uri_value_loader'
diff --git a/eZ/Bundle/EzPublishRestBundle/Resources/config/value_object_visitors.yml b/eZ/Bundle/EzPublishRestBundle/Resources/config/value_object_visitors.yml
index 44862ff0ed5..3246885e13b 100644
--- a/eZ/Bundle/EzPublishRestBundle/Resources/config/value_object_visitors.yml
+++ b/eZ/Bundle/EzPublishRestBundle/Resources/config/value_object_visitors.yml
@@ -859,3 +859,28 @@ services:
class: "%ezpublish_rest.output.value_object_visitor.ViewInput.class%"
tags:
- { name: ezpublish_rest.output.value_object_visitor, type: eZ\Publish\Core\REST\Client\Values\ViewInput }
+
+ ezpublish_rest.output.value_object_visitor.internal.resource_link:
+ parent: ezpublish_rest.output.value_object_visitor.base
+ class: 'eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\ResourceLink'
+ tags:
+ - { name: ezpublish_rest.output.value_object_visitor, type: 'eZ\Publish\Core\REST\Server\Values\ResourceLink' }
+ arguments:
+ - '@ezpublish_rest.unique_controller_uri_value_loader'
+ - '@ezpublish_rest.output.path_expansion_checker.request_header'
+ - '@ezpublish_rest.output.value_object_visitor.dispatcher'
+
+ ezpublish_rest.output.path_expansion_checker.request_header:
+ class: 'eZ\Publish\Core\REST\Server\Output\PathExpansion\RequestHeaderPathExpansionChecker'
+ calls:
+ - [setRequestStack, ['@request_stack']]
+
+ ezpublish_rest.output.value_object_visitor.internal.resource_route_reference:
+ parent: ezpublish_rest.output.value_object_visitor.base
+ class: 'eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\ResourceRouteReference'
+ tags:
+ - { name: ezpublish_rest.output.value_object_visitor, type: 'eZ\Publish\Core\REST\Server\Values\ResourceRouteReference' }
+ arguments:
+ - '@ezpublish_rest.unique_controller_uri_value_loader'
+ - '@ezpublish_rest.output.path_expansion_checker.request_header'
+ - '@ezpublish_rest.output.value_object_visitor.dispatcher'
diff --git a/eZ/Bundle/EzPublishRestBundle/Tests/Functional/ResourceEmbeddingTest.php b/eZ/Bundle/EzPublishRestBundle/Tests/Functional/ResourceEmbeddingTest.php
new file mode 100644
index 00000000000..3ce1d2862e5
--- /dev/null
+++ b/eZ/Bundle/EzPublishRestBundle/Tests/Functional/ResourceEmbeddingTest.php
@@ -0,0 +1,41 @@
+createHttpRequest('GET', '/api/ezp/v2/content/objects/1');
+ $request->addHeader('x-ez-embed-value: Content.MainLocation,Content.Owner.Section');
+
+ $response = $this->sendHttpRequest($request);
+
+ self::assertHttpResponseCodeEquals($response, 200);
+
+ $doc = new \DOMDocument();
+ $doc->loadXML($response->getContent());
+
+ $this->assertXPath($doc, '/Content/MainLocation/id');
+ $this->assertXPath($doc, '/Content/Owner/name');
+ $this->assertXPath($doc, '/Content/Owner/Section/sectionId');
+ }
+
+ protected function assertXPath(\DOMDocument $document, $xpathExpression)
+ {
+ $xpath = new \DOMXPath($document);
+
+ $this->assertTrue(
+ $xpath->evaluate("boolean({$xpathExpression})"),
+ "XPath expression '{$xpathExpression}' resulted in an empty node set."
+ );
+ }
+}
diff --git a/eZ/Publish/Core/REST/Common/Output/Generator.php b/eZ/Publish/Core/REST/Common/Output/Generator.php
index 81a59c15485..cceabffa48e 100644
--- a/eZ/Publish/Core/REST/Common/Output/Generator.php
+++ b/eZ/Publish/Core/REST/Common/Output/Generator.php
@@ -396,4 +396,31 @@ protected function checkEnd($type, $data)
* @return mixed
*/
abstract public function serializeBool($boolValue);
+
+ /**
+ * Returns a string representation of the current stack of the document.
+ *
+ * Example: "Location.ContentInfo'.
+ * Elements of type 'attribute', 'document' and 'list' are ignored.
+ *
+ * @return string
+ */
+ public function getStackPath()
+ {
+ $relevantNodes = array_filter(
+ $this->stack,
+ function ($value) {
+ return !in_array($value[0], ['attribute', 'document', 'list']);
+ }
+ );
+
+ $names = array_map(
+ function ($value) {
+ return $value[1];
+ },
+ $relevantNodes
+ );
+
+ return implode('.', $names);
+ }
}
diff --git a/eZ/Publish/Core/REST/Common/Output/ValueObjectVisitor/ContentObjectStates.php b/eZ/Publish/Core/REST/Common/Output/ValueObjectVisitor/ContentObjectStates.php
index 2ec49459160..11956d4e0f9 100644
--- a/eZ/Publish/Core/REST/Common/Output/ValueObjectVisitor/ContentObjectStates.php
+++ b/eZ/Publish/Core/REST/Common/Output/ValueObjectVisitor/ContentObjectStates.php
@@ -13,6 +13,7 @@
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
use eZ\Publish\Core\REST\Common\Output\Generator;
use eZ\Publish\Core\REST\Common\Output\Visitor;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
/**
* ContentObjectStates value object visitor.
@@ -36,17 +37,15 @@ public function visit(Visitor $visitor, Generator $generator, $data)
foreach ($data->states as $state) {
$generator->startObjectElement('ObjectState');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
'ezpublish_rest_loadObjectState',
- array(
+ [
'objectStateGroupId' => $state->groupId,
'objectStateId' => $state->objectState->id,
- )
+ ]
)
);
- $generator->endAttribute('href');
$generator->endObjectElement('ObjectState');
}
diff --git a/eZ/Publish/Core/REST/Common/Output/ValueObjectVisitorDispatcher.php b/eZ/Publish/Core/REST/Common/Output/ValueObjectVisitorDispatcher.php
index f5cee7967d4..ab87192f638 100644
--- a/eZ/Publish/Core/REST/Common/Output/ValueObjectVisitorDispatcher.php
+++ b/eZ/Publish/Core/REST/Common/Output/ValueObjectVisitorDispatcher.php
@@ -59,18 +59,26 @@ public function addVisitor($visitedClassName, ValueObjectVisitor $visitor)
*
* @return mixed
*/
- public function visit($data)
+ public function visit($data, Generator $generator = null, Visitor $visitor = null)
{
if (!is_object($data)) {
throw new Exceptions\InvalidTypeException($data);
}
$checkedClassNames = array();
+ if ($visitor === null) {
+ $visitor = $this->outputVisitor;
+ }
+
+ if ($generator === null) {
+ $generator = $this->outputGenerator;
+ }
+
$className = get_class($data);
do {
$checkedClassNames[] = $className;
if (isset($this->visitors[$className])) {
- return $this->visitors[$className]->visit($this->outputVisitor, $this->outputGenerator, $data);
+ return $this->visitors[$className]->visit($visitor, $generator, $data);
}
} while ($className = get_parent_class($className));
diff --git a/eZ/Publish/Core/REST/Common/Output/Visitor.php b/eZ/Publish/Core/REST/Common/Output/Visitor.php
index b2c20a43f00..ad67b628027 100644
--- a/eZ/Publish/Core/REST/Common/Output/Visitor.php
+++ b/eZ/Publish/Core/REST/Common/Output/Visitor.php
@@ -134,12 +134,15 @@ public function visit($data)
*
* @return mixed
*/
- public function visitValueObject($data)
+ public function visitValueObject($data, Generator $generator = null, Visitor $visitor = null)
{
$this->valueObjectVisitorDispatcher->setOutputGenerator($this->generator);
- $this->valueObjectVisitorDispatcher->setOutputVisitor($this);
- return $this->valueObjectVisitorDispatcher->visit($data);
+ return $this->valueObjectVisitorDispatcher->visit(
+ $data,
+ $generator ?: $this->generator,
+ $visitor ?: $this
+ );
}
/**
diff --git a/eZ/Publish/Core/REST/Common/Tests/Output/GeneratorTest.php b/eZ/Publish/Core/REST/Common/Tests/Output/GeneratorTest.php
index 72311663f91..dce1017886c 100644
--- a/eZ/Publish/Core/REST/Common/Tests/Output/GeneratorTest.php
+++ b/eZ/Publish/Core/REST/Common/Tests/Output/GeneratorTest.php
@@ -201,4 +201,48 @@ public function testNonEmptyDocument()
$this->assertFalse($generator->isEmpty());
}
+
+ public function testGetDocumentStackPath()
+ {
+ $generator = $this->getGenerator();
+
+ $generator->startDocument('test');
+
+ self::assertEquals('', $generator->getStackPath());
+ }
+
+ public function testGetRootStackPath()
+ {
+ $generator = $this->getGenerator();
+
+ $generator->startDocument('test');
+ $generator->startObjectElement('element');
+
+ self::assertEquals('element', $generator->getStackPath());
+ }
+
+ public function testGetElementStackPath()
+ {
+ $generator = $this->getGenerator();
+
+ $generator->startDocument('test');
+ $generator->startObjectElement('element');
+ $generator->startObjectElement('subElement');
+
+ self::assertEquals('element.subElement', $generator->getStackPath());
+ }
+
+ public function testGetListChildrenStackPath()
+ {
+ $generator = $this->getGenerator();
+
+ $generator->startDocument('test');
+ $generator->startObjectElement('listOfElements');
+ $generator->startList('listOfElements');
+ $generator->startObjectElement('child');
+ $generator->startAttribute('href', 'http://google.com');
+ $generator->endAttribute('href');
+
+ self::assertEquals('listOfElements.child', $generator->getStackPath());
+ }
}
diff --git a/eZ/Publish/Core/REST/Common/Tests/Output/ValueObjectVisitorBaseTest.php b/eZ/Publish/Core/REST/Common/Tests/Output/ValueObjectVisitorBaseTest.php
index 914045fb065..118b7ddd83a 100644
--- a/eZ/Publish/Core/REST/Common/Tests/Output/ValueObjectVisitorBaseTest.php
+++ b/eZ/Publish/Core/REST/Common/Tests/Output/ValueObjectVisitorBaseTest.php
@@ -194,6 +194,26 @@ protected function addRouteExpectation($routeName, $arguments, $returnValue)
->will($this->returnValue($returnValue));
}
+ /**
+ * Adds the expectated value object visit calls sequence.
+ *
+ * @param array $valueObjects Array of visited value object, or of phpunit matcher ($this->instanceOf(), etc...) .
+ */
+ protected function setVisitValueObjectExpectations(array $valueObjects)
+ {
+ $consecutiveCalls = [];
+ foreach ($valueObjects as $valueObject) {
+ $consecutiveCalls = [
+ $valueObject,
+ $this->getGenerator(),
+ $this->getVisitorMock(),
+ ];
+ }
+
+ $mocker = $this->getVisitorMock()->expects($this->any())->method('visitValueObject');
+ call_user_func_array([$mocker, 'withConsecutive'], $consecutiveCalls);
+ }
+
/**
* @return \Symfony\Component\Routing\RouterInterface|\PHPUnit_Framework_MockObject_MockObject
*/
diff --git a/eZ/Publish/Core/REST/Server/Output/PathExpansion/Exceptions/MultipleValueLoadException.php b/eZ/Publish/Core/REST/Server/Output/PathExpansion/Exceptions/MultipleValueLoadException.php
new file mode 100644
index 00000000000..17d327ddf1e
--- /dev/null
+++ b/eZ/Publish/Core/REST/Server/Output/PathExpansion/Exceptions/MultipleValueLoadException.php
@@ -0,0 +1,19 @@
+innerGenerator = $generator;
+ }
+
+ /**
+ * Not supported in this generator, as the context is always within a generated document.
+ *
+ * @param mixed $data
+ *
+ * @throws BadStateException
+ */
+ public function startDocument($data)
+ {
+ throw new BadStateException(
+ 'generator',
+ 'start/endDocument can not be used with the ExpansionGenerator'
+ );
+ }
+
+ /**
+ * Returns if the document is empty or already contains data.
+ *
+ * @return bool
+ */
+ public function isEmpty()
+ {
+ return $this->innerGenerator->isEmpty();
+ }
+
+ /**
+ * Not supported in this generator, as the context is always within a generated document.
+ *
+ * @param mixed $data
+ *
+ * @throws BadStateException
+ */
+ public function endDocument($data)
+ {
+ throw new BadStateException('generator', 'start/endDocument can not be used with the ExpansionGenerator');
+ }
+
+ /**
+ * Start object element.
+ * If the element is the first added to this generator, it is silently skipped.
+ * Subsequent elements are started as expected.
+ *
+ * @param string $name
+ * @param string $mediaTypeName
+ */
+ public function startObjectElement($name, $mediaTypeName = null)
+ {
+ $this->stack[] = $name;
+
+ if (count($this->stack) > 1) {
+ $this->innerGenerator->startObjectElement($name, $mediaTypeName);
+ }
+ }
+
+ /**
+ * End object element.
+ *
+ * @param string $name
+ */
+ public function endObjectElement($name)
+ {
+ $objectElementName = array_pop($this->stack);
+ if (count($this->stack) > 0) {
+ $this->innerGenerator->endObjectElement($name);
+ } else {
+ if ($name !== $objectElementName) {
+ throw new OutputGeneratorException("Closing object element name doesn't match the opening one ($objectElementName)");
+ }
+ }
+ }
+
+ /**
+ * Start hash element.
+ *
+ * @param string $name
+ */
+ public function startHashElement($name)
+ {
+ $this->innerGenerator->startHashElement($name);
+ }
+
+ /**
+ * End hash element.
+ *
+ * @param string $name
+ */
+ public function endHashElement($name)
+ {
+ $this->innerGenerator->endHashElement($name);
+ }
+
+ /**
+ * Start value element.
+ *
+ * @param string $name
+ * @param string $value
+ */
+ public function startValueElement($name, $value)
+ {
+ $this->innerGenerator->startValueElement($name, $value);
+ }
+
+ /**
+ * End value element.
+ *
+ * @param string $name
+ */
+ public function endValueElement($name)
+ {
+ $this->innerGenerator->endValueElement($name);
+ }
+
+ /**
+ * Start list.
+ *
+ * @param string $name
+ */
+ public function startList($name)
+ {
+ $this->innerGenerator->startList($name);
+ }
+
+ /**
+ * End list.
+ *
+ * @param string $name
+ */
+ public function endList($name)
+ {
+ $this->innerGenerator->endList($name);
+ }
+
+ /**
+ * Start attribute.
+ * Skips the href and media-type attribute at stack depth 0.
+ *
+ * @param string $name
+ * @param string $value
+ */
+ public function startAttribute($name, $value)
+ {
+ if (!in_array($name, ['href', 'media-type']) || count($this->stack) > 1) {
+ $this->innerGenerator->startAttribute($name, $value);
+ }
+ }
+
+ /**
+ * End attribute.
+ *
+ * @param string $name
+ */
+ public function endAttribute($name)
+ {
+ if (!in_array($name, ['href', 'media-type']) || count($this->stack) > 1) {
+ $this->innerGenerator->endAttribute($name);
+ }
+ }
+
+ /**
+ * Get media type.
+ *
+ * @param string $name
+ *
+ * @return string
+ */
+ public function getMediaType($name)
+ {
+ return $this->innerGenerator->getMediaType($name);
+ }
+
+ /**
+ * Generates a generic representation of the scalar, hash or list given in
+ * $hashValue into the document, using an element of $hashElementName as
+ * its parent.
+ *
+ * @param string $hashElementName
+ * @param mixed $hashValue
+ */
+ public function generateFieldTypeHash($hashElementName, $hashValue)
+ {
+ $this->innerGenerator->generateFieldTypeHash($hashElementName, $hashValue);
+ }
+
+ /**
+ * Serializes a boolean value.
+ *
+ * @param bool $boolValue
+ *
+ * @return mixed
+ */
+ public function serializeBool($boolValue)
+ {
+ return $this->innerGenerator->serializeBool($boolValue);
+ }
+
+ public function getStackPath()
+ {
+ return $this->innerGenerator->getStackPath();
+ }
+}
diff --git a/eZ/Publish/Core/REST/Server/Output/PathExpansion/PathExpansionChecker.php b/eZ/Publish/Core/REST/Server/Output/PathExpansion/PathExpansionChecker.php
new file mode 100644
index 00000000000..b7681338bb0
--- /dev/null
+++ b/eZ/Publish/Core/REST/Server/Output/PathExpansion/PathExpansionChecker.php
@@ -0,0 +1,30 @@
+
+ *
+ *
+ *
+ *
+ * ```
+ */
+interface PathExpansionChecker
+{
+ /**
+ * Tests if the link at $documentPath must be expanded.
+ *
+ * @param string $documentPath Path in a rest generator (example: Content.Owner).
+ *
+ * @return bool
+ */
+ public function needsExpansion($documentPath);
+}
diff --git a/eZ/Publish/Core/REST/Server/Output/PathExpansion/RequestHeaderPathExpansionChecker.php b/eZ/Publish/Core/REST/Server/Output/PathExpansion/RequestHeaderPathExpansionChecker.php
new file mode 100644
index 00000000000..6e5f27a2ff4
--- /dev/null
+++ b/eZ/Publish/Core/REST/Server/Output/PathExpansion/RequestHeaderPathExpansionChecker.php
@@ -0,0 +1,49 @@
+getRequestStack()->getMasterRequest();
+
+ if (is_null($request)) {
+ return false;
+ }
+ if (!$request->headers->has('x-ez-embed-value')) {
+ return false;
+ }
+
+ $documentPath = strtolower($documentPath);
+ foreach (explode(',', $request->headers->get('x-ez-embed-value')) as $requestedPath) {
+ $requestedPath = strtolower($requestedPath);
+ if ($requestedPath === $documentPath) {
+ return true;
+ }
+ if (substr($requestedPath, 0, strlen($documentPath)) === $documentPath) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+}
diff --git a/eZ/Publish/Core/REST/Server/Output/PathExpansion/ValueLoaders/ControllerUriValueLoader.php b/eZ/Publish/Core/REST/Server/Output/PathExpansion/ValueLoaders/ControllerUriValueLoader.php
new file mode 100644
index 00000000000..17ac92e281f
--- /dev/null
+++ b/eZ/Publish/Core/REST/Server/Output/PathExpansion/ValueLoaders/ControllerUriValueLoader.php
@@ -0,0 +1,60 @@
+router = $router;
+ $this->controllerResolver = $controllerResolver;
+ }
+
+ public function load($restResourceLink, $mediaType = null)
+ {
+ $request = Request::create($restResourceLink);
+ $request->attributes->add($this->router->match($restResourceLink));
+
+ if ($mediaType !== null) {
+ $request->headers->set('Accept', $mediaType);
+ }
+
+ $controller = $this->controllerResolver->getController($request);
+ $arguments = $this->controllerResolver->getArguments($request, $controller);
+
+ $value = call_user_func_array($controller, $arguments);
+
+ if ($value instanceof Response) {
+ throw new UnexpectedValueException('Expected the controller to return a Value object, got a Response instead');
+ }
+
+ return $value;
+ }
+}
diff --git a/eZ/Publish/Core/REST/Server/Output/PathExpansion/ValueLoaders/UniqueUriValueLoader.php b/eZ/Publish/Core/REST/Server/Output/PathExpansion/ValueLoaders/UniqueUriValueLoader.php
new file mode 100644
index 00000000000..e2336312847
--- /dev/null
+++ b/eZ/Publish/Core/REST/Server/Output/PathExpansion/ValueLoaders/UniqueUriValueLoader.php
@@ -0,0 +1,45 @@
+innerLoader = $innerLoader;
+ }
+
+ /**
+ * @param string $uri REST URI to a value object. Ex: /api/ezp/v2/content/objects/1
+ * @param string $mediaType The media-type to load, default if not specified. Ex: application/vnd.ez.api.Content+xml.
+ *
+ * @return \eZ\Publish\API\Repository\Values\ValueObject
+ *
+ * @throws MultipleValueLoadException When load is called on an URI that was previously loaded (at instance level).
+ */
+ public function load($uri, $mediaType = null)
+ {
+ if (isset($this->loadedUris[$uri]) && array_key_exists($mediaType, $this->loadedUris[$uri])) {
+ throw new MultipleValueLoadException();
+ }
+
+ $this->loadedUris[$uri][$mediaType] = true;
+
+ return $this->innerLoader->load($uri, $mediaType);
+ }
+}
diff --git a/eZ/Publish/Core/REST/Server/Output/PathExpansion/ValueLoaders/UriValueLoader.php b/eZ/Publish/Core/REST/Server/Output/PathExpansion/ValueLoaders/UriValueLoader.php
new file mode 100644
index 00000000000..b1d8569d61f
--- /dev/null
+++ b/eZ/Publish/Core/REST/Server/Output/PathExpansion/ValueLoaders/UriValueLoader.php
@@ -0,0 +1,20 @@
+visitValueObject($data->value);
+ $visitor->visitValueObject($data->value, $generator, $visitor);
if ($this->getParameter('content.view_cache') !== true) {
return;
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/ContentTypeGroup.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/ContentTypeGroup.php
index d80d6b3cf27..86038c12ff5 100644
--- a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/ContentTypeGroup.php
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/ContentTypeGroup.php
@@ -13,6 +13,7 @@
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
use eZ\Publish\Core\REST\Common\Output\Generator;
use eZ\Publish\Core\REST\Common\Output\Visitor;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
/**
* ContentTypeGroup value object visitor.
@@ -34,10 +35,7 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$generator->startAttribute(
'href',
- $this->router->generate(
- 'ezpublish_rest_loadContentTypeGroup',
- array('contentTypeGroupId' => $data->id)
- )
+ $this->router->generate('ezpublish_rest_loadContentTypeGroup', ['contentTypeGroupId' => $data->id])
);
$generator->endAttribute('href');
@@ -54,30 +52,31 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$generator->endValueElement('modified');
$generator->startObjectElement('Creator', 'User');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadUser', array('userId' => $data->creatorId))
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadUser', ['userId' => $data->creatorId]),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('Creator');
$generator->startObjectElement('Modifier', 'User');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadUser', array('userId' => $data->modifierId))
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadUser', ['userId' => $data->modifierId]),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('Modifier');
$generator->startObjectElement('ContentTypes', 'ContentTypeInfoList');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
'ezpublish_rest_listContentTypesForGroup',
- array('contentTypeGroupId' => $data->id)
- )
+ ['contentTypeGroupId' => $data->id],
+ 'ContentTypeInfoList'
+ ),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('ContentTypes');
$generator->endObjectElement('ContentTypeGroup');
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/ContentTypeGroupRefList.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/ContentTypeGroupRefList.php
index 4539033a1d1..275f473de17 100644
--- a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/ContentTypeGroupRefList.php
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/ContentTypeGroupRefList.php
@@ -13,6 +13,7 @@
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
use eZ\Publish\Core\REST\Common\Output\Generator;
use eZ\Publish\Core\REST\Common\Output\Visitor;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
/**
* ContentTypeGroupRefList value object visitor.
@@ -48,16 +49,9 @@ public function visit(Visitor $visitor, Generator $generator, $data)
foreach ($data->contentTypeGroups as $contentTypeGroup) {
$generator->startObjectElement('ContentTypeGroupRef', 'ContentTypeGroup');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
- 'ezpublish_rest_loadContentTypeGroup',
- array(
- 'contentTypeGroupId' => $contentTypeGroup->id,
- )
- )
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadContentTypeGroup', ['contentTypeGroupId' => $contentTypeGroup->id])
);
- $generator->endAttribute('href');
// Unlinking last group is not allowed
if ($groupCount > 1) {
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/Location.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/Location.php
index f9674b7d749..0e8321a71a1 100644
--- a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/Location.php
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/Location.php
@@ -14,7 +14,7 @@
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
use eZ\Publish\Core\REST\Common\Output\Generator;
use eZ\Publish\Core\REST\Common\Output\Visitor;
-use eZ\Publish\Core\REST\Server\Values\RestContent as RestContentValue;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
/**
* Location value object visitor.
@@ -73,16 +73,12 @@ public function visit(Visitor $visitor, Generator $generator, $location)
$generator->startObjectElement('ParentLocation', 'Location');
if (trim($location->pathString, '/') !== '1') {
- $generator->startAttribute(
- 'href',
- $this->router->generate(
- 'ezpublish_rest_loadLocation',
- array(
- 'locationPath' => implode('/', array_slice($location->path, 0, count($location->path) - 1)),
- )
- )
+ new ResourceRouteReference(
+ 'ezpublish_rest_loadLocation',
+ [
+ 'locationPath' => implode('/', array_slice($location->path, 0, count($location->path) - 1)),
+ ]
);
- $generator->endAttribute('href');
}
$generator->endObjectElement('ParentLocation');
@@ -99,24 +95,17 @@ public function visit(Visitor $visitor, Generator $generator, $location)
$generator->endValueElement('remoteId');
$generator->startObjectElement('Children', 'LocationList');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
- 'ezpublish_rest_loadLocationChildren',
- array(
- 'locationPath' => trim($location->pathString, '/'),
- )
- )
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadLocationChildren', ['locationPath' => trim($location->pathString, '/')]),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('Children');
$generator->startObjectElement('Content');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadContent', array('contentId' => $location->contentId))
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadContent', ['contentId' => $location->contentId])
);
- $generator->endAttribute('href');
$generator->endObjectElement('Content');
$generator->startValueElement('sortField', $this->serializeSortField($location->sortField));
@@ -126,26 +115,19 @@ public function visit(Visitor $visitor, Generator $generator, $location)
$generator->endValueElement('sortOrder');
$generator->startObjectElement('UrlAliases', 'UrlAliasRefList');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
- 'ezpublish_rest_listLocationURLAliases',
- array('locationPath' => trim($location->pathString, '/'))
- )
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_listLocationURLAliases', ['locationPath' => trim($location->pathString, '/')])
);
- $generator->endAttribute('href');
$generator->endObjectElement('UrlAliases');
$generator->startObjectElement('ContentInfo', 'ContentInfo');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
- 'ezpublish_rest_loadContent',
- array('contentId' => $location->contentId)
- )
+
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadContent', ['contentId' => $location->contentId]),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
- $visitor->visitValueObject(new RestContentValue($location->contentInfo));
+
$generator->endObjectElement('ContentInfo');
$generator->endObjectElement('Location');
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/LocationList.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/LocationList.php
index ced1d48a318..ac4264eadd4 100644
--- a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/LocationList.php
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/LocationList.php
@@ -13,6 +13,7 @@
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
use eZ\Publish\Core\REST\Common\Output\Generator;
use eZ\Publish\Core\REST\Common\Output\Visitor;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
/**
* LocationList value object visitor.
@@ -38,14 +39,12 @@ public function visit(Visitor $visitor, Generator $generator, $data)
foreach ($data->locations as $restLocation) {
$generator->startObjectElement('Location');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
'ezpublish_rest_loadLocation',
- array('locationPath' => trim($restLocation->location->pathString, '/'))
+ ['locationPath' => trim($restLocation->location->pathString, '/')]
)
);
- $generator->endAttribute('href');
$generator->endObjectElement('Location');
}
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/ObjectStateGroup.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/ObjectStateGroup.php
index da27c957162..cfde2b1dbd3 100644
--- a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/ObjectStateGroup.php
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/ObjectStateGroup.php
@@ -13,6 +13,7 @@
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
use eZ\Publish\Core\REST\Common\Output\Generator;
use eZ\Publish\Core\REST\Common\Output\Visitor;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
/**
* ObjectStateGroup value object visitor.
@@ -51,11 +52,14 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$generator->endValueElement('languageCodes');
$generator->startObjectElement('ObjectStates', 'ObjectStateList');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadObjectStates', array('objectStateGroupId' => $data->id))
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
+ 'ezpublish_rest_loadObjectStates',
+ ['objectStateGroupId' => $data->id]
+ ),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('ObjectStates');
$this->visitNamesList($generator, $data->getNames());
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/ResourceLink.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/ResourceLink.php
new file mode 100644
index 00000000000..3f95778ecab
--- /dev/null
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/ResourceLink.php
@@ -0,0 +1,71 @@
+valueLoader = $valueLoader;
+ $this->pathExpansionChecker = $pathExpansionChecker;
+ $this->visitorDispatcher = $visitorDispatcher;
+ }
+
+ /**
+ * @param Visitor $visitor
+ * @param Generator $generator
+ * @param \eZ\Publish\Core\REST\Server\Values\ResourceLink $data
+ */
+ public function visit(Visitor $visitor, Generator $generator, $data)
+ {
+ $generator->startAttribute('href', $data->link);
+ $generator->endAttribute('href');
+
+ if ($this->pathExpansionChecker->needsExpansion($generator->getStackPath())) {
+ try {
+ $this->visitorDispatcher->visit(
+ $this->valueLoader->load($data->link, $data->mediaType ?: null),
+ new ExpansionGenerator($generator),
+ $visitor
+ );
+ } catch (ApiUnauthorizedException $e) {
+ $generator->startAttribute('embed-error', $e->getMessage());
+ $generator->endAttribute('embed-error');
+ } catch (MultipleValueLoadException $e) {
+ $generator->startAttribute('embed-error', $e->getMessage());
+ $generator->endAttribute('embed-error');
+ }
+ }
+ }
+}
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/ResourceRouteReference.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/ResourceRouteReference.php
new file mode 100644
index 00000000000..e977ffe5bbe
--- /dev/null
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/ResourceRouteReference.php
@@ -0,0 +1,33 @@
+router->generate(
+ $data->route,
+ $data->loadParameters
+ ),
+ isset($data->mediaTypeName) ? $generator->getMediaType($data->mediaTypeName) : null
+ )
+ );
+ }
+}
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestContent.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestContent.php
index 9c225412345..bf8d8ae3dac 100644
--- a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestContent.php
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestContent.php
@@ -13,6 +13,7 @@
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
use eZ\Publish\Core\REST\Common\Output\Generator;
use eZ\Publish\Core\REST\Common\Output\Visitor;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
use eZ\Publish\Core\REST\Server\Values\Version as VersionValue;
/**
@@ -45,7 +46,7 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$generator->startAttribute(
'href',
$data->path === null ?
- $this->router->generate('ezpublish_rest_loadContent', array('contentId' => $contentInfo->id)) :
+ $this->router->generate('ezpublish_rest_loadContent', ['contentId' => $contentInfo->id]) :
$data->path
);
$generator->endAttribute('href');
@@ -56,89 +57,99 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$generator->endAttribute('id');
$generator->startObjectElement('ContentType');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
'ezpublish_rest_loadContentType',
- array('contentTypeId' => $contentInfo->contentTypeId)
- )
+ ['contentTypeId' => $contentInfo->contentTypeId]
+ ),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('ContentType');
$generator->startValueElement('Name', $contentInfo->name);
$generator->endValueElement('Name');
$generator->startObjectElement('Versions', 'VersionList');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadContentVersions', array('contentId' => $contentInfo->id))
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
+ 'ezpublish_rest_loadContentVersions',
+ ['contentId' => $contentInfo->id]
+ )
);
- $generator->endAttribute('href');
$generator->endObjectElement('Versions');
$generator->startObjectElement('CurrentVersion', 'Version');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
'ezpublish_rest_redirectCurrentVersion',
- array('contentId' => $contentInfo->id)
- )
+ ['contentId' => $contentInfo->id]
+ ),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
// Embed current version, if available
if ($currentVersion !== null) {
+ // @todo EZP-26033: this should use rest resource embedding
$visitor->visitValueObject(
new VersionValue(
$currentVersion,
$contentType,
$restContent->relations
- )
+ ),
+ $generator,
+ $visitor
);
}
$generator->endObjectElement('CurrentVersion');
$generator->startObjectElement('Section');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadSection', array('sectionId' => $contentInfo->sectionId))
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
+ 'ezpublish_rest_loadSection',
+ ['sectionId' => $contentInfo->sectionId]
+ ),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('Section');
// Main location will not exist if we're visiting the content draft
if ($data->mainLocation !== null) {
$generator->startObjectElement('MainLocation', 'Location');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
'ezpublish_rest_loadLocation',
- array('locationPath' => trim($mainLocation->pathString, '/'))
- )
+ ['locationPath' => trim($mainLocation->pathString, '/')]
+ ),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('MainLocation');
}
$generator->startObjectElement('Locations', 'LocationList');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
'ezpublish_rest_loadLocationsForContent',
- array('contentId' => $contentInfo->id)
- )
+ ['contentId' => $contentInfo->id]
+ ),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('Locations');
$generator->startObjectElement('Owner', 'User');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadUser', array('userId' => $contentInfo->ownerId))
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
+ 'ezpublish_rest_loadUser',
+ ['userId' => $contentInfo->ownerId]
+ ),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('Owner');
// Modification date will not exist if we're visiting the content draft
@@ -180,14 +191,14 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$generator->endValueElement('alwaysAvailable');
$generator->startObjectElement('ObjectStates', 'ContentObjectStates');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
'ezpublish_rest_getObjectStatesForContent',
- array('contentId' => $contentInfo->id)
- )
+ ['contentId' => $contentInfo->id]
+ ),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('ObjectStates');
$generator->endObjectElement('Content');
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestContentType.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestContentType.php
index 5311047419e..b7a083a9410 100644
--- a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestContentType.php
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestContentType.php
@@ -76,47 +76,40 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$generator->endValueElement('modificationDate');
$generator->startObjectElement('Creator', 'User');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ // @todo EZP-26033: this sould use rest resource embedding
+ $visitor->visitValueObject(
+ new Values\ResourceRouteReference(
'ezpublish_rest_loadUser',
- array('userId' => $contentType->creatorId)
+ ['userId' => $contentType->creatorId]
)
);
- $generator->endAttribute('href');
$generator->endObjectElement('Creator');
$generator->startObjectElement('Modifier', 'User');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new Values\ResourceRouteReference(
'ezpublish_rest_loadUser',
- array('userId' => $contentType->modifierId)
+ ['userId' => $contentType->modifierId]
)
);
- $generator->endAttribute('href');
$generator->endObjectElement('Modifier');
$generator->startObjectElement('Groups', 'ContentTypeGroupRefList');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new Values\ResourceRouteReference(
'ezpublish_rest_loadGroupsOfContentType',
- array('contentTypeId' => $contentType->id)
+ ['contentTypeId' => $contentType->id]
)
);
- $generator->endAttribute('href');
$generator->endObjectElement('Groups');
$generator->startObjectElement('Draft', 'ContentType');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new Values\ResourceRouteReference(
'ezpublish_rest_loadContentTypeDraft',
- array('contentTypeId' => $contentType->id)
+ ['contentTypeId' => $contentType->id]
)
);
- $generator->endAttribute('href');
$generator->endObjectElement('Draft');
$generator->startValueElement('remoteId', $contentType->remoteId);
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestExecutedView.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestExecutedView.php
index 372321be86b..2719abe6cb2 100644
--- a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestExecutedView.php
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestExecutedView.php
@@ -18,6 +18,7 @@
use eZ\Publish\API\Repository\ContentService;
use eZ\Publish\API\Repository\ContentTypeService;
use eZ\Publish\API\Repository\LocationService;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
use eZ\Publish\Core\REST\Server\Values\RestContent as RestContentValue;
/**
@@ -89,11 +90,12 @@ public function visit(Visitor $visitor, Generator $generator, $data)
// BEGIN Result
$generator->startObjectElement('Result', 'ViewResult');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_views_load_results', array('viewId' => $data->identifier))
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
+ 'ezpublish_rest_views_load_results',
+ ['viewId' => $data->identifier]
+ )
);
- $generator->endAttribute('href');
// BEGIN Result metadata
$generator->startValueElement('count', $data->searchResults->totalCount);
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestLocation.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestLocation.php
index 82f08974e18..03d7cde094c 100644
--- a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestLocation.php
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestLocation.php
@@ -13,6 +13,7 @@
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
use eZ\Publish\Core\REST\Common\Output\Generator;
use eZ\Publish\Core\REST\Common\Output\Visitor;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
use eZ\Publish\Core\REST\Server\Values\RestContent as RestContentValue;
/**
@@ -40,7 +41,7 @@ public function visit(Visitor $visitor, Generator $generator, $data)
'href',
$this->router->generate(
'ezpublish_rest_loadLocation',
- array('locationPath' => trim($location->pathString, '/'))
+ ['locationPath' => trim($location->pathString, '/')]
)
);
$generator->endAttribute('href');
@@ -65,16 +66,14 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$generator->startObjectElement('ParentLocation', 'Location');
if (trim($location->pathString, '/') !== '1') {
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
'ezpublish_rest_loadLocation',
- array(
- 'locationPath' => implode('/', array_slice($location->path, 0, count($location->path) - 1)),
- )
- )
+ ['locationPath' => implode('/', array_slice($location->path, 0, count($location->path) - 1))]
+ ),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
}
$generator->endObjectElement('ParentLocation');
@@ -91,24 +90,26 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$generator->endValueElement('remoteId');
$generator->startObjectElement('Children', 'LocationList');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
'ezpublish_rest_loadLocationChildren',
- array(
- 'locationPath' => trim($location->pathString, '/'),
- )
- )
+ ['locationPath' => trim($location->pathString, '/')]
+ ),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('Children');
$generator->startObjectElement('Content');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadContent', array('contentId' => $contentInfo->id))
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
+ 'ezpublish_rest_loadContent',
+ ['contentId' => $contentInfo->id],
+ 'Content'
+ ),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('Content');
$generator->startValueElement('sortField', $this->serializeSortField($location->sortField));
@@ -118,25 +119,27 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$generator->endValueElement('sortOrder');
$generator->startObjectElement('UrlAliases', 'UrlAliasRefList');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
'ezpublish_rest_listLocationURLAliases',
- array('locationPath' => trim($location->pathString, '/'))
- )
+ ['locationPath' => trim($location->pathString, '/')]
+ ),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('UrlAliases');
$generator->startObjectElement('ContentInfo', 'ContentInfo');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
'ezpublish_rest_loadContent',
- array('contentId' => $contentInfo->id)
- )
+ ['contentId' => $contentInfo->id],
+ 'ContentInfo'
+ ),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
+
$visitor->visitValueObject(new RestContentValue($contentInfo));
$generator->endObjectElement('ContentInfo');
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestObjectState.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestObjectState.php
index d94f6ea8090..de50bf2df2e 100644
--- a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestObjectState.php
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestObjectState.php
@@ -13,6 +13,7 @@
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
use eZ\Publish\Core\REST\Common\Output\Generator;
use eZ\Publish\Core\REST\Common\Output\Visitor;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
/**
* RestObjectState value object visitor.
@@ -52,11 +53,12 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$generator->startObjectElement('ObjectStateGroup');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadObjectStateGroup', array('objectStateGroupId' => $data->groupId))
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
+ 'ezpublish_rest_loadObjectStateGroup',
+ ['objectStateGroupId' => $data->groupId]
+ )
);
- $generator->endAttribute('href');
$generator->endObjectElement('ObjectStateGroup');
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestRelation.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestRelation.php
index be2145121bf..55bfc0cfb19 100644
--- a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestRelation.php
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestRelation.php
@@ -14,6 +14,7 @@
use eZ\Publish\Core\REST\Common\Output\Generator;
use eZ\Publish\Core\REST\Common\Output\Visitor;
use eZ\Publish\API\Repository\Values\Content\Relation as RelationValue;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
/**
* RestRelation value object visitor.
@@ -46,29 +47,21 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$generator->endAttribute('href');
$generator->startObjectElement('SourceContent', 'ContentInfo');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
'ezpublish_rest_loadContent',
- array(
- 'contentId' => $data->contentId,
- )
+ ['contentId' => $data->contentId]
)
);
- $generator->endAttribute('href');
$generator->endObjectElement('SourceContent');
$generator->startObjectElement('DestinationContent', 'ContentInfo');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
'ezpublish_rest_loadContent',
- array(
- 'contentId' => $data->relation->getDestinationContentInfo()->id,
- )
+ ['contentId' => $data->relation->getDestinationContentInfo()->id]
)
);
- $generator->endAttribute('href');
$generator->endObjectElement('DestinationContent');
if ($data->relation->sourceFieldDefinitionIdentifier !== null) {
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestTrashItem.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestTrashItem.php
index 53e80b56954..a9467efd341 100644
--- a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestTrashItem.php
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestTrashItem.php
@@ -13,6 +13,7 @@
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
use eZ\Publish\Core\REST\Common\Output\Generator;
use eZ\Publish\Core\REST\Common\Output\Visitor;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
use eZ\Publish\Core\REST\Server\Values\RestContent as RestContentValue;
/**
@@ -63,16 +64,12 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$pathStringParts = array_slice($pathStringParts, 0, count($pathStringParts) - 1);
$generator->startObjectElement('ParentLocation', 'Location');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
'ezpublish_rest_loadLocation',
- array(
- 'locationPath' => implode('/', $pathStringParts),
- )
+ ['locationPath' => implode('/', $pathStringParts)]
)
);
- $generator->endAttribute('href');
$generator->endObjectElement('ParentLocation');
$generator->startValueElement('pathString', $trashItem->pathString);
@@ -88,11 +85,12 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$generator->endValueElement('remoteId');
$generator->startObjectElement('Content');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadContent', array('contentId' => $contentInfo->id))
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
+ 'ezpublish_rest_loadContent',
+ ['contentId' => $contentInfo->id]
+ )
);
- $generator->endAttribute('href');
$generator->endObjectElement('Content');
$generator->startValueElement('sortField', $this->serializeSortField($trashItem->sortField));
@@ -102,14 +100,12 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$generator->endValueElement('sortOrder');
$generator->startObjectElement('ContentInfo', 'ContentInfo');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
'ezpublish_rest_loadContent',
- array('contentId' => $contentInfo->id)
+ ['contentId' => $contentInfo->id]
)
);
- $generator->endAttribute('href');
$visitor->visitValueObject(new RestContentValue($contentInfo));
$generator->endObjectElement('ContentInfo');
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestUser.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestUser.php
index 8525bcbbde5..a62421a36ab 100644
--- a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestUser.php
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestUser.php
@@ -13,6 +13,7 @@
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
use eZ\Publish\Core\REST\Common\Output\Generator;
use eZ\Publish\Core\REST\Common\Output\Visitor;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
use eZ\Publish\Core\REST\Server\Values\Version as VersionValue;
/**
@@ -50,66 +51,69 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$generator->startObjectElement('ContentType');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadContentType', array('contentTypeId' => $contentInfo->contentTypeId))
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
+ 'ezpublish_rest_loadContentType',
+ ['contentTypeId' => $contentInfo->contentTypeId]
+ )
);
- $generator->endAttribute('href');
-
$generator->endObjectElement('ContentType');
$generator->startValueElement('name', $contentInfo->name);
$generator->endValueElement('name');
$generator->startObjectElement('Versions', 'VersionList');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadContentVersions', array('contentId' => $contentInfo->id))
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
+ 'ezpublish_rest_loadContentVersions',
+ ['contentId' => $contentInfo->id]
+ )
);
- $generator->endAttribute('href');
$generator->endObjectElement('Versions');
$generator->startObjectElement('Section');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadSection', array('sectionId' => $contentInfo->sectionId))
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
+ 'ezpublish_rest_loadSection',
+ ['sectionId' => $contentInfo->sectionId]
+ )
);
- $generator->endAttribute('href');
$generator->endObjectElement('Section');
$generator->startObjectElement('MainLocation', 'Location');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
'ezpublish_rest_loadLocation',
- array('locationPath' => trim($data->mainLocation->pathString, '/'))
+ ['locationPath' => trim($data->mainLocation->pathString, '/')]
)
);
- $generator->endAttribute('href');
$generator->endObjectElement('MainLocation');
$generator->startObjectElement('Locations', 'LocationList');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadLocationsForContent', array('contentId' => $contentInfo->id))
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
+ 'ezpublish_rest_loadLocationsForContent',
+ ['contentId' => $contentInfo->id]
+ )
);
- $generator->endAttribute('href');
$generator->endObjectElement('Locations');
$generator->startObjectElement('Groups', 'UserGroupRefList');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadUserGroupsOfUser', array('userId' => $contentInfo->id))
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
+ 'ezpublish_rest_loadUserGroupsOfUser',
+ ['userId' => $contentInfo->id]
+ )
);
- $generator->endAttribute('href');
$generator->endObjectElement('Groups');
$generator->startObjectElement('Owner', 'User');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadUser', array('userId' => $contentInfo->ownerId))
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
+ 'ezpublish_rest_loadUser',
+ ['userId' => $contentInfo->ownerId]
+ )
);
- $generator->endAttribute('href');
$generator->endObjectElement('Owner');
$generator->startValueElement('publishDate', $contentInfo->publishedDate->format('c'));
@@ -148,27 +152,15 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$generator->endValueElement('enabled');
$generator->startObjectElement('UserGroups', 'UserGroupList');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
- 'ezpublish_rest_loadUserGroupsOfUser',
- array('userId' => $contentInfo->id)
- )
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadUserGroupsOfUser', ['userId' => $contentInfo->id])
);
- $generator->endAttribute('href');
$generator->endObjectElement('UserGroups');
$generator->startObjectElement('Roles', 'RoleAssignmentList');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
- 'ezpublish_rest_loadRoleAssignmentsForUser',
- array(
- 'userId' => $contentInfo->id,
- )
- )
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadRoleAssignmentsForUser', ['userId' => $contentInfo->id])
);
- $generator->endAttribute('href');
$generator->endObjectElement('Roles');
$generator->endObjectElement('User');
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestUserGroup.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestUserGroup.php
index d8f297dfc3d..a4f92be3e1a 100644
--- a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestUserGroup.php
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestUserGroup.php
@@ -13,6 +13,7 @@
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
use eZ\Publish\Core\REST\Common\Output\Generator;
use eZ\Publish\Core\REST\Common\Output\Visitor;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
use eZ\Publish\Core\REST\Server\Values\Version as VersionValue;
/**
@@ -52,14 +53,14 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$generator->startObjectElement('ContentType');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
'ezpublish_rest_loadContentType',
- array('contentTypeId' => $contentInfo->contentTypeId)
- )
+ ['contentTypeId' => $contentInfo->contentTypeId]
+ ),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('ContentType');
@@ -67,46 +68,44 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$generator->endValueElement('name');
$generator->startObjectElement('Versions', 'VersionList');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadContentVersions', array('contentId' => $contentInfo->id))
+
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadContentVersions', ['contentId' => $contentInfo->id]),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('Versions');
$generator->startObjectElement('Section');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadSection', array('sectionId' => $contentInfo->sectionId))
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadSection', array('sectionId' => $contentInfo->sectionId)),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('Section');
$generator->startObjectElement('MainLocation', 'Location');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
- 'ezpublish_rest_loadLocation',
- array('locationPath' => $mainLocationPath)
- )
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadLocation', ['locationPath' => $mainLocationPath]),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('MainLocation');
$generator->startObjectElement('Locations', 'LocationList');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadLocationsForContent', array('contentId' => $contentInfo->id))
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadLocationsForContent', ['contentId' => $contentInfo->id]),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('Locations');
$generator->startObjectElement('Owner', 'User');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadUser', array('userId' => $contentInfo->ownerId))
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadUser', ['userId' => $contentInfo->ownerId]),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('Owner');
$generator->startValueElement('publishDate', $contentInfo->publishedDate->format('c'));
@@ -133,55 +132,38 @@ public function visit(Visitor $visitor, Generator $generator, $data)
);
$generator->startObjectElement('ParentUserGroup', 'UserGroup');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
'ezpublish_rest_loadUserGroup',
- array(
- 'groupPath' => implode('/', array_slice($mainLocation->path, 0, count($mainLocation->path) - 1)),
- )
- )
+ ['groupPath' => implode('/', array_slice($mainLocation->path, 0, count($mainLocation->path) - 1))]
+ ),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('ParentUserGroup');
$generator->startObjectElement('Subgroups', 'UserGroupList');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
- 'ezpublish_rest_loadSubUserGroups',
- array(
- 'groupPath' => $mainLocationPath,
- )
- )
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadSubUserGroups', ['groupPath' => $mainLocationPath]),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('Subgroups');
$generator->startObjectElement('Users', 'UserList');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
- 'ezpublish_rest_loadUsersFromGroup',
- array(
- 'groupPath' => $mainLocationPath,
- )
- )
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadUsersFromGroup', ['groupPath' => $mainLocationPath]),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('Users');
$generator->startObjectElement('Roles', 'RoleAssignmentList');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
- 'ezpublish_rest_loadRoleAssignmentsForUserGroup',
- array(
- 'groupPath' => $mainLocationPath,
- )
- )
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadRoleAssignmentsForUserGroup', ['groupPath' => $mainLocationPath]),
+ $generator,
+ $visitor
);
- $generator->endAttribute('href');
$generator->endObjectElement('Roles');
$generator->endObjectElement('UserGroup');
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestUserGroupRoleAssignment.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestUserGroupRoleAssignment.php
index c8e7c92eeee..66d4375c6f6 100644
--- a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestUserGroupRoleAssignment.php
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestUserGroupRoleAssignment.php
@@ -14,6 +14,7 @@
use eZ\Publish\Core\REST\Common\Output\Generator;
use eZ\Publish\Core\REST\Common\Output\Visitor;
use eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
/**
* RestUserGroupRoleAssignment value object visitor.
@@ -53,11 +54,12 @@ public function visit(Visitor $visitor, Generator $generator, $data)
}
$generator->startObjectElement('Role');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadRole', array('roleId' => $role->id))
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
+ 'ezpublish_rest_loadRole',
+ ['roleId' => $role->id]
+ )
);
- $generator->endAttribute('href');
$generator->endObjectElement('Role');
$generator->endObjectElement('RoleAssignment');
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestUserRoleAssignment.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestUserRoleAssignment.php
index a3a509b000e..34f00066555 100644
--- a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestUserRoleAssignment.php
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/RestUserRoleAssignment.php
@@ -14,6 +14,7 @@
use eZ\Publish\Core\REST\Common\Output\Generator;
use eZ\Publish\Core\REST\Common\Output\Visitor;
use eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
/**
* RestUserRoleAssignment value object visitor.
@@ -53,11 +54,9 @@ public function visit(Visitor $visitor, Generator $generator, $data)
}
$generator->startObjectElement('Role');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadRole', array('roleId' => $role->id))
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadRole', ['roleId' => $role->id])
);
- $generator->endAttribute('href');
$generator->endObjectElement('Role');
$generator->endObjectElement('RoleAssignment');
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/Role.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/Role.php
index 24896dc84ae..ae1fd879c1b 100644
--- a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/Role.php
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/Role.php
@@ -14,6 +14,7 @@
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
use eZ\Publish\Core\REST\Common\Output\Generator;
use eZ\Publish\Core\REST\Common\Output\Visitor;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
/**
* Role value object visitor.
@@ -43,11 +44,9 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$generator->endValueElement('identifier');
$generator->startObjectElement('Policies', 'PolicyList');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadPolicies', array('roleId' => $data->id))
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadPolicies', ['roleId' => $data->id])
);
- $generator->endAttribute('href');
$generator->endObjectElement('Policies');
$generator->endObjectElement('Role');
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/URLAlias.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/URLAlias.php
index 2453a7cc06d..6b83e232443 100644
--- a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/URLAlias.php
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/URLAlias.php
@@ -14,6 +14,7 @@
use eZ\Publish\Core\REST\Common\Output\Generator;
use eZ\Publish\Core\REST\Common\Output\Visitor;
use eZ\Publish\API\Repository\Values;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
/**
* URLAlias value object visitor.
@@ -46,11 +47,9 @@ public function visit(Visitor $visitor, Generator $generator, $data)
if ($data->type === Values\Content\URLAlias::LOCATION) {
$generator->startObjectElement('location', 'Location');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadLocation', array('locationPath' => $data->destination))
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadLocation', ['locationPath' => $data->destination])
);
- $generator->endAttribute('href');
$generator->endObjectElement('location');
} else {
$generator->startValueElement('resource', $data->destination);
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/UserGroupRefList.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/UserGroupRefList.php
index 0d745bf263d..3caa3595bcd 100644
--- a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/UserGroupRefList.php
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/UserGroupRefList.php
@@ -13,6 +13,7 @@
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
use eZ\Publish\Core\REST\Common\Output\Generator;
use eZ\Publish\Core\REST\Common\Output\Visitor;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
/**
* UserGroupRefList value object visitor.
@@ -42,31 +43,25 @@ public function visit(Visitor $visitor, Generator $generator, $data)
foreach ($data->userGroups as $userGroup) {
$generator->startObjectElement('UserGroup');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
'ezpublish_rest_loadUserGroup',
- array(
- 'groupPath' => trim($userGroup->mainLocation->pathString, '/'),
- )
+ ['groupPath' => trim($userGroup->mainLocation->pathString, '/')]
)
);
- $generator->endAttribute('href');
if ($data->userId !== null && $groupCount > 1) {
$generator->startHashElement('unassign');
- $generator->startAttribute(
- 'href',
- $this->router->generate(
+ $visitor->visitValueObject(
+ new ResourceRouteReference(
'ezpublish_rest_unassignUserFromUserGroup',
- array(
+ [
'userId' => $data->userId,
'groupPath' => $userGroup->mainLocation->path[count($userGroup->mainLocation->path) - 1],
- )
+ ]
)
);
- $generator->endAttribute('href');
$generator->startAttribute('method', 'DELETE');
$generator->endAttribute('method');
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/UserRefList.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/UserRefList.php
index 3b07724d2ff..a4c75bbd9a9 100644
--- a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/UserRefList.php
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/UserRefList.php
@@ -13,6 +13,7 @@
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
use eZ\Publish\Core\REST\Common\Output\Generator;
use eZ\Publish\Core\REST\Common\Output\Visitor;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
/**
* UserRefList value object visitor.
@@ -39,10 +40,9 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$generator->startList('User');
foreach ($data->users as $user) {
$generator->startObjectElement('User');
-
- $generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadUser', array('userId' => $user->contentInfo->id)));
- $generator->endAttribute('href');
-
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadUser', ['userId' => $user->contentInfo->id])
+ );
$generator->endObjectElement('User');
}
$generator->endList('User');
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/UserSession.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/UserSession.php
index 2207cb6851b..15404dc6fa1 100644
--- a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/UserSession.php
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/UserSession.php
@@ -13,6 +13,7 @@
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
use eZ\Publish\Core\REST\Common\Output\Generator;
use eZ\Publish\Core\REST\Common\Output\Visitor;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
/**
* UserSession value object visitor.
@@ -53,11 +54,9 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$generator->endValueElement('csrfToken');
$generator->startObjectElement('User', 'User');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadUser', array('userId' => $data->user->id))
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadUser', ['userId' => $data->user->id])
);
- $generator->endAttribute('href');
$generator->endObjectElement('User');
$generator->endObjectElement('Session');
diff --git a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/VersionInfo.php b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/VersionInfo.php
index 05462f09184..62da07dc443 100644
--- a/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/VersionInfo.php
+++ b/eZ/Publish/Core/REST/Server/Output/ValueObjectVisitor/VersionInfo.php
@@ -14,6 +14,7 @@
use eZ\Publish\Core\REST\Common\Output\Generator;
use eZ\Publish\Core\REST\Common\Output\Visitor;
use eZ\Publish\API\Repository\Values;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
/**
* VersionInfo value object visitor.
@@ -52,12 +53,9 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$generator->endValueElement('modificationDate');
$generator->startObjectElement('Creator', 'User');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadUser',
- array('userId' => $versionInfo->creatorId))
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadUser', ['userId' => $versionInfo->creatorId])
);
- $generator->endAttribute('href');
$generator->endObjectElement('Creator');
$generator->startValueElement(
@@ -81,11 +79,9 @@ public function visit(Visitor $visitor, Generator $generator, $data)
$this->visitNamesList($generator, $versionInfo->names);
$generator->startObjectElement('Content', 'ContentInfo');
- $generator->startAttribute(
- 'href',
- $this->router->generate('ezpublish_rest_loadContent', array('contentId' => $versionInfo->getContentInfo()->id))
+ $visitor->visitValueObject(
+ new ResourceRouteReference('ezpublish_rest_loadContent', ['contentId' => $versionInfo->getContentInfo()->id])
);
- $generator->endAttribute('href');
$generator->endObjectElement('Content');
$generator->endHashElement('VersionInfo');
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/PathExpansion/ExpansionGeneratorTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/PathExpansion/ExpansionGeneratorTest.php
new file mode 100644
index 00000000000..0ad592d32c3
--- /dev/null
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/PathExpansion/ExpansionGeneratorTest.php
@@ -0,0 +1,217 @@
+buildGenerator()->startDocument('tenant');
+ }
+
+ /**
+ * @expectedException \eZ\Publish\Core\Base\Exceptions\BadStateException
+ */
+ public function testEndDocument()
+ {
+ $this->buildGenerator()->endDocument('tenant');
+ }
+
+ public function testIsEmpty()
+ {
+ $this->getInnerGeneratorMock()
+ ->expects($this->once())
+ ->method('isEmpty');
+
+ $this->buildGenerator()->isEmpty();
+ }
+
+ public function testStartEndObjectElement()
+ {
+ $this->getInnerGeneratorMock()
+ ->expects($this->once())
+ ->method('startObjectElement')
+ ->with('pertwee', 'doctor');
+
+ $this->getInnerGeneratorMock()
+ ->expects($this->once())
+ ->method('endObjectElement')
+ ->with('pertwee');
+
+ $generator = $this->buildGenerator();
+ $generator->startObjectElement('jon', 'doctor');
+ $generator->startObjectElement('pertwee', 'doctor');
+ $generator->endObjectElement('pertwee');
+ $generator->endObjectElement('jon');
+ }
+
+ public function testStartHashElement()
+ {
+ $this->getInnerGeneratorMock()
+ ->expects($this->once())
+ ->method('startHashElement')
+ ->with('baker');
+
+ $this->buildGenerator()->startHashElement('baker');
+ }
+
+ public function testEndHashElement()
+ {
+ $this->getInnerGeneratorMock()
+ ->expects($this->once())
+ ->method('endHashElement')
+ ->with('baker');
+
+ $this->buildGenerator()->endHashElement('baker');
+ }
+
+ public function testStartValueElement()
+ {
+ $this->getInnerGeneratorMock()
+ ->expects($this->once())
+ ->method('startValueElement')
+ ->with('baker', 'paul');
+
+ $this->buildGenerator()->startValueElement('baker', 'paul');
+ }
+
+ public function testEndValueElement()
+ {
+ $this->getInnerGeneratorMock()
+ ->expects($this->once())
+ ->method('endValueElement')
+ ->with('baker');
+
+ $this->buildGenerator()->endValueElement('baker');
+ }
+
+ public function testStartList()
+ {
+ $this->getInnerGeneratorMock()
+ ->expects($this->once())
+ ->method('startList')
+ ->with('hartnell');
+
+ $this->buildGenerator()->startList('hartnell');
+ }
+
+ public function testEndList()
+ {
+ $this->getInnerGeneratorMock()
+ ->expects($this->once())
+ ->method('endList')
+ ->with('hartnell');
+
+ $this->buildGenerator()->endList('hartnell');
+ }
+
+ public function testStartEndAttribute()
+ {
+ $this->getInnerGeneratorMock()
+ ->expects($this->once())
+ ->method('startObjectElement')
+ ->with('eccleston', 'doctor');
+
+ $this->getInnerGeneratorMock()
+ ->expects($this->once())
+ ->method('startAttribute')
+ ->with('jacket', 'leather');
+
+ $generator = $this->buildGenerator();
+
+ $generator->startObjectElement('smith');
+ $generator->startObjectElement('eccleston', 'doctor');
+ $generator->startAttribute('jacket', 'leather');
+ }
+
+ public function testStartEndAttributeAtRoot()
+ {
+ $this->getInnerGeneratorMock()
+ ->expects($this->never())
+ ->method('startObjectElement');
+
+ $this->getInnerGeneratorMock()
+ ->expects($this->once())
+ ->method('startAttribute')
+ ->with('jacket');
+
+ $this->getInnerGeneratorMock()
+ ->expects($this->once())
+ ->method('endAttribute')
+ ->with('jacket');
+
+ $this->buildGenerator()->startObjectElement('eccleston');
+ $this->buildGenerator()->startAttribute('href', 'http://ez.no');
+ $this->buildGenerator()->endAttribute('href');
+ $this->buildGenerator()->startAttribute('media-type', 'application/planet.gallifrey.doctor');
+ $this->buildGenerator()->endAttribute('media-type');
+ $this->buildGenerator()->startAttribute('jacket', 'leather');
+ $this->buildGenerator()->endAttribute('jacket');
+ }
+
+ public function testGetMediaType()
+ {
+ $this->getInnerGeneratorMock()
+ ->expects($this->once())
+ ->method('getMediaType')
+ ->with('foo')
+ ->willReturn('application/vnd.ez.api.foo');
+
+ self::assertEquals('application/vnd.ez.api.foo', $this->buildGenerator()->getMediaType('foo'));
+ }
+
+ public function testGenerateFieldTypeHash()
+ {
+ $this->getInnerGeneratorMock()
+ ->expects($this->once())
+ ->method('generateFieldTypeHash')
+ ->with('smith', []);
+
+ $this->buildGenerator()->generateFieldTypeHash('smith', []);
+ }
+
+ public function testSerializeBool()
+ {
+ $this->getInnerGeneratorMock()
+ ->expects($this->once())
+ ->method('serializeBool')
+ ->with(true)
+ ->willReturn('true');
+
+ self::assertEquals('true', $this->buildGenerator()->serializeBool(true));
+ }
+
+ /**
+ * @return ExpansionGenerator
+ */
+ protected function buildGenerator()
+ {
+ return new ExpansionGenerator($this->getInnerGeneratorMock());
+ }
+
+ /**
+ * @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\Core\REST\Common\Output\Generator
+ */
+ protected function getInnerGeneratorMock()
+ {
+ if (!isset($this->innerGeneratorMock)) {
+ $this->innerGeneratorMock = $this->getMockBuilder('eZ\Publish\Core\REST\Common\Output\Generator')->getMock();
+ }
+
+ return $this->innerGeneratorMock;
+ }
+}
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/PathExpansion/RequestHeaderPathExpansionCheckerTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/PathExpansion/RequestHeaderPathExpansionCheckerTest.php
new file mode 100644
index 00000000000..105c03292a8
--- /dev/null
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/PathExpansion/RequestHeaderPathExpansionCheckerTest.php
@@ -0,0 +1,80 @@
+buildCheckerWithRequestStack(new RequestStack());
+
+ self::assertFalse($checker->needsExpansion('anything'));
+ }
+
+ public function testNoHeader()
+ {
+ $requestStack = new RequestStack();
+ $requestStack->push(new Request());
+
+ $checker = $this->buildCheckerWithRequestStack($requestStack);
+
+ self::assertFalse($checker->needsExpansion('anything'));
+ }
+
+ public function testEmptyHeader()
+ {
+ $checker = $this->buildCheckerWithRequestStack($this->buildRequestStackWithHeader(''));
+
+ self::assertFalse($checker->needsExpansion('anything'));
+ }
+
+ public function testSimpleExpansion()
+ {
+ $checker = $this->buildCheckerWithRequestStack(
+ $this->buildRequestStackWithHeader('Content.MainLocation,Content.Owner')
+ );
+ $checker = $this->buildCheckerWithRequestStack($this->buildRequestStackWithHeader('Content.MainLocation,Content.Owner'));
+
+ self::assertTrue($checker->needsExpansion('Content.MainLocation'));
+ self::assertTrue($checker->needsExpansion('Content.Owner'));
+ self::assertFalse($checker->needsExpansion('Content.SomethingElse'));
+ }
+
+ public function testChildrenExpansion()
+ {
+ $checker = $this->buildCheckerWithRequestStack(
+ $this->buildRequestStackWithHeader('Location.Children.Location.ContentInfo')
+ );
+
+ self::assertTrue($checker->needsExpansion('Location.Children'));
+ self::assertTrue($checker->needsExpansion('Location.Children.Location'));
+ self::assertFalse($checker->needsExpansion('Location.urlAliases'));
+ }
+
+ private function buildRequestStackWithHeader($headerValue)
+ {
+ $requestStack = new RequestStack();
+
+ $request = new Request();
+ $request->headers->set('x-ez-embed-value', $headerValue);
+ $requestStack->push($request);
+
+ return $requestStack;
+ }
+
+ private function buildCheckerWithRequestStack(RequestStack $requestStack)
+ {
+ $checker = new RequestHeaderPathExpansionChecker();
+ $checker->setRequestStack($requestStack);
+
+ return $checker;
+ }
+}
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/PathExpansion/ValueLoaders/ControllerUriValueLoaderTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/PathExpansion/ValueLoaders/ControllerUriValueLoaderTest.php
new file mode 100644
index 00000000000..361de22a729
--- /dev/null
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/PathExpansion/ValueLoaders/ControllerUriValueLoaderTest.php
@@ -0,0 +1,100 @@
+loader = new ControllerUriValueLoader(
+ $this->routerMock = $this->getMock('Symfony\Component\Routing\RouterInterface'),
+ $this->controllerResolverMock = $this->getMock('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface')
+ );
+ }
+
+ /**
+ * Covers the normal behaviour of the load method.
+ */
+ public function testLoad()
+ {
+ $controllerArray = ['_controller' => 'some:controller', 'id' => 1];
+
+ $valueObject = new \stdClass();
+
+ $this->routerMock
+ ->expects($this->once())
+ ->method('match')
+ ->with('/api/ezp/v2/resource/1')
+ ->will($this->returnValue($controllerArray));
+
+ $this->controllerResolverMock
+ ->expects($this->once())
+ ->method('getController')
+ ->will($this->returnValue(
+ function () use ($valueObject) { return $valueObject; }
+ ));
+
+ $this->controllerResolverMock
+ ->expects($this->once())
+ ->method('getArguments')
+ ->will($this->returnValue(['id' => 1]));
+
+ self::assertSame(
+ $valueObject,
+ $this->loader->load('/api/ezp/v2/resource/1')
+ );
+ }
+
+ /**
+ * @expectedException \UnexpectedValueException
+ * @expectedExceptionMessage Expected the controller to return a Value object, got a Response instead
+ */
+ public function testLoadReturnsResponse()
+ {
+ $controllerArray = ['_controller' => 'some:controller', 'id' => 1];
+
+ $valueObject = new Response();
+
+ $this->routerMock
+ ->expects($this->once())
+ ->method('match')
+ ->with('/api/ezp/v2/resource/1')
+ ->will($this->returnValue($controllerArray));
+
+ $this->controllerResolverMock
+ ->expects($this->once())
+ ->method('getController')
+ ->will($this->returnValue(
+ function () use ($valueObject) { return $valueObject; }
+ ));
+
+ $this->controllerResolverMock
+ ->expects($this->once())
+ ->method('getArguments')
+ ->will($this->returnValue(['id' => 1]));
+
+ $this->loader->load('/api/ezp/v2/resource/1');
+ }
+}
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/PathExpansion/ValueLoaders/UniqueUriValueLoaderTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/PathExpansion/ValueLoaders/UniqueUriValueLoaderTest.php
new file mode 100644
index 00000000000..1abe2c93a74
--- /dev/null
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/PathExpansion/ValueLoaders/UniqueUriValueLoaderTest.php
@@ -0,0 +1,59 @@
+buildLoader();
+
+ $returnValue = new stdClass();
+
+ $this->getInnerLoaderMock()
+ ->expects($this->exactly(2))
+ ->method('load')
+ ->withConsecutive(
+ ['/doctors/david-tenant', null],
+ ['/doctors/david-tenant', 'application/other-type']
+ )
+ ->will($this->returnValue($returnValue));
+
+ self::assertEquals($returnValue, $loader->load('/doctors/david-tenant'));
+ self::assertEquals($returnValue, $loader->load('/doctors/david-tenant', 'application/other-type'));
+ $loader->load('/doctors/david-tenant');
+ }
+
+ /**
+ * @return \eZ\Publish\Core\REST\Server\Output\PathExpansion\ValueLoaders\UniqueUriValueLoader
+ */
+ protected function buildLoader()
+ {
+ return new UniqueUriValueLoader($this->getInnerLoaderMock());
+ }
+
+ /**
+ * @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\Core\REST\Server\Output\PathExpansion\ValueLoaders\UriValueLoader
+ */
+ protected function getInnerLoaderMock()
+ {
+ if (!isset($this->innerLoaderMock)) {
+ $this->innerLoaderMock = $this
+ ->getMockBuilder('eZ\Publish\Core\REST\Server\Output\PathExpansion\ValueLoaders\UriValueLoader')
+ ->getMock();
+ }
+
+ return $this->innerLoaderMock;
+ }
+}
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/ContentTypeGroupRefListTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/ContentTypeGroupRefListTest.php
index a335856ef7c..f272e4dab36 100644
--- a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/ContentTypeGroupRefListTest.php
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/ContentTypeGroupRefListTest.php
@@ -15,6 +15,7 @@
use eZ\Publish\Core\Repository\Values\ContentType\ContentType;
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
use eZ\Publish\Core\REST\Server\Values\ContentTypeGroupRefList;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
class ContentTypeGroupRefListTest extends ValueObjectVisitorBaseTest
{
@@ -60,11 +61,11 @@ public function testVisit()
);
// first iteration
- $this->addRouteExpectation(
- 'ezpublish_rest_loadContentTypeGroup',
- array('contentTypeGroupId' => $contentTypeGroupRefList->contentTypeGroups[0]->id),
- "/content/typegroups/{$contentTypeGroupRefList->contentTypeGroups[0]->id}"
- );
+ $this->setVisitValueObjectExpectations([
+ new ResourceRouteReference('ezpublish_rest_loadContentTypeGroup', ['contentTypeGroupId' => $contentTypeGroupRefList->contentTypeGroups[0]->id]),
+ new ResourceRouteReference('ezpublish_rest_loadContentTypeGroup', ['contentTypeGroupId' => $contentTypeGroupRefList->contentTypeGroups[1]->id]),
+ ]);
+
$this->addRouteExpectation(
'ezpublish_rest_unlinkContentTypeFromGroup',
array(
@@ -75,11 +76,6 @@ public function testVisit()
);
// second iteration
- $this->addRouteExpectation(
- 'ezpublish_rest_loadContentTypeGroup',
- array('contentTypeGroupId' => $contentTypeGroupRefList->contentTypeGroups[1]->id),
- "/content/typegroups/{$contentTypeGroupRefList->contentTypeGroups[1]->id}"
- );
$this->addRouteExpectation(
'ezpublish_rest_unlinkContentTypeFromGroup',
array(
@@ -115,26 +111,6 @@ public function testContentTypeGroupRefListHrefCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/ContentTypeGroupRefList[@href="/content/types/42/groups"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisit
- */
- public function testContentTypeGroupRefListMediaTypeCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/ContentTypeGroupRefList[@media-type="application/vnd.ez.api.ContentTypeGroupRefList+xml"]');
- }
-
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisit
- */
- public function testFirstContentTypeGroupRefHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/ContentTypeGroupRefList/ContentTypeGroupRef[1][@href="/content/typegroups/1"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -165,16 +141,6 @@ public function testFirstContentTypeGroupRefUnlinkMethodCorrect(\DOMDocument $do
$this->assertXPath($dom, '/ContentTypeGroupRefList/ContentTypeGroupRef[1]/unlink[@method="DELETE"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisit
- */
- public function testSecondContentTypeGroupRefHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/ContentTypeGroupRefList/ContentTypeGroupRef[2][@href="/content/typegroups/2"]');
- }
-
/**
* @param \DOMDocument $dom
*
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/ContentTypeGroupTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/ContentTypeGroupTest.php
index bba07579262..820275387eb 100644
--- a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/ContentTypeGroupTest.php
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/ContentTypeGroupTest.php
@@ -13,6 +13,7 @@
use eZ\Publish\Core\REST\Common\Tests\Output\ValueObjectVisitorBaseTest;
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
use eZ\Publish\Core\Repository\Values\ContentType;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
class ContentTypeGroupTest extends ValueObjectVisitorBaseTest
{
@@ -50,31 +51,17 @@ public function testVisit()
)
);
- $routerMock = $this->getRouterMock();
-
$this->addRouteExpectation(
'ezpublish_rest_loadContentTypeGroup',
- array('contentTypeGroupId' => $contentTypeGroup->id),
+ ['contentTypeGroupId' => $contentTypeGroup->id],
"/content/typegroups/{$contentTypeGroup->id}"
);
- $this->addRouteExpectation(
- 'ezpublish_rest_loadUser',
- array('userId' => $contentTypeGroup->creatorId),
- "/user/users/{$contentTypeGroup->creatorId}"
- );
-
- $this->addRouteExpectation(
- 'ezpublish_rest_loadUser',
- array('userId' => $contentTypeGroup->modifierId),
- "/user/users/{$contentTypeGroup->modifierId}"
- );
-
- $this->addRouteExpectation(
- 'ezpublish_rest_listContentTypesForGroup',
- array('contentTypeGroupId' => $contentTypeGroup->id),
- "/content/typegroups/{$contentTypeGroup->id}/types"
- );
+ $this->setVisitValueObjectExpectations([
+ new ResourceRouteReference('ezpublish_rest_loadUser', ['userId' => $contentTypeGroup->creatorId]),
+ new ResourceRouteReference('ezpublish_rest_loadUser', ['userId' => $contentTypeGroup->modifierId]),
+ new ResourceRouteReference('ezpublish_rest_listContentTypesForGroup', ['contentTypeGroupId' => $contentTypeGroup->id], 'ContentTypeInfoList'),
+ ]);
$visitor->visit(
$this->getVisitorMock(),
@@ -233,29 +220,6 @@ public function testResultContainsCreatorElement($result)
);
}
- /**
- * Test if result contains Creator element attributes.
- *
- * @param string $result
- *
- * @depends testVisit
- */
- public function testResultContainsCreatorAttributes($result)
- {
- $this->assertXMLTag(
- array(
- 'tag' => 'Creator',
- 'attributes' => array(
- 'href' => '/user/users/14',
- 'media-type' => 'application/vnd.ez.api.User+xml',
- ),
- ),
- $result,
- 'Invalid element attributes.',
- false
- );
- }
-
/**
* Test if result contains Modifier element.
*
@@ -275,29 +239,6 @@ public function testResultContainsModifierElement($result)
);
}
- /**
- * Test if result contains Modifier element attributes.
- *
- * @param string $result
- *
- * @depends testVisit
- */
- public function testResultContainsModifierAttributes($result)
- {
- $this->assertXMLTag(
- array(
- 'tag' => 'Modifier',
- 'attributes' => array(
- 'href' => '/user/users/13',
- 'media-type' => 'application/vnd.ez.api.User+xml',
- ),
- ),
- $result,
- 'Invalid element attributes.',
- false
- );
- }
-
/**
* Test if result contains ContentTypes element.
*
@@ -317,29 +258,6 @@ public function testResultContainsContentTypesElement($result)
);
}
- /**
- * Test if result contains ContentTypes element attributes.
- *
- * @param string $result
- *
- * @depends testVisit
- */
- public function testResultContainsContentTypesAttributes($result)
- {
- $this->assertXMLTag(
- array(
- 'tag' => 'ContentTypes',
- 'attributes' => array(
- 'href' => '/content/typegroups/42/types',
- 'media-type' => 'application/vnd.ez.api.ContentTypeInfoList+xml',
- ),
- ),
- $result,
- 'Invalid attributes.',
- false
- );
- }
-
/**
* Get the ContentTypeGroup visitor.
*
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/ObjectStateGroupTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/ObjectStateGroupTest.php
index 7847b963c1c..3a60f2f48a5 100644
--- a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/ObjectStateGroupTest.php
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/ObjectStateGroupTest.php
@@ -13,6 +13,7 @@
use eZ\Publish\Core\REST\Common\Tests\Output\ValueObjectVisitorBaseTest;
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
use eZ\Publish\Core\Repository\Values\ObjectState;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
class ObjectStateGroupTest extends ValueObjectVisitorBaseTest
{
@@ -51,11 +52,9 @@ public function testVisit()
"/content/objectstategroups/$objectStateGroup->id"
);
- $this->addRouteExpectation(
- 'ezpublish_rest_loadObjectStates',
- array('objectStateGroupId' => $objectStateGroup->id),
- "/content/objectstategroups/$objectStateGroup->id/objectstates"
- );
+ $this->setVisitValueObjectExpectations([
+ new ResourceRouteReference('ezpublish_rest_loadObjectStates', ['objectStateGroupId' => $objectStateGroup->id]),
+ ]);
$visitor->visit(
$this->getVisitorMock(),
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/ResourceLinkTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/ResourceLinkTest.php
new file mode 100644
index 00000000000..a7a198c552b
--- /dev/null
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/ResourceLinkTest.php
@@ -0,0 +1,268 @@
+getVisitor();
+ $generator = $this->getGenerator();
+
+ $generator->startDocument(null);
+ $generator->startObjectElement('SomeRoot');
+ $generator->startObjectElement('SomeObject');
+
+ $this->getPathExpansionCheckerMock()
+ ->expects($this->once())
+ ->method('needsExpansion')
+ ->with('SomeRoot.SomeObject')
+ ->will($this->returnValue(true));
+
+ $this->getValueLoaderMock()
+ ->expects($this->once())
+ ->method('load')
+ ->with($resourceLink->link, $resourceLink->mediaType)
+ ->will($this->returnValue($loadedValue = new \stdClass()));
+
+ $this->getValueObjectVisitorDispatcherMock()
+ ->expects($this->once())
+ ->method('visit')
+ ->with(
+ $loadedValue,
+ $this->isInstanceOf('eZ\Publish\Core\REST\Server\Output\PathExpansion\ExpansionGenerator'),
+ $this->getVisitorMock()
+ );
+
+ $visitor->visit($this->getVisitorMock(), $generator, $resourceLink);
+
+ $generator->endObjectElement('SomeObject');
+ $generator->endObjectElement('SomeRoot');
+
+ $result = $generator->endDocument(null);
+
+ $this->assertNotNull($result);
+
+ $dom = new \DOMDocument();
+ $dom->loadXml($result);
+
+ $this->assertXPath($dom, '//SomeObject[@href="' . $resourceLink->link . '"]');
+ $this->assertXPath($dom, '//SomeObject[@media-type="application/vnd.ez.api.SomeObject+xml"]');
+ }
+
+ /**
+ * @param ResourceLinkValue $resourceLink
+ * @dataProvider buildValueObject
+ */
+ public function testVisitWithNoExpansion(ResourceLinkValue $resourceLink)
+ {
+ $visitor = $this->getVisitor();
+ $generator = $this->getGenerator();
+
+ $generator->startDocument(null);
+ $generator->startObjectElement('SomeRoot');
+ $generator->startObjectElement('SomeObject');
+
+ $this->getPathExpansionCheckerMock()
+ ->expects($this->once())
+ ->method('needsExpansion')
+ ->with('SomeRoot.SomeObject')
+ ->will($this->returnValue(false));
+
+ $this->getValueLoaderMock()
+ ->expects($this->never())
+ ->method('load');
+
+ $this->getValueObjectVisitorDispatcherMock()
+ ->expects($this->never())
+ ->method('visit');
+
+ $visitor->visit($this->getVisitorMock(), $generator, $resourceLink);
+
+ $generator->endObjectElement('SomeObject');
+ $generator->endObjectElement('SomeRoot');
+
+ $result = $generator->endDocument(null);
+
+ $this->assertNotNull($result);
+
+ $dom = new \DOMDocument();
+ $dom->loadXml($result);
+
+ $this->assertXPath($dom, '//SomeObject[@href="' . $resourceLink->link . '"]');
+ $this->assertXPath($dom, '//SomeObject[@media-type="application/vnd.ez.api.SomeObject+xml"]');
+ }
+
+ /**
+ * @dataProvider buildValueObject
+ */
+ public function testVisitUnauthorizedException(ResourceLinkValue $resourceLink)
+ {
+ $visitor = $this->getVisitor();
+ $generator = $this->getGenerator();
+
+ $generator->startDocument(null);
+ $generator->startObjectElement('SomeRoot');
+ $generator->startObjectElement('SomeObject');
+
+ $this->getPathExpansionCheckerMock()
+ ->expects($this->once())
+ ->method('needsExpansion')
+ ->with('SomeRoot.SomeObject')
+ ->will($this->returnValue(true));
+
+ $this->getValueLoaderMock()
+ ->expects($this->once())
+ ->method('load')
+ ->will($this->throwException(new UnauthorizedException('something', 'load')));
+
+ $this->getValueObjectVisitorDispatcherMock()
+ ->expects($this->never())
+ ->method('visit');
+
+ $visitor->visit($this->getVisitorMock(), $generator, $resourceLink);
+
+ $generator->endObjectElement('SomeObject');
+ $generator->endObjectElement('SomeRoot');
+
+ $result = $generator->endDocument(null);
+
+ $this->assertNotNull($result);
+
+ $dom = new \DOMDocument();
+ $dom->loadXml($result);
+
+ $this->assertXPath($dom, '//SomeObject[@href="' . $resourceLink->link . '"]');
+ $this->assertXPath($dom, '//SomeObject[@media-type="application/vnd.ez.api.SomeObject+xml"]');
+ $this->assertXPath($dom, '//SomeObject[@embed-error="User does not have access to \'load\' \'something\'"]');
+ }
+
+ /**
+ * @dataProvider buildValueObject
+ */
+ public function testVisitMultipleLoadException(ResourceLinkValue $resourceLink)
+ {
+ $visitor = $this->getVisitor();
+ $generator = $this->getGenerator();
+
+ $generator->startDocument(null);
+ $generator->startObjectElement('SomeRoot');
+ $generator->startObjectElement('SomeObject');
+
+ $this->getPathExpansionCheckerMock()
+ ->expects($this->once())
+ ->method('needsExpansion')
+ ->with('SomeRoot.SomeObject')
+ ->will($this->returnValue(true));
+
+ $this->getValueLoaderMock()
+ ->expects($this->once())
+ ->method('load')
+ ->will($this->throwException(new MultipleValueLoadException()));
+
+ $this->getValueObjectVisitorDispatcherMock()
+ ->expects($this->never())
+ ->method('visit');
+
+ $visitor->visit($this->getVisitorMock(), $generator, $resourceLink);
+
+ $generator->endObjectElement('SomeObject');
+ $generator->endObjectElement('SomeRoot');
+
+ $result = $generator->endDocument(null);
+
+ $this->assertNotNull($result);
+
+ $dom = new \DOMDocument();
+ $dom->loadXml($result);
+
+ $this->assertXPath($dom, '//SomeObject[@href="' . $resourceLink->link . '"]');
+ $this->assertXPath($dom, '//SomeObject[@media-type="application/vnd.ez.api.SomeObject+xml"]');
+ $this->assertXPath($dom, '//SomeObject[@embed-error="Value was already loaded"]');
+ }
+
+ public function testVisitCircularLoadException()
+ {
+ self::markTestIncomplete('@todo Implement feature');
+ }
+
+ public function buildValueObject()
+ {
+ return [
+ [new ResourceLinkValue('/api/ezp/v2/resource')],
+ ];
+ }
+
+ /**
+ * Must return an instance of the tested visitor object.
+ *
+ * @return \eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor
+ */
+ protected function internalGetVisitor()
+ {
+ return new ResourceLink(
+ $this->getValueLoaderMock(),
+ $this->getPathExpansionCheckerMock(),
+ $this->getValueObjectVisitorDispatcherMock()
+ );
+ }
+
+ /**
+ * @return \eZ\Publish\Core\REST\Server\Output\PathExpansion\ValueLoaders\UriValueLoader|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected function getValueLoaderMock()
+ {
+ if ($this->valueLoaderMock === null) {
+ $this->valueLoaderMock = $this
+ ->getMockBuilder('eZ\Publish\Core\REST\Server\Output\PathExpansion\ValueLoaders\UriValueLoader')
+ ->getMock();
+ }
+
+ return $this->valueLoaderMock;
+ }
+
+ /**
+ * @return \eZ\Publish\Core\REST\Server\Output\PathExpansion\PathExpansionChecker|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected function getPathExpansionCheckerMock()
+ {
+ if ($this->pathExpansionCheckerMock === null) {
+ $this->pathExpansionCheckerMock = $this
+ ->getMockBuilder('eZ\Publish\Core\REST\Server\Output\PathExpansion\PathExpansionChecker')
+ ->getMock();
+ }
+
+ return $this->pathExpansionCheckerMock;
+ }
+
+ /**
+ * @return \eZ\Publish\Core\REST\Common\Output\ValueObjectVisitorDispatcher|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected function getValueObjectVisitorDispatcherMock()
+ {
+ if ($this->valueObjectVisitorDispatcherMock === null) {
+ $this->valueObjectVisitorDispatcherMock = $this
+ ->getMockBuilder('eZ\Publish\Core\REST\Common\Output\ValueObjectVisitorDispatcher')
+ ->getMock();
+ }
+
+ return $this->valueObjectVisitorDispatcherMock;
+ }
+}
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestContentTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestContentTest.php
index 72cb0d58440..94342ecbfef 100644
--- a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestContentTest.php
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestContentTest.php
@@ -11,6 +11,7 @@
namespace eZ\Publish\Core\REST\Server\Tests\Output\ValueObjectVisitor;
use eZ\Publish\Core\REST\Common\Tests\Output\ValueObjectVisitorBaseTest;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
use eZ\Publish\Core\REST\Server\Values\RestContent;
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
use eZ\Publish\Core\Repository\Values;
@@ -30,54 +31,21 @@ public function testVisitWithoutEmbeddedVersion()
$restContent = $this->getBasicRestContent();
- $this->getVisitorMock()->expects($this->never())
- ->method('visitValueObject');
-
$this->addRouteExpectation(
'ezpublish_rest_loadContent',
array('contentId' => $restContent->contentInfo->id),
"/content/objects/{$restContent->contentInfo->id}"
);
- $this->addRouteExpectation(
- 'ezpublish_rest_loadContentType',
- array('contentTypeId' => $restContent->contentInfo->contentTypeId),
- "/content/types/{$restContent->contentInfo->contentTypeId}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadContentVersions',
- array('contentId' => $restContent->contentInfo->id),
- "/content/objects/{$restContent->contentInfo->id}/versions"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_redirectCurrentVersion',
- array('contentId' => $restContent->contentInfo->id),
- "/content/objects/{$restContent->contentInfo->id}/currentversion"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadSection',
- array('sectionId' => $restContent->contentInfo->sectionId),
- "/content/sections/{$restContent->contentInfo->sectionId}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadLocation',
- array('locationPath' => $locationPath = trim($restContent->mainLocation->pathString, '/')),
- "/content/locations/{$locationPath}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadLocationsForContent',
- array('contentId' => $restContent->contentInfo->id),
- "/content/objects/{$restContent->contentInfo->id}/locations"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadUser',
- array('userId' => $restContent->contentInfo->ownerId),
- "/user/users/{$restContent->contentInfo->ownerId}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_getObjectStatesForContent',
- array('contentId' => $restContent->contentInfo->id),
- "/content/objects/{$restContent->contentInfo->id}/objectstates"
- );
+ $this->setVisitValueObjectExpectations([
+ new ResourceRouteReference('ezpublish_rest_loadContentType', ['contentTypeId' => $restContent->contentInfo->contentTypeId]),
+ new ResourceRouteReference('ezpublish_rest_loadContentVersions', ['contentId' => $restContent->contentInfo->id]),
+ new ResourceRouteReference('ezpublish_rest_redirectCurrentVersion', ['contentId' => $restContent->contentInfo->id]),
+ new ResourceRouteReference('ezpublish_rest_loadSection', ['sectionId' => $restContent->contentInfo->sectionId]),
+ new ResourceRouteReference('ezpublish_rest_loadLocation', ['locationPath' => $locationPath = trim($restContent->mainLocation->pathString, '/')]),
+ new ResourceRouteReference('ezpublish_rest_loadLocationsForContent', ['contentId' => $restContent->contentInfo->id]),
+ new ResourceRouteReference('ezpublish_rest_loadUser', ['userId' => $restContent->contentInfo->ownerId]),
+ new ResourceRouteReference('ezpublish_rest_getObjectStatesForContent', ['contentId' => $restContent->contentInfo->id]),
+ ]);
$visitor->visit(
$this->getVisitorMock(),
@@ -164,16 +132,6 @@ public function testContentRemoteIdCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/Content[@remoteId="abc123"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testContentTypeHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/Content/ContentType[@href="/content/types/contentType23"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -194,16 +152,6 @@ public function testNameCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/Content/Name[text()="Sindelfingen"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testVersionsHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/Content/Versions[@href="/content/objects/content23/versions"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -214,16 +162,6 @@ public function testVersionsMediaTypeCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/Content/Versions[@media-type="application/vnd.ez.api.VersionList+xml"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testCurrentVersionHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/Content/CurrentVersion[@href="/content/objects/content23/currentversion"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -234,16 +172,6 @@ public function testCurrentVersionMediaTypeCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/Content/CurrentVersion[@media-type="application/vnd.ez.api.Version+xml"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testSectionHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/Content/Section[@href="/content/sections/section23"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -254,16 +182,6 @@ public function testSectionMediaTypeCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/Content/Section[@media-type="application/vnd.ez.api.Section+xml"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testMainLocationHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/Content/MainLocation[@href="/content/locations/1/2/23"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -274,16 +192,6 @@ public function testMainLocationMediaTypeCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/Content/MainLocation[@media-type="application/vnd.ez.api.Location+xml"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testLocationsHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/Content/Locations[@href="/content/objects/content23/locations"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -294,16 +202,6 @@ public function testLocationsMediaTypeCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/Content/Locations[@media-type="application/vnd.ez.api.LocationList+xml"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testOwnerHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/Content/Owner[@href="/user/users/user23"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -376,51 +274,21 @@ public function testVisitWithEmbeddedVersion()
'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentType'
);
- $this->getVisitorMock()->expects($this->once())
- ->method('visitValueObject')
- ->with($this->isInstanceOf('eZ\\Publish\\Core\\REST\\Server\\Values\\Version'));
-
$this->addRouteExpectation(
'ezpublish_rest_loadContent',
array('contentId' => $restContent->contentInfo->id),
"/content/objects/{$restContent->contentInfo->id}"
);
- $this->addRouteExpectation(
- 'ezpublish_rest_loadContentType',
- array('contentTypeId' => $restContent->contentInfo->contentTypeId),
- "/content/types/{$restContent->contentInfo->contentTypeId}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadContentVersions',
- array('contentId' => $restContent->contentInfo->id),
- "/content/objects/{$restContent->contentInfo->id}/versions"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_redirectCurrentVersion',
- array('contentId' => $restContent->contentInfo->id),
- "/content/objects/{$restContent->contentInfo->id}/currentversion"
- );
-
- $this->addRouteExpectation(
- 'ezpublish_rest_loadSection',
- array('sectionId' => $restContent->contentInfo->sectionId),
- "/content/sections/{$restContent->contentInfo->sectionId}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadLocation',
- array('locationPath' => $locationPath = trim($restContent->mainLocation->pathString, '/')),
- "/content/locations/{$locationPath}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadLocationsForContent',
- array('contentId' => $restContent->contentInfo->id),
- "/content/objects/{$restContent->contentInfo->id}/locations"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadUser',
- array('userId' => $restContent->contentInfo->ownerId),
- "/user/users/{$restContent->contentInfo->ownerId}"
- );
+ $this->setVisitValueObjectExpectations([
+ new ResourceRouteReference('ezpublish_rest_loadContentType', ['contentTypeId' => $restContent->contentInfo->contentTypeId]),
+ new ResourceRouteReference('ezpublish_rest_loadContentVersions', ['contentId' => $restContent->contentInfo->id]),
+ new ResourceRouteReference('ezpublish_rest_redirectCurrentVersion', ['contentId' => $restContent->contentInfo->id]),
+ $this->isInstanceOf('eZ\Publish\Core\REST\Server\Values\Version'),
+ new ResourceRouteReference('ezpublish_rest_loadSection', ['sectionId' => $restContent->contentInfo->sectionId]),
+ new ResourceRouteReference('ezpublish_rest_loadLocation', ['locationPath' => $locationPath = trim($restContent->mainLocation->pathString, '/')]),
+ new ResourceRouteReference('ezpublish_rest_loadLocationsForContent', ['contentId' => $restContent->contentInfo->id]),
+ new ResourceRouteReference('ezpublish_rest_loadUser', ['userId' => $restContent->contentInfo->ownerId]),
+ ]);
$visitor->visit(
$this->getVisitorMock(),
@@ -448,16 +316,6 @@ public function testContentMediaTypeWithVersionCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/Content[@media-type="application/vnd.ez.api.Content+xml"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithEmbeddedVersion
- */
- public function testEmbeddedCurrentVersionHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/Content/CurrentVersion[@href="/content/objects/content23/currentversion"]');
- }
-
/**
* @param \DOMDocument $dom
*
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestContentTypeTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestContentTypeTest.php
index dfd81adb83b..c00ae877982 100644
--- a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestContentTypeTest.php
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestContentTypeTest.php
@@ -13,6 +13,7 @@
use eZ\Publish\Core\REST\Common\Tests\Output\ValueObjectVisitorBaseTest;
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
use eZ\Publish\Core\Repository\Values;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
use eZ\Publish\Core\REST\Server\Values\RestContentType;
/**
@@ -33,35 +34,19 @@ public function testVisitDefinedType()
$restContentType = $this->getBasicContentType();
- $this->getVisitorMock()->expects($this->once())
- ->method('visitValueObject')
- ->with($this->isInstanceOf('eZ\\Publish\\Core\\REST\\Server\\Values\\FieldDefinitionList'));
-
$this->addRouteExpectation(
'ezpublish_rest_loadContentType',
array('contentTypeId' => $restContentType->contentType->id),
"/content/types/{$restContentType->contentType->id}"
);
- $this->addRouteExpectation(
- 'ezpublish_rest_loadUser',
- array('userId' => $restContentType->contentType->creatorId),
- "/user/users/{$restContentType->contentType->creatorId}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadUser',
- array('userId' => $restContentType->contentType->modifierId),
- "/user/users/{$restContentType->contentType->modifierId}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadGroupsOfContentType',
- array('contentTypeId' => $restContentType->contentType->id),
- "/content/types/{$restContentType->contentType->id}/groups"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadContentTypeDraft',
- array('contentTypeId' => $restContentType->contentType->id),
- "/content/types/{$restContentType->contentType->id}/draft"
- );
+
+ $this->setVisitValueObjectExpectations([
+ $this->isInstanceOf('eZ\Publish\Core\REST\Server\Values\FieldDefinitionList'),
+ new ResourceRouteReference('ezpublish_rest_loadUser', ['userId' => $restContentType->contentType->creatorId]),
+ new ResourceRouteReference('ezpublish_rest_loadUser', ['userId' => $restContentType->contentType->modifierId]),
+ new ResourceRouteReference('ezpublish_rest_loadGroupsOfContentType', ['contentTypeId' => $restContentType->contentType->id]),
+ new ResourceRouteReference('ezpublish_rest_loadContentTypeDraft', ['contentTypeId' => $restContentType->contentType->id]),
+ ]);
$visitor->visit(
$this->getVisitorMock(),
@@ -111,16 +96,6 @@ protected function getBasicContentType()
);
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitDefinedType
- */
- public function testContentTypeHref(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/ContentType[@href="/content/types/contentTypeId"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -221,16 +196,6 @@ public function testModificationDate(\DOMDocument $dom)
$this->assertXPath($dom, '/ContentType/modificationDate[text()="2012-09-06T19:32:00+02:00"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitDefinedType
- */
- public function testCreatorHref(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/ContentType/Creator[@href="/user/users/creatorId"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -241,16 +206,6 @@ public function testCreatorMediaType(\DOMDocument $dom)
$this->assertXPath($dom, '/ContentType/Creator[@media-type="application/vnd.ez.api.User+xml"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitDefinedType
- */
- public function testModifierHref(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/ContentType/Modifier[@href="/user/users/modifierId"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -261,16 +216,6 @@ public function testModifierMediaType(\DOMDocument $dom)
$this->assertXPath($dom, '/ContentType/Modifier[@media-type="application/vnd.ez.api.User+xml"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitDefinedType
- */
- public function testDraftHref(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/ContentType/Draft[@href="/content/types/contentTypeId/draft"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -281,16 +226,6 @@ public function testDraftType(\DOMDocument $dom)
$this->assertXPath($dom, '/ContentType/Draft[@media-type="application/vnd.ez.api.ContentType+xml"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitDefinedType
- */
- public function testGroupsHref(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/ContentType/Groups[@href="/content/types/contentTypeId/groups"]');
- }
-
/**
* @param \DOMDocument $dom
*
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestExecutedViewTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestExecutedViewTest.php
index 7a5a53ad9dc..11905b36710 100644
--- a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestExecutedViewTest.php
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestExecutedViewTest.php
@@ -16,6 +16,7 @@
use eZ\Publish\Core\REST\Common\Tests\Output\ValueObjectVisitorBaseTest;
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
use eZ\Publish\Core\Repository\Values\Content;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
use eZ\Publish\Core\REST\Server\Values\RestExecutedView;
use eZ\Publish\Core\Repository\Values\Content as ApiValues;
@@ -50,11 +51,9 @@ public function testVisit()
array('viewId' => $view->identifier),
"/content/views/{$view->identifier}"
);
- $this->addRouteExpectation(
- 'ezpublish_rest_views_load_results',
- array('viewId' => $view->identifier),
- "/content/views/{$view->identifier}/results"
- );
+ $this->setVisitValueObjectExpectations([
+ new ResourceRouteReference('ezpublish_rest_views_load_results', ['viewId' => $view->identifier]),
+ ]);
$visitor->visit(
$this->getVisitorMock(),
@@ -84,7 +83,6 @@ public function provideXpathAssertions()
array('/View/Query[@media-type="application/vnd.ez.api.Query+xml"]'),
array('/View/Result'),
array('/View/Result[@media-type="application/vnd.ez.api.ViewResult+xml"]'),
- array('/View/Result[@href="/content/views/test_view/results"]'),
);
}
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestLocationRootNodeTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestLocationRootNodeTest.php
index 95f0e171a38..3620af059c5 100644
--- a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestLocationRootNodeTest.php
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestLocationRootNodeTest.php
@@ -11,6 +11,7 @@
namespace eZ\Publish\Core\REST\Server\Tests\Output\ValueObjectVisitor;
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
use eZ\Publish\Core\REST\Server\Values\RestLocation;
use eZ\Publish\Core\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
@@ -60,31 +61,14 @@ public function testVisit()
array('locationPath' => '1'),
'/content/locations/1'
);
- $this->addRouteExpectation(
- 'ezpublish_rest_loadLocationChildren',
- array('locationPath' => '1'),
- '/content/locations/1/children'
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadContent',
- array('contentId' => $location->location->contentId),
- "/content/objects/{$location->location->contentId}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_listLocationURLAliases',
- array('locationPath' => '1'),
- '/content/objects/1/urlaliases'
- );
-
- $this->addRouteExpectation(
- 'ezpublish_rest_loadContent',
- array('contentId' => $location->location->contentId),
- "/content/objects/{$location->location->contentId}"
- );
- $this->getVisitorMock()->expects($this->once())
- ->method('visitValueObject')
- ->with($this->isInstanceOf('eZ\\Publish\\Core\\REST\\Server\\Values\\RestContent'));
+ $this->setVisitValueObjectExpectations([
+ new ResourceRouteReference('ezpublish_rest_loadLocationChildren', array('locationPath' => '1')),
+ new ResourceRouteReference('ezpublish_rest_loadContent', array('contentId' => $location->location->contentId)),
+ new ResourceRouteReference('ezpublish_rest_listLocationURLAliases', array('locationPath' => '1')),
+ new ResourceRouteReference('ezpublish_rest_loadContent', array('contentId' => $location->location->contentId), 'ContentInfo'),
+ $this->isInstanceOf('eZ\Publish\Core\REST\Server\Values\RestContent'),
+ ]);
$visitor->visit(
$this->getVisitorMock(),
@@ -195,7 +179,6 @@ public function testResultContainsChildrenAttributes($result)
'tag' => 'Children',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.LocationList+xml',
- 'href' => '/content/locations/1/children',
),
),
$result,
@@ -238,7 +221,6 @@ public function testResultContainsUrlAliasesTagAttributes($result)
'tag' => 'UrlAliases',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.UrlAliasRefList+xml',
- 'href' => '/content/objects/1/urlaliases',
),
),
$result,
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestLocationTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestLocationTest.php
index f5c6d8d3b1a..889dccbf660 100644
--- a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestLocationTest.php
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestLocationTest.php
@@ -12,6 +12,7 @@
use eZ\Publish\Core\REST\Common\Tests\Output\ValueObjectVisitorBaseTest;
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
use eZ\Publish\Core\REST\Server\Values\RestLocation;
use eZ\Publish\Core\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
@@ -56,42 +57,15 @@ public function testVisit()
0
);
- $this->addRouteExpectation(
- 'ezpublish_rest_loadLocation',
- array('locationPath' => '1/2/21/42'),
- '/content/locations/1/2/21/42'
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadLocation',
- array('locationPath' => '1/2/21'),
- '/content/locations/1/2/21'
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadLocationChildren',
- array('locationPath' => '1/2/21/42'),
- '/content/locations/1/2/21/42/children'
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadContent',
- array('contentId' => $location->location->contentId),
- "/content/objects/{$location->location->contentId}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_listLocationURLAliases',
- array('locationPath' => '1/2/21/42'),
- '/content/objects/1/2/21/42/urlaliases'
- );
-
- // Expected twice, second one here for ContentInfo
- $this->addRouteExpectation(
- 'ezpublish_rest_loadContent',
- array('contentId' => $location->location->contentId),
- "/content/objects/{$location->location->contentId}"
- );
-
- $this->getVisitorMock()->expects($this->once())
- ->method('visitValueObject')
- ->with($this->isInstanceOf('eZ\\Publish\\Core\\REST\\Server\\Values\\RestContent'));
+ $this->setVisitValueObjectExpectations([
+ new ResourceRouteReference('ezpublish_rest_loadLocation', ['locationPath' => '1/2/21/42']),
+ new ResourceRouteReference('ezpublish_rest_loadLocation', ['locationPath' => '1/2/21']),
+ new ResourceRouteReference('ezpublish_rest_loadLocationChildren', ['locationPath' => '1/2/21/42']),
+ new ResourceRouteReference('ezpublish_rest_loadContent', ['contentId' => $location->location->contentId]),
+ new ResourceRouteReference('ezpublish_rest_listLocationURLAliases', ['locationPath' => '1/2/21/42']),
+ new ResourceRouteReference('ezpublish_rest_loadContent', ['contentId' => $location->location->contentId]),
+ $this->isInstanceOf('eZ\Publish\Core\REST\Server\Values\RestContent'),
+ ]);
$visitor->visit(
$this->getVisitorMock(),
@@ -139,7 +113,6 @@ public function testResultContainsLocationAttributes($result)
'tag' => 'Location',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.Location+xml',
- 'href' => '/content/locations/1/2/21/42',
),
),
$result,
@@ -181,7 +154,6 @@ public function testResultContainsContentInfoAttributes($result)
'tag' => 'ContentInfo',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.ContentInfo+xml',
- 'href' => '/content/objects/42',
),
),
$result,
@@ -323,7 +295,6 @@ public function testResultContainsChildrenAttributes($result)
'tag' => 'Children',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.LocationList+xml',
- 'href' => '/content/locations/1/2/21/42/children',
),
),
$result,
@@ -365,7 +336,6 @@ public function testResultContainsParentLocationAttributes($result)
'tag' => 'ParentLocation',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.Location+xml',
- 'href' => '/content/locations/1/2/21',
),
),
$result,
@@ -407,7 +377,6 @@ public function testResultContainsContentAttributes($result)
'tag' => 'Content',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.Content+xml',
- 'href' => '/content/objects/42',
),
),
$result,
@@ -549,7 +518,6 @@ public function testResultContainsUrlAliasesTagAttributes($result)
'tag' => 'UrlAliases',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.UrlAliasRefList+xml',
- 'href' => '/content/objects/1/2/21/42/urlaliases',
),
),
$result,
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestObjectStateTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestObjectStateTest.php
index 7131d85bfce..2afedd6607e 100644
--- a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestObjectStateTest.php
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestObjectStateTest.php
@@ -14,6 +14,7 @@
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
use eZ\Publish\Core\Repository\Values\ObjectState\ObjectState;
use eZ\Publish\Core\REST\Common\Values;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
class RestObjectStateTest extends ValueObjectVisitorBaseTest
{
@@ -55,11 +56,9 @@ public function testVisit()
array('objectStateGroupId' => $objectState->groupId, 'objectStateId' => $objectState->objectState->id),
"/content/objectstategroups/{$objectState->groupId}/objectstates/{$objectState->objectState->id}"
);
- $this->addRouteExpectation(
- 'ezpublish_rest_loadObjectStateGroup',
- array('objectStateGroupId' => $objectState->groupId),
- "/content/objectstategroups/{$objectState->groupId}"
- );
+ $this->setVisitValueObjectExpectations([
+ new ResourceRouteReference('ezpublish_rest_loadObjectStateGroup', ['objectStateGroupId' => $objectState->groupId]),
+ ]);
$visitor->visit(
$this->getVisitorMock(),
@@ -110,7 +109,6 @@ public function testResultContainsObjectStateAttributes($result)
'tag' => 'ObjectState',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.ObjectState+xml',
- 'href' => '/content/objectstategroups/21/objectstates/42',
),
),
$result,
@@ -152,7 +150,6 @@ public function testResultContainsObjectStateGroupAttributes($result)
'tag' => 'ObjectStateGroup',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.ObjectStateGroup+xml',
- 'href' => '/content/objectstategroups/21',
),
),
$result,
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestRelationTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestRelationTest.php
index f4f7b17e1af..a993f575c22 100644
--- a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestRelationTest.php
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestRelationTest.php
@@ -13,6 +13,7 @@
use eZ\Publish\Core\REST\Common\Tests\Output\ValueObjectVisitorBaseTest;
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
use eZ\Publish\Core\Repository\Values\Content;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
use eZ\Publish\Core\REST\Server\Values\RestRelation;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
@@ -61,16 +62,10 @@ public function testVisit()
),
"/content/objects/{$relation->contentId}/versions/{$relation->versionNo}/relations/{$relation->relation->id}"
);
- $this->addRouteExpectation(
- 'ezpublish_rest_loadContent',
- array('contentId' => $relation->contentId),
- "/content/objects/{$relation->contentId}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadContent',
- array('contentId' => $relation->relation->getDestinationContentInfo()->id),
- "/content/objects/{$relation->relation->getDestinationContentInfo()->id}"
- );
+ $this->setVisitValueObjectExpectations([
+ new ResourceRouteReference('ezpublish_rest_loadContent', ['contentId' => $relation->contentId]),
+ new ResourceRouteReference('ezpublish_rest_loadContent', ['contentId' => $relation->relation->getDestinationContentInfo()->id]),
+ ]);
$visitor->visit(
$this->getVisitorMock(),
@@ -122,7 +117,6 @@ public function testResultContainsRelationAttributes($result)
'tag' => 'Relation',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.Relation+xml',
- 'href' => '/content/objects/1/versions/1/relations/42',
),
),
$result,
@@ -143,7 +137,6 @@ public function testResultContainsSourceContentElement($result)
'tag' => 'SourceContent',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.ContentInfo+xml',
- 'href' => '/content/objects/1',
),
),
$result,
@@ -164,7 +157,6 @@ public function testResultContainsDestinationContentElement($result)
'tag' => 'DestinationContent',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.ContentInfo+xml',
- 'href' => '/content/objects/2',
),
),
$result,
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestTrashItemTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestTrashItemTest.php
index 5d5be003e35..654547765dc 100644
--- a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestTrashItemTest.php
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestTrashItemTest.php
@@ -12,6 +12,7 @@
use eZ\Publish\Core\REST\Common\Tests\Output\ValueObjectVisitorBaseTest;
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
use eZ\Publish\Core\REST\Server\Values\RestTrashItem;
use eZ\Publish\Core\Repository\Values\Content\TrashItem;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
@@ -61,28 +62,12 @@ public function testVisit()
array('trashItemId' => $trashItem->trashItem->id),
"/content/trash/{$trashItem->trashItem->id}"
);
- $this->addRouteExpectation(
- 'ezpublish_rest_loadLocation',
- array('locationPath' => '1/2/21'),
- '/content/locations/1/2/21'
- );
-
- $this->addRouteExpectation(
- 'ezpublish_rest_loadContent',
- array('contentId' => $trashItem->trashItem->contentInfo->id),
- "/content/objects/{$trashItem->trashItem->contentInfo->id}"
- );
-
- // Expected twice, second one here for ContentInfo
- $this->addRouteExpectation(
- 'ezpublish_rest_loadContent',
- array('contentId' => $trashItem->trashItem->contentInfo->id),
- "/content/objects/{$trashItem->trashItem->contentInfo->id}"
- );
-
- $this->getVisitorMock()->expects($this->once())
- ->method('visitValueObject')
- ->with($this->isInstanceOf('eZ\\Publish\\Core\\REST\\Server\\Values\\RestContent'));
+ $this->setVisitValueObjectExpectations([
+ new ResourceRouteReference('ezpublish_rest_loadLocation', ['locationPath' => '1/2/21']),
+ new ResourceRouteReference('ezpublish_rest_loadContent', ['contentId' => $trashItem->trashItem->contentInfo->id]),
+ new ResourceRouteReference('ezpublish_rest_loadContent', ['contentId' => $trashItem->trashItem->contentInfo->id]),
+ $this->isInstanceOf('eZ\Publish\Core\REST\Server\Values\RestContent'),
+ ]);
$visitor->visit(
$this->getVisitorMock(),
@@ -133,7 +118,6 @@ public function testResultContainsTrashItemAttributes($result)
'tag' => 'TrashItem',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.TrashItem+xml',
- 'href' => '/content/trash/42',
),
),
$result,
@@ -175,7 +159,6 @@ public function testResultContainsContentInfoAttributes($result)
'tag' => 'ContentInfo',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.ContentInfo+xml',
- 'href' => '/content/objects/84',
),
),
$result,
@@ -317,7 +300,6 @@ public function testResultContainsParentLocationAttributes($result)
'tag' => 'ParentLocation',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.Location+xml',
- 'href' => '/content/locations/1/2/21',
),
),
$result,
@@ -419,7 +401,6 @@ public function testResultContainsContentAttributes($result)
'tag' => 'Content',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.Content+xml',
- 'href' => '/content/objects/84',
),
),
$result,
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestUserGroupRoleAssignmentTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestUserGroupRoleAssignmentTest.php
index f74ac66e3c0..76af4d72dc4 100644
--- a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestUserGroupRoleAssignmentTest.php
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestUserGroupRoleAssignmentTest.php
@@ -51,11 +51,9 @@ public function testVisit()
),
"/user/groups/1/5/14/roles/{$userGroupRoleAssignment->roleAssignment->role->id}"
);
- $this->addRouteExpectation(
- 'ezpublish_rest_loadRole',
- array('roleId' => $userGroupRoleAssignment->roleAssignment->role->id),
- "/user/roles/{$userGroupRoleAssignment->roleAssignment->role->id}"
- );
+ $this->setVisitValueObjectExpectations([
+ new Values\ResourceRouteReference('ezpublish_rest_loadRole', ['roleId' => $userGroupRoleAssignment->roleAssignment->role->id]),
+ ]);
$visitor->visit(
$this->getVisitorMock(),
@@ -106,7 +104,6 @@ public function testResultContainsRoleAssignmentAttributes($result)
'tag' => 'RoleAssignment',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.RoleAssignment+xml',
- 'href' => '/user/groups/1/5/14/roles/42',
),
),
$result,
@@ -148,7 +145,6 @@ public function testResultContainsRoleAttributes($result)
'tag' => 'Role',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.Role+xml',
- 'href' => '/user/roles/42',
),
),
$result,
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestUserGroupTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestUserGroupTest.php
index 2ee90daab51..8074bac5082 100644
--- a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestUserGroupTest.php
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestUserGroupTest.php
@@ -11,6 +11,7 @@
namespace eZ\Publish\Core\REST\Server\Tests\Output\ValueObjectVisitor;
use eZ\Publish\Core\REST\Common\Tests\Output\ValueObjectVisitorBaseTest;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
use eZ\Publish\Core\REST\Server\Values\RestUserGroup;
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
use eZ\Publish\Core\Repository\Values;
@@ -30,65 +31,22 @@ public function testVisitWithoutEmbeddedVersion()
$restUserGroup = $this->getBasicRestUserGroup();
- $this->getVisitorMock()->expects($this->once())
- ->method('visitValueObject');
-
$userGroupPath = implode('/', $restUserGroup->mainLocation->path);
- $this->addRouteExpectation(
- 'ezpublish_rest_loadUserGroup',
- array('groupPath' => $userGroupPath),
- "/user/groups/{$userGroupPath}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadContentType',
- array('contentTypeId' => $restUserGroup->contentInfo->contentTypeId),
- "/content/types/{$restUserGroup->contentInfo->contentTypeId}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadContentVersions',
- array('contentId' => $restUserGroup->contentInfo->id),
- "/content/objects/{$restUserGroup->contentInfo->id}/versions"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadSection',
- array('sectionId' => $restUserGroup->contentInfo->sectionId),
- "/content/sections/{$restUserGroup->contentInfo->sectionId}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadLocation',
- array('locationPath' => $userGroupPath),
- "/content/locations/{$userGroupPath}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadLocationsForContent',
- array('contentId' => $restUserGroup->contentInfo->id),
- "/content/objects/{$restUserGroup->contentInfo->id}/locations"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadUser',
- array('userId' => $restUserGroup->contentInfo->ownerId),
- "/user/users/{$restUserGroup->contentInfo->ownerId}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadUserGroup',
- array('groupPath' => '1/2'),
- '/user/groups/1/2'
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadSubUserGroups',
- array('groupPath' => $userGroupPath),
- "/user/groups/{$userGroupPath}/subgroups"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadUsersFromGroup',
- array('groupPath' => $userGroupPath),
- "/user/groups/{$userGroupPath}/users"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadRoleAssignmentsForUserGroup',
- array('groupPath' => $userGroupPath),
- "/user/groups/{$userGroupPath}/roles"
- );
+
+ $this->setVisitValueObjectExpectations([
+ new ResourceRouteReference('ezpublish_rest_loadUserGroup', ['groupPath' => $userGroupPath]),
+ new ResourceRouteReference('ezpublish_rest_loadContentType', ['contentTypeId' => $restUserGroup->contentInfo->contentTypeId]),
+ new ResourceRouteReference('ezpublish_rest_loadContentVersions', ['contentId' => $restUserGroup->contentInfo->id]),
+ new ResourceRouteReference('ezpublish_rest_loadSection', ['sectionId' => $restUserGroup->contentInfo->sectionId]),
+ new ResourceRouteReference('ezpublish_rest_loadLocation', ['locationPath' => $userGroupPath]),
+ new ResourceRouteReference('ezpublish_rest_loadLocationsForContent', ['contentId' => $restUserGroup->contentInfo->id]),
+ new ResourceRouteReference('ezpublish_rest_loadUser', ['userId' => $restUserGroup->contentInfo->ownerId]),
+ $this->isInstanceOf('eZ\Publish\Core\REST\Server\Values\Version'),
+ new ResourceRouteReference('ezpublish_rest_loadUserGroup', ['groupPath' => '1/2']),
+ new ResourceRouteReference('ezpublish_rest_loadSubUserGroups', ['groupPath' => $userGroupPath]),
+ new ResourceRouteReference('ezpublish_rest_loadUsersFromGroup', ['groupPath' => $userGroupPath]),
+ new ResourceRouteReference('ezpublish_rest_loadRoleAssignmentsForUserGroup', ['groupPath' => $userGroupPath]),
+ ]);
$visitor->visit(
$this->getVisitorMock(),
@@ -138,16 +96,6 @@ protected function getBasicRestUserGroup()
);
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testUserGroupHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/UserGroup[@href="/user/groups/1/2/23"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -178,16 +126,6 @@ public function testUserGroupRemoteIdCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/UserGroup[@remoteId="abc123"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testUserGroupTypeHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/UserGroup/ContentType[@href="/content/types/contentType23"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -208,16 +146,6 @@ public function testNameCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/UserGroup/name[text()="Sindelfingen"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testVersionsHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/UserGroup/Versions[@href="/content/objects/content23/versions"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -228,16 +156,6 @@ public function testVersionsMediaTypeCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/UserGroup/Versions[@media-type="application/vnd.ez.api.VersionList+xml"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testSectionHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/UserGroup/Section[@href="/content/sections/section23"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -248,16 +166,6 @@ public function testSectionMediaTypeCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/UserGroup/Section[@media-type="application/vnd.ez.api.Section+xml"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testMainLocationHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/UserGroup/MainLocation[@href="/content/locations/1/2/23"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -268,16 +176,6 @@ public function testMainLocationMediaTypeCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/UserGroup/MainLocation[@media-type="application/vnd.ez.api.Location+xml"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testLocationsHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/UserGroup/Locations[@href="/content/objects/content23/locations"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -288,16 +186,6 @@ public function testLocationsMediaTypeCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/UserGroup/Locations[@media-type="application/vnd.ez.api.LocationList+xml"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testOwnerHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/UserGroup/Owner[@href="/user/users/user23"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -338,46 +226,6 @@ public function testAlwaysAvailableCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/UserGroup/alwaysAvailable[text()="true"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testParentUserGroupHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/UserGroup/ParentUserGroup[@href="/user/groups/1/2"]');
- }
-
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testSubgroupsHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/UserGroup/Subgroups[@href="/user/groups/1/2/23/subgroups"]');
- }
-
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testUsersHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/UserGroup/Users[@href="/user/groups/1/2/23/users"]');
- }
-
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testRolesHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/UserGroup/Roles[@href="/user/groups/1/2/23/roles"]');
- }
-
/**
* @param \DOMDocument $dom
*
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestUserRoleAssignmentTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestUserRoleAssignmentTest.php
index 1096ea95de3..e1cb34c780a 100644
--- a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestUserRoleAssignmentTest.php
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestUserRoleAssignmentTest.php
@@ -14,6 +14,7 @@
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
use eZ\Publish\Core\Repository\Values\User;
use eZ\Publish\Core\REST\Server\Values;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
class RestUserRoleAssignmentTest extends ValueObjectVisitorBaseTest
{
@@ -52,11 +53,9 @@ public function testVisit()
"/user/users/{$userRoleAssignment->id}/roles/{$userRoleAssignment->roleAssignment->role->id}"
);
- $this->addRouteExpectation(
- 'ezpublish_rest_loadRole',
- array('roleId' => $userRoleAssignment->roleAssignment->role->id),
- "/user/roles/{$userRoleAssignment->roleAssignment->role->id}"
- );
+ $this->setVisitValueObjectExpectations([
+ new ResourceRouteReference('ezpublish_rest_loadRole', ['roleId' => $userRoleAssignment->roleAssignment->role->id]),
+ ]);
$visitor->visit(
$this->getVisitorMock(),
@@ -107,7 +106,6 @@ public function testResultContainsRoleAssignmentAttributes($result)
'tag' => 'RoleAssignment',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.RoleAssignment+xml',
- 'href' => '/user/users/14/roles/42',
),
),
$result,
@@ -149,7 +147,6 @@ public function testResultContainsRoleAttributes($result)
'tag' => 'Role',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.Role+xml',
- 'href' => '/user/roles/42',
),
),
$result,
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestUserTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestUserTest.php
index d4abb0f98bc..f0135579131 100644
--- a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestUserTest.php
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestUserTest.php
@@ -11,6 +11,7 @@
namespace eZ\Publish\Core\REST\Server\Tests\Output\ValueObjectVisitor;
use eZ\Publish\Core\REST\Common\Tests\Output\ValueObjectVisitorBaseTest;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
use eZ\Publish\Core\REST\Server\Values\RestUser;
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
use eZ\Publish\Core\Repository\Values;
@@ -30,60 +31,25 @@ public function testVisitWithoutEmbeddedVersion()
$restUser = $this->getBasicRestUser();
- $this->getVisitorMock()->expects($this->once())
- ->method('visitValueObject');
-
$locationPath = implode('/', $restUser->mainLocation->path);
$this->addRouteExpectation(
'ezpublish_rest_loadUser',
array('userId' => $restUser->contentInfo->id),
"/user/users/{$restUser->contentInfo->id}"
);
- $this->addRouteExpectation(
- 'ezpublish_rest_loadContentType',
- array('contentTypeId' => $restUser->contentInfo->contentTypeId),
- "/content/types/{$restUser->contentInfo->contentTypeId}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadContentVersions',
- array('contentId' => $restUser->contentInfo->id),
- "/content/objects/{$restUser->contentInfo->id}/versions"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadSection',
- array('sectionId' => $restUser->contentInfo->sectionId),
- "/content/sections/{$restUser->contentInfo->sectionId}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadLocation',
- array('locationPath' => $locationPath),
- "/content/locations/{$locationPath}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadLocationsForContent',
- array('contentId' => $restUser->contentInfo->id),
- "/content/objects/{$restUser->contentInfo->id}/locations"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadUserGroupsOfUser',
- array('userId' => $restUser->contentInfo->id),
- "/user/users/{$restUser->contentInfo->id}/groups"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadUser',
- array('userId' => $restUser->contentInfo->ownerId),
- "/user/users/{$restUser->contentInfo->ownerId}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadUserGroupsOfUser',
- array('userId' => $restUser->contentInfo->id),
- "/user/users/{$restUser->contentInfo->id}/groups"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_loadRoleAssignmentsForUser',
- array('userId' => $restUser->contentInfo->id),
- "/user/users/{$restUser->contentInfo->id}/roles"
- );
+
+ $this->setVisitValueObjectExpectations([
+ new ResourceRouteReference('ezpublish_rest_loadContentType', ['contentTypeId' => $restUser->contentInfo->contentTypeId]),
+ new ResourceRouteReference('ezpublish_rest_loadContentVersions', ['contentId' => $restUser->contentInfo->id]),
+ new ResourceRouteReference('ezpublish_rest_loadSection', ['sectionId' => $restUser->contentInfo->sectionId]),
+ new ResourceRouteReference('ezpublish_rest_loadLocation', ['locationPath' => $locationPath]),
+ new ResourceRouteReference('ezpublish_rest_loadLocationsForContent', ['contentId' => $restUser->contentInfo->id]),
+ new ResourceRouteReference('ezpublish_rest_loadUserGroupsOfUser', ['userId' => $restUser->contentInfo->id]),
+ new ResourceRouteReference('ezpublish_rest_loadUser', ['userId' => $restUser->contentInfo->ownerId]),
+ $this->isInstanceOf('eZ\Publish\Core\REST\Server\Values\Version'),
+ new ResourceRouteReference('ezpublish_rest_loadUserGroupsOfUser', ['userId' => $restUser->contentInfo->id]),
+ new ResourceRouteReference('ezpublish_rest_loadRoleAssignmentsForUser', ['userId' => $restUser->contentInfo->id]),
+ ]);
$visitor->visit(
$this->getVisitorMock(),
@@ -173,16 +139,6 @@ public function testUserRemoteIdCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/User[@remoteId="abc123"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testUserTypeHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/User/ContentType[@href="/content/types/contentType23"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -203,16 +159,6 @@ public function testNameCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/User/name[text()="Sindelfingen"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testVersionsHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/User/Versions[@href="/content/objects/content23/versions"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -223,16 +169,6 @@ public function testVersionsMediaTypeCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/User/Versions[@media-type="application/vnd.ez.api.VersionList+xml"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testSectionHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/User/Section[@href="/content/sections/section23"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -243,16 +179,6 @@ public function testSectionMediaTypeCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/User/Section[@media-type="application/vnd.ez.api.Section+xml"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testMainLocationHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/User/MainLocation[@href="/content/locations/1/2/23"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -263,16 +189,6 @@ public function testMainLocationMediaTypeCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/User/MainLocation[@media-type="application/vnd.ez.api.Location+xml"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testLocationsHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/User/Locations[@href="/content/objects/content23/locations"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -283,16 +199,6 @@ public function testLocationsMediaTypeCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/User/Locations[@media-type="application/vnd.ez.api.LocationList+xml"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testOwnerHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/User/Owner[@href="/user/users/user23"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -333,16 +239,6 @@ public function testAlwaysAvailableCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/User/alwaysAvailable[text()="true"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testUserGroupsHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/User/UserGroups[@href="/user/users/content23/groups"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -353,16 +249,6 @@ public function testUserGroupsMediaTypeCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/User/UserGroups[@media-type="application/vnd.ez.api.UserGroupList+xml"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisitWithoutEmbeddedVersion
- */
- public function testRolesHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/User/Roles[@href="/user/users/content23/roles"]');
- }
-
/**
* @param \DOMDocument $dom
*
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RoleTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RoleTest.php
index 13bef90c1df..5c3ec3bcc81 100644
--- a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RoleTest.php
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RoleTest.php
@@ -13,6 +13,7 @@
use eZ\Publish\Core\REST\Common\Tests\Output\ValueObjectVisitorBaseTest;
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
use eZ\Publish\Core\Repository\Values\User;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
class RoleTest extends ValueObjectVisitorBaseTest
{
@@ -47,7 +48,9 @@ public function testVisit()
);
$this->addRouteExpectation('ezpublish_rest_loadRole', array('roleId' => $role->id), "/user/roles/{$role->id}");
- $this->addRouteExpectation('ezpublish_rest_loadPolicies', array('roleId' => $role->id), "/user/roles/{$role->id}/policies");
+ $this->setVisitValueObjectExpectations([
+ new ResourceRouteReference('ezpublish_rest_loadPolicies', ['roleId' => $role->id]),
+ ]);
$visitor->visit(
$this->getVisitorMock(),
@@ -98,7 +101,6 @@ public function testResultContainsRoleAttributes($result)
'tag' => 'Role',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.Role+xml',
- 'href' => '/user/roles/42',
),
),
$result,
@@ -227,7 +229,6 @@ public function testResultContainsPoliciesAttributes($result)
'tag' => 'Policies',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.PolicyList+xml',
- 'href' => '/user/roles/42/policies',
),
),
$result,
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/UserGroupRefListTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/UserGroupRefListTest.php
index 9d6b33f755f..daa51eaea0f 100644
--- a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/UserGroupRefListTest.php
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/UserGroupRefListTest.php
@@ -13,6 +13,7 @@
use eZ\Publish\Core\REST\Common\Tests\Output\ValueObjectVisitorBaseTest;
use eZ\Publish\Core\Repository\Values\User\UserGroup;
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
use eZ\Publish\Core\REST\Server\Values\UserGroupRefList;
use eZ\Publish\Core\REST\Server\Values\RestUserGroup;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
@@ -63,29 +64,12 @@ public function testVisit()
14
);
- $groupPath = trim($UserGroupRefList->userGroups[0]->mainLocation->pathString, '/');
- $this->addRouteExpectation(
- 'ezpublish_rest_loadUserGroup',
- array('groupPath' => $groupPath),
- "/user/groups/{$groupPath}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_unassignUserFromUserGroup',
- array('userId' => $UserGroupRefList->userId, 'groupPath' => 14),
- '/user/users/14/groups/14'
- );
-
- $groupPath = trim($UserGroupRefList->userGroups[1]->mainLocation->pathString, '/');
- $this->addRouteExpectation(
- 'ezpublish_rest_loadUserGroup',
- array('groupPath' => '1/5/13'),
- "/user/groups/{$groupPath}"
- );
- $this->addRouteExpectation(
- 'ezpublish_rest_unassignUserFromUserGroup',
- array('userId' => $UserGroupRefList->userId, 'groupPath' => 13),
- '/user/users/14/groups/13'
- );
+ $this->setVisitValueObjectExpectations([
+ new ResourceRouteReference('ezpublish_rest_loadUserGroup', ['groupPath' => '1/5/14']),
+ new ResourceRouteReference('ezpublish_rest_unassignUserFromUserGroup', ['userId' => $UserGroupRefList->userId, 'groupPath' => 14]),
+ new ResourceRouteReference('ezpublish_rest_loadUserGroup', ['groupPath' => '1/5/13']),
+ new ResourceRouteReference('ezpublish_rest_unassignUserFromUserGroup', ['userId' => $UserGroupRefList->userId, 'groupPath' => 13]),
+ ]);
$visitor->visit(
$this->getVisitorMock(),
@@ -103,16 +87,6 @@ public function testVisit()
return $dom;
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisit
- */
- public function testUserGroupRefListHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/UserGroupRefList[@href="/some/path"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -123,16 +97,6 @@ public function testUserGroupRefListMediaTypeCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/UserGroupRefList[@media-type="application/vnd.ez.api.UserGroupRefList+xml"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisit
- */
- public function testFirstUserGroupHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/UserGroupRefList/UserGroup[1][@href="/user/groups/1/5/14"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -143,16 +107,6 @@ public function testFirstUserGroupMediaTypeCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/UserGroupRefList/UserGroup[1][@media-type="application/vnd.ez.api.UserGroup+xml"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisit
- */
- public function testFirstUserGroupUnassignHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/UserGroupRefList/UserGroup[1]/unassign[@href="/user/users/14/groups/14"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -163,16 +117,6 @@ public function testFirstUserGroupUnassignMethodCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/UserGroupRefList/UserGroup[1]/unassign[@method="DELETE"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisit
- */
- public function testSecondUserGroupHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/UserGroupRefList/UserGroup[2][@href="/user/groups/1/5/13"]');
- }
-
/**
* @param \DOMDocument $dom
*
@@ -183,16 +127,6 @@ public function testSecondUserGroupMediaTypeCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/UserGroupRefList/UserGroup[2][@media-type="application/vnd.ez.api.UserGroup+xml"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisit
- */
- public function testSecondUserGroupUnassignHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/UserGroupRefList/UserGroup[2]/unassign[@href="/user/users/14/groups/13"]');
- }
-
/**
* @param \DOMDocument $dom
*
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/UserRefListTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/UserRefListTest.php
index 9c5d9f0b09d..a520fe46e35 100644
--- a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/UserRefListTest.php
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/UserRefListTest.php
@@ -13,6 +13,7 @@
use eZ\Publish\Core\REST\Common\Tests\Output\ValueObjectVisitorBaseTest;
use eZ\Publish\Core\Repository\Values\User\User;
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
use eZ\Publish\Core\REST\Server\Values\UserRefList;
use eZ\Publish\Core\REST\Server\Values\RestUser;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
@@ -49,11 +50,9 @@ public function testVisit()
'/some/path'
);
- $this->addRouteExpectation(
- 'ezpublish_rest_loadUser',
- array('userId' => $UserRefList->users[0]->contentInfo->id),
- "/user/users/{$UserRefList->users[0]->contentInfo->id}"
- );
+ $this->setVisitValueObjectExpectations([
+ new ResourceRouteReference('ezpublish_rest_loadUser', ['userId' => $UserRefList->users[0]->contentInfo->id]),
+ ]);
$visitor->visit(
$this->getVisitorMock(),
@@ -91,16 +90,6 @@ public function testUserRefListMediaTypeCorrect(\DOMDocument $dom)
$this->assertXPath($dom, '/UserRefList[@media-type="application/vnd.ez.api.UserRefList+xml"]');
}
- /**
- * @param \DOMDocument $dom
- *
- * @depends testVisit
- */
- public function testUserHrefCorrect(\DOMDocument $dom)
- {
- $this->assertXPath($dom, '/UserRefList/User[@href="/user/users/14"]');
- }
-
/**
* @param \DOMDocument $dom
*
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/UserSessionCreatedTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/UserSessionCreatedTest.php
index 593c96cf288..fac413d2d5e 100644
--- a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/UserSessionCreatedTest.php
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/UserSessionCreatedTest.php
@@ -50,11 +50,9 @@ public function testVisit()
"/user/sessions/{$session->sessionId}"
);
- $this->addRouteExpectation(
- 'ezpublish_rest_loadUser',
- array('userId' => $session->user->id),
- "/user/users/{$session->user->id}"
- );
+ $this->setVisitValueObjectExpectations([
+ new Values\ResourceRouteReference('ezpublish_rest_loadUser', ['userId' => $session->user->id]),
+ ]);
$visitor->visit(
$this->getVisitorMock(),
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/UserSessionTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/UserSessionTest.php
index 8fae69cc213..a66e9b30852 100644
--- a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/UserSessionTest.php
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/UserSessionTest.php
@@ -52,11 +52,9 @@ public function testVisit()
"/user/sessions/{$session->sessionId}"
);
- $this->addRouteExpectation(
- 'ezpublish_rest_loadUser',
- array('userId' => $session->user->id),
- "/user/users/{$session->user->id}"
- );
+ $this->setVisitValueObjectExpectations([
+ new Values\ResourceRouteReference('ezpublish_rest_loadUser', ['userId' => $session->user->id]),
+ ]);
$visitor->visit(
$this->getVisitorMock(),
@@ -219,7 +217,6 @@ public function testResultContainsUserAttributes($result)
array(
'tag' => 'User',
'attributes' => array(
- 'href' => '/user/users/user123',
'media-type' => 'application/vnd.ez.api.User+xml',
),
),
diff --git a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/VersionInfoTest.php b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/VersionInfoTest.php
index 5510ba791e2..c9e24d3f39b 100644
--- a/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/VersionInfoTest.php
+++ b/eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/VersionInfoTest.php
@@ -14,6 +14,7 @@
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
use eZ\Publish\Core\Repository\Values\Content;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
+use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
class VersionInfoTest extends ValueObjectVisitorBaseTest
{
@@ -63,17 +64,10 @@ public function testVisit()
)
);
- $this->addRouteExpectation(
- 'ezpublish_rest_loadUser',
- array('userId' => $versionInfo->creatorId),
- "/user/users/{$versionInfo->creatorId}"
- );
-
- $this->addRouteExpectation(
- 'ezpublish_rest_loadContent',
- array('contentId' => $versionInfo->contentInfo->id),
- "/content/objects/{$versionInfo->contentInfo->id}"
- );
+ $this->setVisitValueObjectExpectations([
+ new ResourceRouteReference('ezpublish_rest_loadUser', ['userId' => $versionInfo->creatorId]),
+ new ResourceRouteReference('ezpublish_rest_loadContent', ['contentId' => $versionInfo->contentInfo->id]),
+ ]);
$visitor->visit(
$this->getVisitorMock(),
@@ -268,7 +262,6 @@ public function testVersionInfoContentElement($result)
'tag' => 'Content',
'attributes' => array(
'media-type' => 'application/vnd.ez.api.ContentInfo+xml',
- 'href' => '/content/objects/42',
),
),
$result,
diff --git a/eZ/Publish/Core/REST/Server/Values/ResourceLink.php b/eZ/Publish/Core/REST/Server/Values/ResourceLink.php
new file mode 100644
index 00000000000..7435363c3ff
--- /dev/null
+++ b/eZ/Publish/Core/REST/Server/Values/ResourceLink.php
@@ -0,0 +1,37 @@
+link = $link;
+ $this->mediaType = $mediaType;
+ }
+}
diff --git a/eZ/Publish/Core/REST/Server/Values/ResourceRouteReference.php b/eZ/Publish/Core/REST/Server/Values/ResourceRouteReference.php
new file mode 100644
index 00000000000..fd0dd23d398
--- /dev/null
+++ b/eZ/Publish/Core/REST/Server/Values/ResourceRouteReference.php
@@ -0,0 +1,47 @@
+route = $route;
+ $this->loadParameters = $loadParameters;
+ $this->mediaTypeName = $mediaType;
+ }
+}