Skip to content

Commit

Permalink
Add a regression test for api-platform/api-platform#1085
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka authored and teohhanhui committed Apr 5, 2019
1 parent dc827a2 commit 31ea473
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
38 changes: 38 additions & 0 deletions features/jsonapi/non_resource.feature
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,41 @@ Feature: JSON API non-resource handling
}
}
"""

@!mongodb
@createSchema
Scenario: Create a resource that contains a stdClass object.
When I send a "POST" request to "/plain_object_dummies" with body:
"""
{
"data": {
"type": "PlainObjectDummy",
"attributes": {
"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\"}"
}
}
}
"""
Then the response status code should be 201
And the response should be in JSON
And the header "Content-Type" should be equal to "application/vnd.api+json; charset=utf-8"
And the JSON should be valid according to the JSON API schema
And the JSON should be a superset of:
"""
{
"data": {
"id": "/plain_object_dummies/1",
"type": "PlainObjectDummy",
"attributes": {
"_id": 1,
"data": {
"fields": [],
"showCaption": false,
"alternativeContent": false,
"alternativeAudioContent": false,
"blockLayout": "default"
}
}
}
}
"""
29 changes: 29 additions & 0 deletions features/jsonld/non_resource.feature
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,32 @@ Feature: JSON-LD non-resource handling
"id": 1
}
"""

@!mongodb
@createSchema
Scenario: Create a resource that contains a stdClass object.
When I send a "POST" request to "/plain_object_dummies" with body:
"""
{
"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\"}"
}
"""
Then the response status code should be 201
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the JSON should be equal to:
"""
{
"@context": "/contexts/PlainObjectDummy",
"@id": "/plain_object_dummies/1",
"@type": "PlainObjectDummy",
"data": {
"fields": [],
"showCaption": false,
"alternativeContent": false,
"alternativeAudioContent": false,
"blockLayout": "default"
},
"id": 1
}
"""
56 changes: 56 additions & 0 deletions tests/Fixtures/TestBundle/Entity/PlainObjectDummy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;

/**
* Regression test for https://github.com/api-platform/api-platform/issues/1085.
*
* @author Antoine Bluchet <soyuka@gmail.com>
*
* @ApiResource
* @ORM\Entity
*/
class PlainObjectDummy
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;

/**
* @var string
*/
private $content;

/**
* @var array
*/
public $data;

public function setContent($content)
{
$this->content = $content;
$this->data = (array) json_decode($content);
}

public function getId()
{
return $this->id;
}
}

0 comments on commit 31ea473

Please sign in to comment.