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
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\message_subscribe_email\Unit\ManagerTest
Expanded class hierarchy of ManagerTest
File
- message_subscribe_email/
tests/ src/ Unit/ ManagerTest.php, line 19
Namespace
Drupal\Tests\message_subscribe_email\UnitView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ManagerTest:: |
public | function | Data provider for testGetFlags(). | |
ManagerTest:: |
public | function | Tests the flag retrieval. | |
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. | |
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. | |
UnitTestCase:: |
protected | function | 340 |