mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
Merge branch 'household_filiation' of gitlab.com:Chill-Projet/chill-bundles into household_filiation
This commit is contained in:
commit
4d08f3583e
@ -28,7 +28,6 @@ class RelationshipApiController extends ApiController
|
|||||||
{
|
{
|
||||||
//TODO: add permissions? (voter?)
|
//TODO: add permissions? (voter?)
|
||||||
$relationships = $this->repository->findByPerson($person);
|
$relationships = $this->repository->findByPerson($person);
|
||||||
//dump($relationships[0]->getRelation());
|
|
||||||
|
|
||||||
return $this->json(\array_values($relationships), Response::HTTP_OK, [], ['groups' => [ 'read']]);
|
return $this->json(\array_values($relationships), Response::HTTP_OK, [], ['groups' => [ 'read']]);
|
||||||
}
|
}
|
||||||
|
@ -106,6 +106,8 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
|
|||||||
|
|
||||||
protected UserRepository $userRepository;
|
protected UserRepository $userRepository;
|
||||||
|
|
||||||
|
public const PERSON = 'person';
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Registry $workflowRegistry,
|
Registry $workflowRegistry,
|
||||||
SocialIssueRepository $socialIssueRepository,
|
SocialIssueRepository $socialIssueRepository,
|
||||||
@ -257,6 +259,8 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
|
|||||||
$manager->persist($person);
|
$manager->persist($person);
|
||||||
$manager->persist($accompanyingPeriod);
|
$manager->persist($accompanyingPeriod);
|
||||||
echo "add person'".$person->__toString()."'\n";
|
echo "add person'".$person->__toString()."'\n";
|
||||||
|
|
||||||
|
$this->addReference(self::PERSON, $person);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getRandomUser(): User
|
private function getRandomUser(): User
|
||||||
|
@ -6,17 +6,31 @@ namespace Chill\PersonBundle\DataFixtures\ORM;
|
|||||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||||
use Doctrine\Persistence\ObjectManager;
|
use Doctrine\Persistence\ObjectManager;
|
||||||
|
use Chill\PersonBundle\DataFixtures\ORM\LoadPeople;
|
||||||
|
use Chill\PersonBundle\DataFixtures\ORM\LoadRelations;
|
||||||
|
use Chill\PersonBundle\Entity\Relationships\Relationship;
|
||||||
|
|
||||||
class LoadRelationships extends Fixture implements DependentFixtureInterface
|
class LoadRelationships extends Fixture implements DependentFixtureInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function getDependencies()
|
public function getDependencies()
|
||||||
{
|
{
|
||||||
|
return [
|
||||||
|
LoadPeople::class,
|
||||||
|
LoadRelations::class
|
||||||
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function load(ObjectManager $manager)
|
public function load(ObjectManager $manager)
|
||||||
{
|
{
|
||||||
|
$relationship = new Relationship;
|
||||||
|
$relationship->setFromPerson($this->getReference(LoadPeople::PERSON));
|
||||||
|
$relationship->setToPerson($this->getReference(LoadPeople::PERSON));
|
||||||
|
$relationship->setRelation($this->getReference(LoadRelations::RELATIONS));
|
||||||
|
$relationship->setReverse((bool)random_int(0, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -903,7 +903,6 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'class' => \Chill\PersonBundle\Entity\Relationships\Relation::class,
|
'class' => \Chill\PersonBundle\Entity\Relationships\Relation::class,
|
||||||
'controller' => \Chill\PersonBundle\Controller\RelationshipApiController::class,
|
|
||||||
'name' => 'relations',
|
'name' => 'relations',
|
||||||
'base_path' => '/api/1.0/relations/relation',
|
'base_path' => '/api/1.0/relations/relation',
|
||||||
'base_role' => 'ROLE_USER',
|
'base_role' => 'ROLE_USER',
|
||||||
|
@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Tests\Controller;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Chill\PersonBundle\Repository\PersonRepository;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
|
||||||
|
class RelationshipApiControllerTest extends WebTestCase
|
||||||
|
{
|
||||||
|
public static function setUpBeforeClass()
|
||||||
|
{
|
||||||
|
static::bootKernel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->client = static::createClient(array(), array(
|
||||||
|
'PHP_AUTH_USER' => 'fred',
|
||||||
|
'PHP_AUTH_PW' => 'password',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider personProvider
|
||||||
|
*/
|
||||||
|
public function testGetRelationshipByPerson($personId)
|
||||||
|
{
|
||||||
|
$this->client->request(Request::METHOD_GET, sprintf('/api/1.0/relations/relationship/by-person/%d.json', $personId));
|
||||||
|
|
||||||
|
$response = $this->client->getResponse();
|
||||||
|
$this->assertEquals(200, $response->getStatusCode(), 'Test to see that API response returns a status code 200');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider relationProvider
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function testPostRelationship($fromPersonId, $toPersonId, $relationId, $isReverse): void
|
||||||
|
{
|
||||||
|
$this->client->request(Request::METHOD_POST,
|
||||||
|
'/api/1.0/person/relations/relationship.json',
|
||||||
|
[],
|
||||||
|
[],
|
||||||
|
[],
|
||||||
|
\json_encode([
|
||||||
|
'type' => 'relationship',
|
||||||
|
'fromPerson' => ['id' => $fromPersonId, 'type' => 'person'],
|
||||||
|
'toPerson' => ['id' => $toPersonId, 'type' => 'person'],
|
||||||
|
'relation' => ['id' => $relationId, 'type' => 'relation'],
|
||||||
|
'reverse' => $isReverse
|
||||||
|
]));
|
||||||
|
|
||||||
|
$response = $this->client->getResponse();
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationProvider(): array
|
||||||
|
{
|
||||||
|
//TODO: which different cases to test?
|
||||||
|
return [
|
||||||
|
[333, 334, 1, true],
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function personProvider(): array
|
||||||
|
{
|
||||||
|
//TODO: which different cases to test?
|
||||||
|
return [
|
||||||
|
[333],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -1675,7 +1675,7 @@ paths:
|
|||||||
/1.0/relations/relation.json:
|
/1.0/relations/relation.json:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
- relationships
|
- relations
|
||||||
summary: get a list of relations
|
summary: get a list of relations
|
||||||
responses:
|
responses:
|
||||||
401:
|
401:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user