You are here

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

Expanded class hierarchy of PublisherSubscriberStatusCdfAttributeTest

File

tests/src/Unit/EventSubscriber/CdfAttributes/PublisherSubscriberStatusCdfAttributeTest.php, line 24

Namespace

Drupal\Tests\acquia_contenthub\Unit\EventSubscriber\CdfAttributes
View 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

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
PublisherSubscriberStatusCdfAttributeTest::$dispatcher protected property Event dispatcher.
PublisherSubscriberStatusCdfAttributeTest::setUp protected function Overrides UnitTestCase::setUp
PublisherSubscriberStatusCdfAttributeTest::testOnPopulateAttributes public function Tests 'subscriber' and 'publisher' attributes population.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.