You are here

class DeliveryCandidateTest in Message Subscribe 8

Unit tests for the delivery candidate class.

@group message_subscribe

@coversDefaultClass \Drupal\message_subscribe\Subscribers\DeliveryCandidate

Hierarchy

Expanded class hierarchy of DeliveryCandidateTest

File

tests/src/Unit/Subscribers/DeliveryCandidateTest.php, line 16

Namespace

Drupal\Tests\message_subscribe\Unit\Subscribers
View source
class DeliveryCandidateTest extends UnitTestCase {

  /**
   * Test construction.
   *
   * @covers ::__construct
   * @covers ::getFlags
   * @covers ::getNotifiers
   * @covers ::getAccountId
   */
  public function testConstruct() {
    $candidate = new DeliveryCandidate([
      'foo',
    ], [
      'bar',
    ], 123);
    $this
      ->assertEquals([
      'foo' => 'foo',
    ], $candidate
      ->getFlags());
    $this
      ->assertEquals([
      'bar' => 'bar',
    ], $candidate
      ->getNotifiers());
    $this
      ->assertEquals(123, $candidate
      ->getAccountId());
  }

  /**
   * Test adding and removing flags.
   *
   * @covers ::addFlag
   * @covers ::removeFlag
   * @covers ::getFlags
   * @covers ::setFlags
   */
  public function testAddRemoveFlag() {
    $candidate = new DeliveryCandidate([], [], 42);
    $this
      ->assertEmpty($candidate
      ->getFlags());
    $this
      ->assertInstanceOf(DeliveryCandidateInterface::class, $candidate
      ->addFlag('foo'));
    $this
      ->assertEquals([
      'foo' => 'foo',
    ], $candidate
      ->getFlags());
    $this
      ->assertInstanceOf(DeliveryCandidateInterface::class, $candidate
      ->removeFlag('foo'));
    $this
      ->assertEmpty($candidate
      ->getFlags());
    $this
      ->assertInstanceOf(DeliveryCandidateInterface::class, $candidate
      ->setFlags([
      'foo',
      'bar',
    ]));
    $this
      ->assertEquals([
      'foo' => 'foo',
      'bar' => 'bar',
    ], $candidate
      ->getFlags());
  }

  /**
   * Test adding and removing flags.
   *
   * @covers ::addNotifier
   * @covers ::removeNotifier
   * @covers ::getNotifiers
   * @covers ::setNotifiers
   */
  public function testAddRemoveNotifier() {
    $candidate = new DeliveryCandidate([], [], 42);
    $this
      ->assertEmpty($candidate
      ->getNotifiers());
    $this
      ->assertInstanceOf(DeliveryCandidateInterface::class, $candidate
      ->addNotifier('foo'));
    $this
      ->assertEquals([
      'foo' => 'foo',
    ], $candidate
      ->getNotifiers());
    $this
      ->assertInstanceOf(DeliveryCandidateInterface::class, $candidate
      ->removeNotifier('foo'));
    $this
      ->assertEmpty($candidate
      ->getNotifiers());
    $this
      ->assertInstanceOf(DeliveryCandidateInterface::class, $candidate
      ->setNotifiers([
      'foo',
      'bar',
    ]));
    $this
      ->assertEquals([
      'foo' => 'foo',
      'bar' => 'bar',
    ], $candidate
      ->getNotifiers());
  }

  /**
   * Test setting account ID.
   *
   * @covers ::getAccountId
   * @covers ::setAccountId
   */
  public function testAccountId() {
    $candidate = new DeliveryCandidate([], [], 42);
    $this
      ->assertEquals(42, $candidate
      ->getAccountId());
    $this
      ->assertInstanceOf(DeliveryCandidateInterface::class, $candidate
      ->setAccountId(123));
    $this
      ->assertEquals(123, $candidate
      ->getAccountId());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeliveryCandidateTest::testAccountId public function Test setting account ID.
DeliveryCandidateTest::testAddRemoveFlag public function Test adding and removing flags.
DeliveryCandidateTest::testAddRemoveNotifier public function Test adding and removing flags.
DeliveryCandidateTest::testConstruct public function Test construction.
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.
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.
UnitTestCase::setUp protected function 340