PublisherSubscriberStatusCdfAttributeTest.php in Acquia Content Hub 8.2
File
tests/src/Unit/EventSubscriber/CdfAttributes/PublisherSubscriberStatusCdfAttributeTest.php
View source
<?php
namespace Drupal\Tests\acquia_contenthub\Unit\EventSubscriber\CdfAttributes;
use Acquia\ContentHubClient\CDF\ClientCDFObject;
use Acquia\ContentHubClient\CDFAttribute;
use Drupal\acquia_contenthub\AcquiaContentHubEvents;
use Drupal\acquia_contenthub\Event\BuildClientCdfEvent;
use Drupal\acquia_contenthub\EventSubscriber\CdfAttributes\PublisherSubscriberStatusCdfAttribute;
use Drupal\acquia_contenthub\PubSubModuleStatusChecker;
use Drupal\Core\Extension\ModuleHandler;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\EventDispatcher\EventDispatcher;
class PublisherSubscriberStatusCdfAttributeTest extends UnitTestCase {
protected $dispatcher;
protected function setUp() {
parent::setUp();
$this->dispatcher = new EventDispatcher();
$module_handler_service = $this
->getMockBuilder(ModuleHandler::class)
->disableOriginalConstructor()
->getMock();
$checker = new PubSubModuleStatusChecker($module_handler_service);
$this->dispatcher
->addSubscriber(new PublisherSubscriberStatusCdfAttribute($checker));
}
public function testOnPopulateAttributes() {
$isPublisher = TRUE;
$isSubscriber = FALSE;
$cdf = $this
->getMockBuilder(ClientCDFObject::class)
->disableOriginalConstructor()
->getMock();
$publiherCdfAttribute = $this
->getMockBuilder(CDFAttribute::class)
->disableOriginalConstructor()
->getMock();
$subscriberCdfAttribute = $this
->getMockBuilder(CDFAttribute::class)
->disableOriginalConstructor()
->getMock();
$publiherCdfAttribute
->method('getType')
->willReturn(CDFAttribute::TYPE_BOOLEAN);
$publiherCdfAttribute
->method('getValue')
->willReturn($isPublisher);
$subscriberCdfAttribute
->method('getType')
->willReturn(CDFAttribute::TYPE_BOOLEAN);
$subscriberCdfAttribute
->method('getValue')
->willReturn($isSubscriber);
$cdf
->method('getAttribute')
->will($this
->returnValueMap([
[
'publisher',
$publiherCdfAttribute,
],
[
'subscriber',
$subscriberCdfAttribute,
],
]));
$event = $this
->getMockBuilder(BuildClientCdfEvent::class)
->disableOriginalConstructor()
->getMock();
$event
->method('isPropagationStopped')
->willReturn(TRUE);
$event
->method('getCdf')
->willReturn($cdf);
$this->dispatcher
->dispatch(AcquiaContentHubEvents::BUILD_CLIENT_CDF, $event);
$cdf = $event
->getCdf();
$publisher = $cdf
->getAttribute('publisher');
$subscriber = $cdf
->getAttribute('subscriber');
$this
->assertEquals(CDFAttribute::TYPE_BOOLEAN, $publisher
->getType());
$this
->assertEquals($isPublisher, $publisher
->getValue());
$this
->assertEquals(CDFAttribute::TYPE_BOOLEAN, $subscriber
->getType());
$this
->assertEquals($isSubscriber, $subscriber
->getValue());
}
}