added method to case to get case provisions
This commit is contained in:
parent
44b9680e0c
commit
2c65aff7e1
@ -9,6 +9,7 @@ use Drupal\Core\Entity\RevisionableContentEntityBase;
|
|||||||
use Drupal\Core\Entity\RevisionableInterface;
|
use Drupal\Core\Entity\RevisionableInterface;
|
||||||
use Drupal\Core\Entity\EntityChangedTrait;
|
use Drupal\Core\Entity\EntityChangedTrait;
|
||||||
use Drupal\Core\Entity\EntityTypeInterface;
|
use Drupal\Core\Entity\EntityTypeInterface;
|
||||||
|
use Drupal\Core\Entity\EntityTypeManager;
|
||||||
use Drupal\user\UserInterface;
|
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 {
|
public function deleteCaseProvisions(): void {
|
||||||
|
33
tests/src/Unit/OCCaseTest.php
Normal file
33
tests/src/Unit/OCCaseTest.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace Drupal\Tests\opencase\Unit;
|
||||||
|
|
||||||
|
use Drupal\Tests\UnitTestCase;
|
||||||
|
|
||||||
|
class OCCaseTest extends UnitTestCase{
|
||||||
|
|
||||||
|
use EntityTrait;
|
||||||
|
|
||||||
|
private $case;
|
||||||
|
|
||||||
|
public function setUp(): void {
|
||||||
|
$this->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]);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user