From 2c65aff7e1c2ed9f93423dde2f394ce18cfd3a25 Mon Sep 17 00:00:00 2001 From: naomi Date: Tue, 7 Jun 2022 14:22:33 +0100 Subject: [PATCH] added method to case to get case provisions --- modules/opencase_cases/src/Entity/OCCase.php | 7 +++-- tests/src/Unit/OCCaseTest.php | 33 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 tests/src/Unit/OCCaseTest.php diff --git a/modules/opencase_cases/src/Entity/OCCase.php b/modules/opencase_cases/src/Entity/OCCase.php index 31cd16a..b78aad4 100644 --- a/modules/opencase_cases/src/Entity/OCCase.php +++ b/modules/opencase_cases/src/Entity/OCCase.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\RevisionableContentEntityBase; use Drupal\Core\Entity\RevisionableInterface; use Drupal\Core\Entity\EntityChangedTrait; use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Entity\EntityTypeManager; use Drupal\user\UserInterface; /** @@ -92,8 +93,10 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface ]; } - public function getCaseProvisions() { - + public function getCaseProvisionIds(EntityTypeManager $etm): array { + $query = \Drupal::entityTypeManager()->getStorage('oc_case_provision')->getQuery(); + $query->condition('oc_case.target_id', $this->id()); + return $query->execute(); } public function deleteCaseProvisions(): void { diff --git a/tests/src/Unit/OCCaseTest.php b/tests/src/Unit/OCCaseTest.php new file mode 100644 index 0000000..32f74dd --- /dev/null +++ b/tests/src/Unit/OCCaseTest.php @@ -0,0 +1,33 @@ +etm = $this->getEntityTypeManager(); + $this->getContainer([ + 'entity_type.manager' => $this->etm + ]); + $this->case = $this->getMockBuilder('\\Drupal\\opencase_cases\\Entity\\OCCase')->disableOriginalConstructor() + ->onlyMethods(['id']) + ->getMock(); + } + + public function testGetCaseProvisionIds(): void{ + $storage = $this->getStorage($this->etm, 'oc_case_provision'); + $query = $this->getQuery($storage); + $this->case->expects($this->once())->method('id')->willReturn(5); + $query->expects($this->once())->method('condition')->withConsecutive( + ['oc_case.target_id', 5]); + $query->expects($this->once())->method('execute')->willReturn([1,2,3,4]); + $ids = $this->case->getCaseProvisionIds($this->etm); + $this->assertTrue($ids == [1,2,3,4]); + } +}