Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit f668b69

Browse files
committed
Merge pull request #19 from symfony-cmf/include_body
Include body in case of BodyResource
2 parents 402e68f + 4c67c0e commit f668b69

File tree

6 files changed

+69
-13
lines changed

6 files changed

+69
-13
lines changed

Serializer/Jms/Handler/ResourceHandler.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use JMS\Serializer\Context;
1717
use PHPCR\NodeInterface;
1818
use PHPCR\Util\PathHelper;
19+
use Puli\Repository\Api\Resource\BodyResource;
1920
use Puli\Repository\Api\Resource\Resource;
2021
use Symfony\Cmf\Component\Resource\RepositoryRegistryInterface;
2122
use Symfony\Cmf\Bundle\ResourceRestBundle\Registry\PayloadAliasRegistry;
@@ -101,6 +102,10 @@ private function doSerializeResource(Resource $resource, $depth = 0)
101102
}
102103
$data['children'] = $children;
103104

105+
if ($resource instanceof BodyResource) {
106+
$data['body'] = $resource->getBody();
107+
}
108+
104109
foreach ($enhancers as $enhancer) {
105110
$data = $enhancer->enhance($data, $resource);
106111
}

Tests/Features/Context/ResourceContext.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class ResourceContext implements Context, KernelAwareContext
1717
{
1818
private $session;
1919
private $manager;
20+
21+
/**
22+
* @var KernelInterface
23+
*/
2024
private $kernel;
2125

2226
/**
@@ -61,15 +65,27 @@ public function beforeScenario(BeforeScenarioScope $scope)
6165
/**
6266
* @Given the test application has the following configuration:
6367
*/
64-
public function givenTheApplicationHasTheConfiguration(PyStringNode $config)
68+
public function setApplicationConfig(PyStringNode $config)
6569
{
6670
file_put_contents(self::getConfigurationFile(), $config->getRaw());
6771
}
6872

6973
/**
70-
* @Given there exists a ":class" document at ":path":
74+
* @Given there is a file named :filename with:
75+
*/
76+
public function createFile($filename, PyStringNode $content)
77+
{
78+
$filesytem = new Filesystem();
79+
$file = str_replace('%kernel.root_dir%', $this->kernel->getRootDir(), $filename);
80+
$filesytem->mkdir(dirname($file));
81+
82+
file_put_contents($file, (string) $content);
83+
}
84+
85+
/**
86+
* @Given there exists a :class document at :path:
7187
*/
72-
public function givenThereExistsDocument($class, $path, TableNode $fields)
88+
public function createDocument($class, $path, TableNode $fields)
7389
{
7490
$class = 'Symfony\\Cmf\\Bundle\\ResourceRestBundle\\Tests\\Resources\\TestBundle\\Document\\' . $class;
7591
$path = '/tests' . $path;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Feature: Filesystem resource repository
2+
In order to retrieve data from the resource webservice
3+
As a webservice user
4+
I need to be able to query the webservice
5+
6+
Background:
7+
Given the test application has the following configuration:
8+
"""
9+
cmf_resource:
10+
repositories:
11+
default:
12+
type: filesystem
13+
base_dir: "%kernel.root_dir%/Resources/views/snippets"
14+
"""
15+
And there is a file named "%kernel.root_dir%/Resources/views/snippets/snippet1.html" with:
16+
"""
17+
<h1>Snippet 1</h1>
18+
"""
19+
20+
21+
Scenario: Retrieve filesystem resource
22+
When I send a GET request to "/api/default/snippet1.html"
23+
Then the response should contain json:
24+
"""
25+
{
26+
"repository_alias": "default",
27+
"repository_type": "filesystem",
28+
"payload_alias": null,
29+
"payload_type": null,
30+
"path": "\/snippet1.html",
31+
"node_name": "snippet1.html",
32+
"label": "snippet1.html",
33+
"repository_path": "\/snippet1.html",
34+
"children": [],
35+
"body": "<h1>Snippet 1</h1>"
36+
}
37+
"""

Tests/Features/resource_api_phpcr.feature

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ Feature: PHPCR resource repository
2424
Given there exists a "Article" document at "/cmf/articles/foo":
2525
| title | Article 1 |
2626
| body | This is my article |
27-
Then I send a GET request to "/api/phpcr_repo/foo"
28-
And print response
29-
And the response should contain json:
27+
When I send a GET request to "/api/phpcr_repo/foo"
28+
Then the response should contain json:
3029
"""
3130
{
3231
"repository_alias": "phpcr_repo",

Tests/Features/resource_api_phpcr_odm.feature

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Feature: PHPCR-ODM resource repository
1414
1515
cmf_resource_rest:
1616
payload_alias_map:
17-
article:
17+
article:
1818
repository: doctrine_phpcr_odm
1919
type: "Symfony\\Cmf\\Bundle\\ResourceRestBundle\\Tests\\Resources\\TestBundle\\Document\\Article"
2020
"""
@@ -24,9 +24,8 @@ Feature: PHPCR-ODM resource repository
2424
Given there exists a "Article" document at "/cmf/articles/foo":
2525
| title | Article 1 |
2626
| body | This is my article |
27-
Then I send a GET request to "/api/phpcrodm_repo/foo"
28-
And print response
29-
And the response code should be 200
27+
When I send a GET request to "/api/phpcrodm_repo/foo"
28+
Then the response code should be 200
3029
And the response should contain json:
3130
"""
3231
{
@@ -52,9 +51,8 @@ Feature: PHPCR-ODM resource repository
5251
And there exists a "Article" document at "/cmf/articles/foo/boo":
5352
| title | Article child |
5453
| body | But this one is mine |
55-
Then I send a GET request to "/api/phpcrodm_repo/foo"
56-
And print response
57-
And the response code should be 200
54+
When I send a GET request to "/api/phpcrodm_repo/foo"
55+
Then the response code should be 200
5856
And the response should contain json:
5957
"""
6058
{
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>Snippet 1</h1>

0 commit comments

Comments
 (0)