Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions features/http_cache/tags.feature
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,40 @@ Feature: Cache invalidation through HTTP Cache tags
"""
Then the response status code should be 200
And "/relation1s,/relation1s/1,/relation2s/2,/relation2s/1" IRIs should be purged

Scenario: Create a Relation3 with many to many
When I add "Content-Type" header equal to "application/ld+json"
And I send a "POST" request to "/relation3s" with body:
"""
{
"relation2s": ["/relation2s/1", "/relation2s/2"]
}
"""
Then the response status code should be 201
And "/relation3s,/relation2s/1,/relation2s/2" IRIs should be purged

Scenario: Get a Relation3
When I add "Content-Type" header equal to "application/ld+json"
And I send a "GET" request to "/relation3s"
Then the response status code should be 200
And the header "Cache-Tags" should be equal to "/relation3s/1,/relation2s/1,/relation2s/2,/relation3s"

Scenario: Update a collection member only
When I add "Content-Type" header equal to "application/ld+json"
And I send a "PUT" request to "/relation3s/1" with body:
"""
{
"relation2s": ["/relation2s/2"]
}
"""
Then the response status code should be 200
And the header "Cache-Tags" should not exist
And "/relation3s,/relation3s/1,/relation2s/2,/relation2s,/relation2s/1" IRIs should be purged

Scenario: Delete the collection owner
When I add "Content-Type" header equal to "application/ld+json"
And I send a "DELETE" request to "/relation3s/1"
Then the response status code should be 204
And the header "Cache-Tags" should not exist
And "/relation3s,/relation3s/1,/relation2s/2" IRIs should be purged

61 changes: 61 additions & 0 deletions tests/Fixtures/TestBundle/Entity/Relation3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?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\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

/**
* @ApiResource
* @ORM\Entity
*/
class Relation3
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue
*/
public $id;

/**
* @ORM\ManyToMany(targetEntity="Relation2", orphanRemoval=true)
*/
private $relation2s;

public function __construct()
{
$this->relation2s = new ArrayCollection();
}

public function getRelation2s()
{
return $this->relation2s;
}

public function addRelation2(Relation2 $relation)
{
$this->relation2s->add($relation);

return $this;
}

public function removeRelation2(Relation2 $relation)
{
$this->relation2s->removeElement($relation);

return $this;
}
}