You are here

class ManagerTest in Message Subscribe 8

Unit tests for the message subscribe email manager utility class.

@coversDefaultClass \Drupal\message_subscribe_email\Manager

@group message_subscribe_email

Hierarchy

Expanded class hierarchy of ManagerTest

File

message_subscribe_email/tests/src/Unit/ManagerTest.php, line 19

Namespace

Drupal\Tests\message_subscribe_email\Unit
View source
class ManagerTest extends UnitTestCase {

  /**
   * Tests the flag retrieval.
   *
   * @param array $expected
   *   The expected flags.
   * @param array $flags
   *   The available flags for the flag service.
   *
   * @covers ::getFlags
   *
   * @dataProvider providerTestGetFlags
   */
  public function testGetFlags(array $expected, array $flags) {
    $flag_service = $this
      ->prophesize(FlagServiceInterface::class);
    $flag_service
      ->getAllFlags()
      ->willReturn($flags);
    $config = $this
      ->prophesize(ImmutableConfig::class);
    $config
      ->get('flag_prefix')
      ->willReturn('non_standard_prefix');
    $config_factory = $this
      ->prophesize(ConfigFactoryInterface::class);
    $config_factory
      ->get('message_subscribe_email.settings')
      ->willReturn($config
      ->reveal());
    $manager = new Manager($flag_service
      ->reveal(), $config_factory
      ->reveal());
    $this
      ->assertEquals($expected, $manager
      ->getFlags());
  }

  /**
   * Data provider for testGetFlags().
   *
   * @return array
   *   An array of arguments for self::testGetFlags().
   */
  public function providerTestGetFlags() {

    // No flags.
    $return[] = [
      [],
      [],
    ];

    // No matching flags.
    $flag = $this
      ->prophesize(FlagInterface::class)
      ->reveal();
    $return[] = [
      [],
      [
        'foo_flag' => $flag,
      ],
    ];

    // A few matching flags.
    $return[] = [
      [
        'non_standard_prefix_one' => $flag,
        'non_standard_prefix_two' => $flag,
      ],
      [
        'foo_flag' => $flag,
        'non_standard_prefix_one' => $flag,
        'non_standard_prefix_two' => $flag,
      ],
    ];
    return $return;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ManagerTest::providerTestGetFlags public function Data provider for testGetFlags().
ManagerTest::testGetFlags public function Tests the flag retrieval.
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