diff --git a/src/Bundle/ChillPersonBundle/Controller/RelationshipApiController.php b/src/Bundle/ChillPersonBundle/Controller/RelationshipApiController.php index bf4452942..b396cdf36 100644 --- a/src/Bundle/ChillPersonBundle/Controller/RelationshipApiController.php +++ b/src/Bundle/ChillPersonBundle/Controller/RelationshipApiController.php @@ -28,7 +28,6 @@ class RelationshipApiController extends ApiController { //TODO: add permissions? (voter?) $relationships = $this->repository->findByPerson($person); - //dump($relationships[0]->getRelation()); return $this->json(\array_values($relationships), Response::HTTP_OK, [], ['groups' => [ 'read']]); } diff --git a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php index adc37d5b5..f69ec0303 100644 --- a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php +++ b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php @@ -106,6 +106,8 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con protected UserRepository $userRepository; + public const PERSON = 'person'; + public function __construct( Registry $workflowRegistry, SocialIssueRepository $socialIssueRepository, @@ -257,6 +259,8 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con $manager->persist($person); $manager->persist($accompanyingPeriod); echo "add person'".$person->__toString()."'\n"; + + $this->addReference(self::PERSON, $person); } private function getRandomUser(): User diff --git a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadRelationships.php b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadRelationships.php index cfabde912..5efc68400 100644 --- a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadRelationships.php +++ b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadRelationships.php @@ -6,17 +6,31 @@ namespace Chill\PersonBundle\DataFixtures\ORM; use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Common\DataFixtures\DependentFixtureInterface; 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 { + + + public function getDependencies() { + return [ + LoadPeople::class, + LoadRelations::class + ]; } 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)); } } \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php index ea23f2b4b..b0c6a1262 100644 --- a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php +++ b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php @@ -903,7 +903,6 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac ], [ 'class' => \Chill\PersonBundle\Entity\Relationships\Relation::class, - 'controller' => \Chill\PersonBundle\Controller\RelationshipApiController::class, 'name' => 'relations', 'base_path' => '/api/1.0/relations/relation', 'base_role' => 'ROLE_USER', diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/RelationshipApiControllerTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/RelationshipApiControllerTest.php new file mode 100644 index 000000000..6d538a646 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/RelationshipApiControllerTest.php @@ -0,0 +1,74 @@ +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], + ]; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/chill.api.specs.yaml b/src/Bundle/ChillPersonBundle/chill.api.specs.yaml index 241febd36..edd4d0764 100644 --- a/src/Bundle/ChillPersonBundle/chill.api.specs.yaml +++ b/src/Bundle/ChillPersonBundle/chill.api.specs.yaml @@ -1675,7 +1675,7 @@ paths: /1.0/relations/relation.json: get: tags: - - relationships + - relations summary: get a list of relations responses: 401: