Skip to content

Commit 4812d4e

Browse files
soyukateohhanhui
authored andcommitted
Add a regression test for api-platform/api-platform#1085
1 parent 0913b66 commit 4812d4e

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

features/jsonld/non_resource.feature

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,32 @@ Feature: JSON-LD non-resource handling
6262
"id": 1
6363
}
6464
"""
65+
66+
@!mongodb
67+
@createSchema
68+
Scenario: Create a resource that contains a stdClass object.
69+
When I send a "POST" request to "/plain_object_dummies" with body:
70+
"""
71+
{
72+
"content":"{\"fields\":{\"title\":{\"value\":\"\"},\"images\":[{\"id\":0,\"categoryId\":0,\"uri\":\"/api/pictures\",\"resource\":\"{}\",\"description\":\"\",\"alt\":\"\",\"type\":\"picture\",\"text\":\"\",\"src\":\"\"}],\"alternativeAudio\":{},\"caption\":\"\"},\"showCaption\":false,\"alternativeContent\":false,\"alternativeAudioContent\":false,\"blockLayout\":\"default\"}"
73+
}
74+
"""
75+
Then the response status code should be 201
76+
And the response should be in JSON
77+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
78+
And the JSON should be equal to:
79+
"""
80+
{
81+
"@context": "/contexts/PlainObjectDummy",
82+
"@id": "/plain_object_dummies/1",
83+
"@type": "PlainObjectDummy",
84+
"data": {
85+
"fields": [],
86+
"showCaption": false,
87+
"alternativeContent": false,
88+
"alternativeAudioContent": false,
89+
"blockLayout": "default"
90+
},
91+
"id": 1
92+
}
93+
"""
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <dunglas@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity;
15+
16+
use ApiPlatform\Core\Annotation\ApiResource;
17+
use Doctrine\ORM\Mapping as ORM;
18+
19+
/**
20+
* Regression test for https://github.com/api-platform/api-platform/issues/1085.
21+
*
22+
* @author Antoine Bluchet <soyuka@gmail.com>
23+
*
24+
* @ApiResource
25+
* @ORM\Entity
26+
*/
27+
class PlainObjectDummy
28+
{
29+
/**
30+
* @ORM\Id
31+
* @ORM\Column(type="integer")
32+
* @ORM\GeneratedValue(strategy="AUTO")
33+
*/
34+
private $id;
35+
36+
/**
37+
* @var string
38+
*/
39+
private $content;
40+
41+
/**
42+
* @var array
43+
*/
44+
public $data;
45+
46+
public function setContent($content)
47+
{
48+
$this->content = $content;
49+
$this->data = (array) json_decode($content);
50+
}
51+
52+
public function getId()
53+
{
54+
return $this->id;
55+
}
56+
}

0 commit comments

Comments
 (0)