Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace Drupal\Tests\smtp\Unit;
use Drupal\Core\Config\Config;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\FormState;
use Drupal\Core\Messenger\Messenger;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\smtp\Form\SMTPConfigForm;
use Drupal\Tests\UnitTestCase;
use Prophecy\Argument;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Validate requirements for ProceedingsRealmNegotiator.
*
* @group SMTP
*/
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);
$mockContainer = $this->mockContainer = $this->prophesize(ContainerInterface::class);
$mockContainer->get('config.factory')->willReturn($this->mockConfigFactory->reveal());
$mockContainer->get('messenger')->willReturn($this->mockMessenger->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_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('');
}
/**
* 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();
}
}