You are here

public function SubscribersTest::testGetFlags in Message Subscribe 8

Test the getFlags method.

@covers ::getFlags

File

tests/src/Unit/SubscribersTest.php, line 118

Class

SubscribersTest
Unit tests for the subscribers service.

Namespace

Drupal\Tests\message_subscribe\Unit

Code

public function testGetFlags() {

  // Override config mock to allow access to the prefix variable.
  $config = $this
    ->prophesize(ImmutableConfig::class);
  $config
    ->get('flag_prefix')
    ->willReturn('blah');
  $config
    ->get('debug_mode')
    ->willReturn(FALSE);
  $config_factory = $this
    ->prophesize(ConfigFactoryInterface::class);
  $config_factory
    ->get('message_subscribe.settings')
    ->willReturn($config);
  $this->configFactory = $config_factory
    ->reveal();

  // No flags.
  $flag_service = $this
    ->prophesize(FlagServiceInterface::class);
  $flag_service
    ->getAllFlags(NULL, NULL, NULL)
    ->willReturn([]);
  $this->flagService = $flag_service
    ->reveal();
  $subscribers = $this
    ->getSubscriberService();
  $this
    ->assertEquals([], $subscribers
    ->getFlags());

  // No flags matching prefix.
  $flag = $this
    ->prophesize(FlagInterface::class)
    ->reveal();
  $flag_service = $this
    ->prophesize(FlagServiceInterface::class);
  $flag_service
    ->getAllFlags(NULL, NULL, NULL)
    ->willReturn([
    'foo' => $flag,
    'bar' => $flag,
  ]);
  $this->flagService = $flag_service
    ->reveal();
  $subscribers = $this
    ->getSubscriberService();
  $this
    ->assertEquals([], $subscribers
    ->getFlags());

  // Matching prefix.
  $flag_service = $this
    ->prophesize(FlagServiceInterface::class);
  $flag_service
    ->getAllFlags(NULL, NULL, NULL)
    ->willReturn([
    'foo' => $flag,
    'bar' => $flag,
    'blah_foo' => $flag,
  ]);
  $this->flagService = $flag_service
    ->reveal();
  $subscribers = $this
    ->getSubscriberService();
  $this
    ->assertEquals([
    'blah_foo' => $flag,
  ], $subscribers
    ->getFlags());
}