added extra conditions param to getCountOfCaseProvisions
This commit is contained in:
parent
737104d7bd
commit
fb9737ca04
@ -211,6 +211,9 @@ class OCActor extends RevisionableContentEntityBase implements OCActorInterface
|
|||||||
public function getCountOfCaseProvisions(array $conditionsToApplyToCaseProvisionQuery = []): int {
|
public function getCountOfCaseProvisions(array $conditionsToApplyToCaseProvisionQuery = []): int {
|
||||||
$query = \Drupal::entityQuery('oc_case_provision');
|
$query = \Drupal::entityQuery('oc_case_provision');
|
||||||
$query->condition('oc_provider', $this->id());
|
$query->condition('oc_provider', $this->id());
|
||||||
|
foreach($conditionsToApplyToCaseProvisionQuery as $condition) {
|
||||||
|
$query->condition($condition[0], $condition[1], $condition[2] ?? '=');
|
||||||
|
}
|
||||||
return count($query->execute());
|
return count($query->execute());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ class OCActorTest extends UnitTestCase{
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetCountOfCaseProvisions(): void{
|
public function testGetCountOfCaseProvisionsWithNoExtraConditions(): void{
|
||||||
$storage = $this->getStorage($this->etm, 'oc_case_provision');
|
$storage = $this->getStorage($this->etm, 'oc_case_provision');
|
||||||
$query = $this->getQuery($storage);
|
$query = $this->getQuery($storage);
|
||||||
$actor = $this->getMockBuilder('\\Drupal\\opencase_entities\\Entity\\OCActor')->disableOriginalConstructor()
|
$actor = $this->getMockBuilder('\\Drupal\\opencase_entities\\Entity\\OCActor')->disableOriginalConstructor()
|
||||||
@ -27,4 +27,35 @@ class OCActorTest extends UnitTestCase{
|
|||||||
$count = $actor->getCountOfCaseProvisions();
|
$count = $actor->getCountOfCaseProvisions();
|
||||||
$this->assertTrue($count == 4);
|
$this->assertTrue($count == 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testGetCountOfCaseProvisionsWithExtraConditions(): void{
|
||||||
|
$storage = $this->getStorage($this->etm, 'oc_case_provision');
|
||||||
|
$query = $this->getQuery($storage);
|
||||||
|
$actor = $this->getMockBuilder('\\Drupal\\opencase_entities\\Entity\\OCActor')->disableOriginalConstructor()
|
||||||
|
->onlyMethods(['id'])
|
||||||
|
->getMock();
|
||||||
|
$actor->expects($this->once())->method('id')->willReturn(5);
|
||||||
|
$query->expects($this->exactly(2))->method('condition')->withConsecutive(
|
||||||
|
['oc_provider', 5],
|
||||||
|
['some_date_field', '2022-01-01', '<']);
|
||||||
|
$query->expects($this->once())->method('execute')->willReturn([1,2,3,4]);
|
||||||
|
$count = $actor->getCountOfCaseProvisions([['some_date_field', '2022-01-01', '<']]);
|
||||||
|
$this->assertTrue($count == 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetCountOfCaseProvisionsWithExtraConditionsWithAssumedEqualityOperator(): void{
|
||||||
|
$storage = $this->getStorage($this->etm, 'oc_case_provision');
|
||||||
|
$query = $this->getQuery($storage);
|
||||||
|
$actor = $this->getMockBuilder('\\Drupal\\opencase_entities\\Entity\\OCActor')->disableOriginalConstructor()
|
||||||
|
->onlyMethods(['id'])
|
||||||
|
->getMock();
|
||||||
|
$actor->expects($this->once())->method('id')->willReturn(5);
|
||||||
|
$query->expects($this->exactly(2))->method('condition')->withConsecutive(
|
||||||
|
['oc_provider', 5],
|
||||||
|
['some_date_field', '2022-01-01', '=']);
|
||||||
|
$query->expects($this->once())->method('execute')->willReturn([1,2,3,4]);
|
||||||
|
$count = $actor->getCountOfCaseProvisions([['some_date_field', '2022-01-01']]);
|
||||||
|
$this->assertTrue($count == 4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user