Added test for OCActor::getCountOfCaseProvisions

This commit is contained in:
naomi 2022-06-05 12:25:28 +01:00
parent 457b4ad694
commit d81e1b3711

View File

@ -0,0 +1,31 @@
<?php declare(strict_types = 1);
namespace Drupal\Tests\opencase\Unit;
use Drupal\Tests\UnitTestCase;
use Drupal\opencase_entities\Entity\OCActor;
use Drupal\Core\DependencyInjection\ContainerBuilder;
class OCActorTest extends UnitTestCase{
public function setUp(): void {
$this->entityTypeManager = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManager')->disableOriginalConstructor()->getMock();
$container = new ContainerBuilder();
$container->set('entity_type.manager', $this->entityTypeManager);
\Drupal::setContainer($container);
$this->actor = $this->getMockBuilder(OCActor::class)->disableOriginalConstructor()
->onlyMethods(['id'])
->getMock();
}
public function testGetCountOfCaseProvisions(){
$caseProvisionStorage = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageInterface')->disableOriginalConstructor()->getMock();
$this->entityTypeManager->expects($this->once())->method('getStorage')->with('oc_case_provision')->willReturn($caseProvisionStorage);
$query = $this->getMockBuilder('\\Drupal\\Core\\Entity\\Query\\QueryInterface')->getMock();
$caseProvisionStorage->method('getQuery')->willReturn($query);
$this->actor->expects($this->once())->method('id')->willReturn(5);
$query->expects($this->once())->method('condition')->with('oc_provider', 5);
$query->expects($this->once())->method('execute')->willReturn([1,2,3,4]);
$count = $this->actor->getCountOfCaseProvisions();
$this->assertTrue($count == 4);
}
}