* * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ namespace Chill\PersonBundle\Tests\Entity; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation; use Chill\PersonBundle\Entity\Person; use Chill\ThirdPartyBundle\Entity\ThirdParty; use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment; class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase { public function testClosingIsAfterOpeningConsistency() { $datetime1 = new \DateTime('now'); $datetime2 = new \DateTime('tomorrow'); $period = new AccompanyingPeriod($datetime1); $period->setClosingDate($datetime2); $r = $period->isClosingAfterOpening(); $this->assertTrue($r); } public function testClosingIsBeforeOpeningConsistency() { $datetime1 = new \DateTime('tomorrow'); $datetime2 = new \DateTime('now'); $period = new AccompanyingPeriod($datetime1); $period->setClosingDate($datetime2); $this->assertFalse($period->isClosingAfterOpening()); } public function testClosingEqualOpening() { $datetime = new \DateTime('now'); $period = new AccompanyingPeriod($datetime); $period->setClosingDate($datetime); $this->assertTrue($period->isClosingAfterOpening()); } public function testIsOpen() { $period = new AccompanyingPeriod(new \DateTime()); $this->assertTrue($period->isOpen()); } public function testIsClosed() { $period = new AccompanyingPeriod(new \DateTime()); $period->setClosingDate(new \DateTime('tomorrow')); $this->assertFalse($period->isOpen()); } public function testPersonPeriod() { $person = new Person(); $person2 = new Person(); $person3 = new Person(); $period = new AccompanyingPeriod(new \DateTime()); $participation0 = $period->createParticipationFor($person); $period->createParticipationFor($person2); $period->createParticipationFor($person3); $this->assertNotNull($participation0); $this->assertEquals(3, $period->getParticipations()->count()); $this->assertTrue($period->containsPerson($person)); $this->assertFalse($period->containsPerson(new Person())); $participation = $period->getOpenParticipationContainsPerson($person); $participations = $period->getParticipationsContainsPerson($person); $this->assertNotNull($participation); $this->assertSame($person, $participation->getPerson()); $this->assertSame($participation, $participation0); $this->assertEquals(1, $participations->count()); $participationL = $period->closeParticipationFor($person); $this->assertSame($participationL, $participation); $this->assertTrue($participation->getEndDate() instanceof \DateTimeInterface); $participation = $period->getOpenParticipationContainsPerson($person); $this->assertNull($participation); $person4 = new Person(); $participations4 = $period->getParticipationsContainsPerson($person4); $this->assertEquals(0, $participations4->count()); $participation4 = $period->getOpenParticipationContainsPerson($person4); $this->assertNull($participation4); $period->addPerson($person4); $this->assertInstanceOf(AccompanyingPeriodParticipation::class, $period->getOpenParticipationContainsPerson($person4)); $this->assertEquals(1, $period->getParticipationsContainsPerson($person4)->count()); $period->removePerson($person4); $this->assertNull($period->getOpenParticipationContainsPerson($person4)); $this->assertEquals(1, $period->getParticipationsContainsPerson($person4)->count()); } public function testRequestor() { $period = new AccompanyingPeriod(new \DateTime()); $person = new Person(); $thirdParty = new ThirdParty(); $this->assertNull($period->getRequestorThirdParty()); $this->assertNull($period->getRequestorPerson()); $this->assertNull($period->getRequestor()); $period->setRequestor($person); $this->assertNull($period->getRequestorThirdParty()); $this->assertSame($person, $period->getRequestorPerson()); $this->assertSame($person, $period->getRequestor()); $period->setRequestor($thirdParty); $this->assertNull($period->getRequestorPerson()); $this->assertSame($thirdParty, $period->getRequestorThirdParty()); $this->assertSame($thirdParty, $period->getRequestor()); $period->setRequestor(NULL); $this->assertNull($period->getRequestorThirdParty()); $this->assertNull($period->getRequestorPerson()); $this->assertNull($period->getRequestor()); } public function testInitialComment() { $period = new AccompanyingPeriod(new \DateTime()); $comment = new Comment(); $replacingComment = new Comment(); $period->setInitialComment(NULL); $this->assertNull($period->getInitialComment()); $period->setInitialComment($comment); $this->assertSame($period->getInitialComment(), $comment); $this->assertSame($period, $comment->getAccompanyingPeriod()); $this->assertEquals(0, count($period->getComments()), "The initial comment should not appears in the list of comments"); $period->setInitialComment($replacingComment); $this->assertSame($period->getInitialComment(), $replacingComment); $this->assertSame($period, $replacingComment->getAccompanyingPeriod()); $this->assertEquals(0, count($period->getComments()), "The initial comment should not appears in the list of comments"); $this->assertNull($comment->getAccompanyingPeriod()); $period->setInitialComment(NULL); $this->assertNull($period->getInitialComment()); $this->assertNull($replacingComment->getAccompanyingPeriod()); $this->assertEquals(0, count($period->getComments()), "The initial comment should not appears in the list of comments"); } }