From a12c41fcf18b95a511a91cccb0aa921022807b5b Mon Sep 17 00:00:00 2001 From: Shane Bill Date: Mon, 24 Oct 2022 14:08:08 -0300 Subject: [PATCH] dev/cor#3874 Added test cases for failing relationship creation --- .../api/v4/Entity/RelationshipTest.php | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tests/phpunit/api/v4/Entity/RelationshipTest.php b/tests/phpunit/api/v4/Entity/RelationshipTest.php index 5a6b13c18e..f3d9f4f22c 100644 --- a/tests/phpunit/api/v4/Entity/RelationshipTest.php +++ b/tests/phpunit/api/v4/Entity/RelationshipTest.php @@ -77,4 +77,62 @@ class RelationshipTest extends Api4TestBase implements TransactionalInterface { $this->assertEquals($relationship['modified_date'], $cacheRecords[$c2]['relationship_modified_date']); } + public function testRelationshipDisableCreate(): void { + $today = new \DateTime('today'); + $future = new \DateTime('today'); + $future->add(new \DateInterval('P1Y')); + + $c1 = Contact::create(FALSE)->addValue('first_name', '1')->execute()->first()['id']; + $c2 = Contact::create(FALSE)->addValue('first_name', '2')->execute()->first()['id']; + $relationship = Relationship::create(FALSE) + ->setValues([ + 'contact_id_a' => $c1, + 'contact_id_b' => $c2, + 'start_date' => $today->format('Y-m-d'), + 'end_date' => $future->format('Y-m-d'), + 'relationship_type_id' => 1, + 'description' => "Wow, we're related!", + 'is_permission_a_b' => 1, + 'is_permission_b_a:name' => 'View only', + ])->execute()->first(); + $relationship = Relationship::get(FALSE) + ->addWhere('id', '=', $relationship['id']) + ->execute()->first(); + $relationshipDisable = Relationship::update(FALSE) + ->addWhere('id', '=', $relationship['id']) + ->addValue('is_active', FALSE) + ->execute()->first(); + $relationship2 = Relationship::create(FALSE) + ->setValues([ + 'contact_id_a' => $c1, + 'contact_id_b' => $c2, + 'start_date' => $today->format('Y-m-d'), + 'end_date' => $future->format('Y-m-d'), + 'relationship_type_id' => 1, + 'description' => "Wow, we're related!", + 'is_permission_a_b' => 1, + 'is_permission_b_a:name' => 'View only', + ])->execute()->first(); + + $cacheRecords = RelationshipCache::get(FALSE) + ->addWhere('near_contact_id', 'IN', [$c1]) + ->addWhere('is_active', '=', FALSE) + ->addSelect('near_contact_id', 'orientation', 'description', 'start_date', 'end_date') + ->execute()->indexBy('near_contact_id'); + $this->assertCount(1, $cacheRecords); + $this->assertEquals(FALSE, $cacheRecords[$c1]['is_active']); + $this->assertEquals($today, $cachedRecords[$c1]['start_date']); + $this->assertEquals($future, $cachedRecords[$c1]['end_date']); + + $cacheRecords = RelationshipCache::get(FALSE) + ->addWhere('near_contact_id', 'IN', [$c1]) + ->addWhere('is_active', '=', TRUE) + ->addSelect('near_contact_id', 'orientation', 'description', 'start_date', 'end_date') + ->execute()->indexBy('near_contact_id'); + $this->assertCount(1, $cacheRecords); + $this->assertEquals(TRUE, $cacheRecords[$c1]['is_active']); + $this->assertEquals($today, $cachedRecords[$c1]['start_date']); + $this->assertEquals($future, $cachedRecords[$c1]['end_date']); + } + } -- 2.25.1