class SMTPConfigFormTest in SMTP Authentication Support 8
Validate requirements for SMTPConfigForm.
@group SMTP
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\smtp\Unit\SMTPConfigFormTest
Expanded class hierarchy of SMTPConfigFormTest
File
- tests/
src/ Unit/ SMTPConfigFormTest.php, line 24
Namespace
Drupal\Tests\smtp\UnitView source
class SMTPConfigFormTest extends UnitTestCase {
/**
* Test setup.
*/
public function setup() {
$this->mockConfigFactory = $this
->prophesize(ConfigFactoryInterface::class);
$this->mockConfig = $this
->prophesize(Config::class);
$this->mockConfigFactory
->get('smtp.settings')
->willReturn($this->mockConfig
->reveal());
$this->mockConfigFactory
->getEditable('smtp.settings')
->willReturn($this->mockConfig
->reveal());
$this->mockConfigSystemSite = $this
->prophesize(Config::class);
$this->mockConfigSystemSite
->get('name')
->willReturn('Site name');
$this->mockConfigFactory
->get('system.site')
->willReturn($this->mockConfigSystemSite
->reveal());
$this->mockMessenger = $this
->prophesize(Messenger::class);
$this->mockEmailValidator = $this
->prophesize(EmailValidatorInterface::class);
$this->mockCurrentUser = $this
->prophesize(AccountProxyInterface::class);
$this->mockMailManager = $this
->prophesize(MailManagerInterface::class);
$this->mockModuleHandler = $this
->prophesize(ModuleHandlerInterface::class);
$mockContainer = $this->mockContainer = $this
->prophesize(ContainerInterface::class);
$mockContainer
->get('config.factory')
->willReturn($this->mockConfigFactory
->reveal());
$mockContainer
->get('messenger')
->willReturn($this->mockMessenger
->reveal());
$mockContainer
->get('email.validator')
->willReturn($this->mockEmailValidator
->reveal());
$mockContainer
->get('current_user')
->willReturn($this->mockCurrentUser
->reveal());
$mockContainer
->get('plugin.manager.mail')
->willReturn($this->mockMailManager
->reveal());
$mockContainer
->get('module_handler')
->willReturn($this->mockModuleHandler
->reveal());
$mockStringTranslation = $this
->prophesize(TranslationInterface::class);
$mockStringTranslation
->translate(Argument::any())
->willReturnArgument(0);
$mockStringTranslation
->translate(Argument::any(), Argument::any())
->willReturnArgument(0);
$mockStringTranslation
->translateString(Argument::any())
->willReturn('.');
$mockContainer
->get('string_translation')
->willReturn($mockStringTranslation
->reveal());
\Drupal::setContainer($this->mockContainer
->reveal());
}
/**
* Sets the default smtp config.
*/
public function setDefaultConfig() {
$this->mockConfig
->get('smtp_on')
->willReturn(TRUE);
$this->mockConfig
->get('smtp_host')
->willReturn('');
$this->mockConfig
->get('smtp_hostbackup')
->willReturn('');
$this->mockConfig
->get('smtp_port')
->willReturn('');
$this->mockConfig
->get('smtp_protocol')
->willReturn('');
$this->mockConfig
->get('smtp_autotls')
->willReturn(TRUE);
$this->mockConfig
->get('smtp_timeout')
->willReturn('');
$this->mockConfig
->get('smtp_username')
->willReturn('');
$this->mockConfig
->get('smtp_password')
->willReturn('');
$this->mockConfig
->get('smtp_from')
->willReturn('');
$this->mockConfig
->get('smtp_fromname')
->willReturn('');
$this->mockConfig
->get('smtp_allowhtml')
->willReturn('');
$this->mockConfig
->get('smtp_client_hostname')
->willReturn('');
$this->mockConfig
->get('smtp_client_helo')
->willReturn('');
$this->mockConfig
->get('smtp_debugging')
->willReturn('');
$this->mockConfig
->get('smtp_keepalive')
->willReturn(FALSE);
$this->mockConfig
->get('smtp_reroute_address')
->willReturn('');
}
/**
* Test if enabled message is properly shown.
*/
public function testBuildFormEnabledMessage() {
$this
->setDefaultConfig();
$this->mockConfig
->get('smtp_on')
->willReturn(TRUE);
$formBuilder = SMTPConfigForm::create($this->mockContainer
->reveal());
$form = [];
$formBuilder
->buildForm($form, new FormState());
$this->mockMessenger
->addMessage(Argument::which('getUntranslatedString', 'SMTP module is active.'))
->shouldHaveBeenCalled();
}
/**
* Test if enabled message is properly shown.
*/
public function testBuildFormDisabledMessage() {
$this
->setDefaultConfig();
$this->mockConfig
->get('smtp_on')
->willReturn(FALSE);
$formBuilder = SMTPConfigForm::create($this->mockContainer
->reveal());
$form = [];
$formBuilder
->buildForm($form, new FormState());
$this->mockMessenger
->addMessage(Argument::which('getUntranslatedString', 'SMTP module is INACTIVE.'))
->shouldHaveBeenCalled();
}
/**
* Test form id.
*/
public function testGetFormId() {
$formBuilder = SMTPConfigForm::create($this->mockContainer
->reveal());
$form_id = $formBuilder
->getFormId();
$this
->assertEquals('smtp_admin_settings', $form_id);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
SMTPConfigFormTest:: |
public | function | Sets the default smtp config. | |
SMTPConfigFormTest:: |
public | function | Test setup. | |
SMTPConfigFormTest:: |
public | function | Test if enabled message is properly shown. | |
SMTPConfigFormTest:: |
public | function | Test if enabled message is properly shown. | |
SMTPConfigFormTest:: |
public | function | Test form id. | |
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 |