class PublisherSubscriberStatusCdfAttributeTest in Acquia Content Hub 8.2
Tests the PublisherSubscriberStatusCdfAttribute.
@group acquia_contenthub
@package Drupal\Tests\acquia_contenthub\Unit\EventSubscriber\CdfAttributes
@covers \Drupal\acquia_contenthub\EventSubscriber\CdfAttributes\PublisherSubscriberStatusCdfAttribute
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\acquia_contenthub\Unit\EventSubscriber\CdfAttributes\PublisherSubscriberStatusCdfAttributeTest
Expanded class hierarchy of PublisherSubscriberStatusCdfAttributeTest
File
- tests/
src/ Unit/ EventSubscriber/ CdfAttributes/ PublisherSubscriberStatusCdfAttributeTest.php, line 24
Namespace
Drupal\Tests\acquia_contenthub\Unit\EventSubscriber\CdfAttributesView source
class PublisherSubscriberStatusCdfAttributeTest extends UnitTestCase {
/**
* Event dispatcher.
*
* @var \Symfony\Component\EventDispatcher\EventDispatcher
*/
protected $dispatcher;
/**
* {@inheritdoc}
*/
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));
}
/**
* Tests 'subscriber' and 'publisher' attributes population.
*/
public function testOnPopulateAttributes() {
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$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());
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
PublisherSubscriberStatusCdfAttributeTest:: |
protected | property | Event dispatcher. | |
PublisherSubscriberStatusCdfAttributeTest:: |
protected | function |
Overrides UnitTestCase:: |
|
PublisherSubscriberStatusCdfAttributeTest:: |
public | function | Tests 'subscriber' and 'publisher' attributes population. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |