You are here

class MassContactTest in Mass Contact 8

Same name in this branch
  1. 8 tests/src/Unit/MassContactTest.php \Drupal\Tests\mass_contact\Unit\MassContactTest
  2. 8 tests/src/Kernel/MassContactTest.php \Drupal\Tests\mass_contact\Kernel\MassContactTest

Unit tests for the Mass Contact helper service.

@group mass_contact

@coversDefaultClass \Drupal\mass_contact\MassContact

Hierarchy

Expanded class hierarchy of MassContactTest

File

tests/src/Unit/MassContactTest.php, line 22

Namespace

Drupal\Tests\mass_contact\Unit
View source
class MassContactTest extends UnitTestCase {

  /**
   * Tests html support detection.
   *
   * @covers ::htmlSupported
   */
  public function testHtmlSupported() {

    // Test for no modules supporting html email.
    $module_handler = $this
      ->prophesize(ModuleHandlerInterface::class);
    $module_handler
      ->moduleExists('mimemail')
      ->willReturn(FALSE);
    $module_handler
      ->moduleExists('swiftmailer')
      ->willReturn(FALSE);
    $config_factory = $this
      ->prophesize(ConfigFactoryInterface::class)
      ->reveal();
    $queue_factory = $this
      ->prophesize(QueueFactory::class)
      ->reveal();
    $mail_manager = $this
      ->prophesize(MailManagerInterface::class)
      ->reveal();
    $entity_type_manager = $this
      ->prophesize(EntityTypeManagerInterface::class)
      ->reveal();
    $opt_out = $this
      ->prophesize(OptOutInterface::class)
      ->reveal();
    $account = $this
      ->prophesize(AccountInterface::class)
      ->reveal();
    $fixture = new MassContact($module_handler
      ->reveal(), $config_factory, $queue_factory, $mail_manager, $entity_type_manager, $opt_out, $account);
    $this
      ->assertFalse($fixture
      ->htmlSupported());

    // Mime mail module.
    $module_handler
      ->moduleExists('mimemail')
      ->willReturn(TRUE);
    $fixture = new MassContact($module_handler
      ->reveal(), $config_factory, $queue_factory, $mail_manager, $entity_type_manager, $opt_out, $account);
    $this
      ->assertTrue($fixture
      ->htmlSupported());

    // Swiftmailer module.
    $module_handler
      ->moduleExists('mimemail')
      ->willReturn(FALSE);
    $module_handler
      ->moduleExists('swiftmailer')
      ->willReturn(TRUE);
    $fixture = new MassContact($module_handler
      ->reveal(), $config_factory, $queue_factory, $mail_manager, $entity_type_manager, $opt_out, $account);
    $this
      ->assertTrue($fixture
      ->htmlSupported());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MassContactTest::testHtmlSupported public function Tests html support detection.
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