2022-05-15 18:22:30 +00:00
|
|
|
<?php declare(strict_types = 1);
|
|
|
|
|
|
|
|
namespace Drupal\Tests\opencase\Unit;
|
|
|
|
|
|
|
|
use Drupal\Tests\UnitTestCase;
|
|
|
|
use Drupal\opencase\Utils;
|
|
|
|
|
|
|
|
class UtilsTest extends UnitTestCase{
|
|
|
|
public function setUp(): void {
|
|
|
|
/** @var \Drupal\core\Entity\EntityTypeManager&\PHPUnit\Framework\MockObject\MockObject $entityTypeManager */
|
|
|
|
$this->entityTypeManager = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManager')->disableOriginalConstructor()->getMock();
|
|
|
|
$this->utils = new Utils($this->entityTypeManager);
|
|
|
|
$this->storage = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageInterface')->getMock();
|
|
|
|
$this->query = $this->getMockBuilder('\\Drupal\\Core\\Entity\\Query\\QueryInterface')->getMock();
|
|
|
|
$this->entityTypeManager->method('getStorage')->willReturn($this->storage);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetTidByNameGetsTid():void {
|
|
|
|
$term_entity = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityBase')->disableOriginalConstructor()->getMock();
|
|
|
|
$term_entity->expects($this->once())->method('id')->willReturn('3');
|
|
|
|
$this->storage->expects($this->once())->method('loadByProperties')->with(['name' => 'foo', 'vid' => 'bar'])
|
|
|
|
->willReturn([$term_entity]);
|
|
|
|
$this->assertEquals($this->utils->getTidByName('foo', 'bar'), 3);
|
|
|
|
}
|
2022-05-16 09:01:16 +00:00
|
|
|
public function testAddConditionToQueryAddsEqualsIfNoOperatorProvided():void {
|
|
|
|
$this->query->expects($this->exactly(1))->method('condition')->with("1", "2", "=");
|
|
|
|
$this->utils->addConditionsToQuery($this->query, [["1","2"]]);
|
|
|
|
|
2022-05-15 18:22:30 +00:00
|
|
|
}
|
2022-05-15 18:26:54 +00:00
|
|
|
public function testAddConditionToQueryAddsTheRightAmountOfConditions():void {
|
2022-05-15 18:22:30 +00:00
|
|
|
$this->query->expects($this->exactly(4))->method('condition');
|
|
|
|
$this->utils->addConditionsToQuery($this->query, [["1","2","3"], ["lk", "n", "kk"], ['sfd', 'ds', 'fds'], ["1","2","3"]]);
|
|
|
|
}
|
|
|
|
}
|