AchVersionAttributeTest.php in Acquia Content Hub 8.2
File
tests/src/Kernel/EventSubscriber/CdfAttributes/AchVersionAttributeTest.php
View source
<?php
namespace Drupal\Tests\acquia_contenthub\Kernel\EventSubscriber\CdfAttributes;
use Acquia\ContentHubClient\CDF\ClientCDFObject;
use Acquia\ContentHubClient\CDFAttribute;
use Drupal\acquia_contenthub\AcquiaContentHubEvents;
use Drupal\acquia_contenthub\Client\ProjectVersionClient;
use Drupal\acquia_contenthub\Event\BuildClientCdfEvent;
use Drupal\acquia_contenthub\EventSubscriber\CdfAttributes\AchVersionAttribute;
use Drupal\Core\Extension\Extension;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\KernelTests\KernelTestBase;
use Prophecy\Argument;
class AchVersionAttributeTest extends KernelTestBase {
public static $modules = [
'acquia_contenthub_server_test',
'acquia_contenthub',
'depcalc',
'user',
];
protected $dispatcher;
protected function setUp() {
parent::setUp();
$this->dispatcher = $this->container
->get('event_dispatcher');
}
public function testAchVersionCdfAttribute() {
$cdf = ClientCDFObject::create('uuid', [
'settings' => [
'name' => 'test',
],
]);
$event = new BuildClientCdfEvent($cdf);
$this->dispatcher
->dispatch(AcquiaContentHubEvents::BUILD_CLIENT_CDF, $event);
$ach_attribute = $event
->getCdf()
->getAttribute('ch_version');
$this
->assertNotNull($ach_attribute);
$this
->assertEquals(CDFAttribute::TYPE_ARRAY_STRING, $ach_attribute
->getType());
}
public function testVersionFileMissing() {
$module_handler = $this
->prophesize(ModuleHandlerInterface::class);
$extension = $this
->prophesize(Extension::class);
$extension
->getPath()
->willReturn('');
$module_handler
->getModule(Argument::any())
->willReturn($extension
->reveal());
$pv_client = $this
->prophesize(ProjectVersionClient::class);
$cdf = ClientCDFObject::create('uuid', [
'settings' => [
'name' => 'test',
],
]);
$event = new BuildClientCdfEvent($cdf);
$ach_version_setter = new AchVersionAttribute($pv_client
->reveal(), $module_handler
->reveal());
$this
->expectException(\Exception::class);
$this
->expectExceptionMessage('ACH YAML version file doesn\'t exist.');
$ach_version_setter
->onBuildClientCdf($event);
}
}