32 lines
1.6 KiB
PHP
32 lines
1.6 KiB
PHP
|
<?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);
|
||
|
}
|
||
|
}
|