SimplenewsDemoTest.php in Simplenews 3.x
File
modules/simplenews_demo/tests/src/Functional/SimplenewsDemoTest.php
View source
<?php
namespace Drupal\Tests\simplenews_demo\Functional;
use Drupal\Tests\BrowserTestBase;
class SimplenewsDemoTest extends BrowserTestBase {
public static $modules = [];
protected $defaultTheme = 'classy';
protected function setUp() {
parent::setUp();
\Drupal::service('theme_installer')
->install([
'bartik',
]);
$theme_settings = $this
->config('system.theme');
$theme_settings
->set('default', 'bartik')
->save();
\Drupal::service('module_installer')
->install([
'simplenews_demo',
]);
$this
->drupalLogin($this
->drupalCreateUser([
'administer simplenews subscriptions',
'send newsletter',
'administer newsletters',
'administer simplenews settings',
]));
}
public function testInstalled() {
$this
->assertText('Simplenews multiple subscriptions');
$this
->assertText('Stay informed - subscribe to our newsletters.');
$this
->assertText('Simplenews subscription');
$this
->assertText('Stay informed - subscribe to our newsletter.');
$this
->drupalGet('admin/config/services/simplenews');
$this
->clickLink(t('Edit'));
$this
->assertEquals('This is an example newsletter. Change it.', $this
->xpath('//textarea[@id="edit-description"]')[0]
->getText());
$from_name = $this
->xpath('//input[@id="edit-from-name"]')[0];
$from_address = $this
->xpath('//input[@id="edit-from-address"]')[0];
$this
->assertEquals('Drupal', (string) $from_name
->getValue());
$this
->assertEquals('simpletest@example.com', (string) $from_address
->getValue());
$this
->drupalGet('admin/config/services/simplenews');
$this
->assertText(t('Press releases'));
$this
->assertText(t('Special offers'));
$this
->assertText(t('Weekly content update'));
$this
->drupalGet('admin/content/simplenews');
$this
->assertText('Sent press releases');
$this
->assertText('Unpublished press releases');
$this
->assertText('Pending special offers');
$this
->assertText('Stopped special offers');
$this
->assertRaw(t('Newsletter issue sent to 2 subscribers, 0 errors.'));
$this
->assertRaw(t('Newsletter issue is pending, 0 mails sent out of 3, 0 errors.'));
$this
->drupalGet('admin/people/simplenews');
$this
->assertText('a@example.com');
$this
->assertText('b@example.com');
$this
->assertText('demouser1@example.com');
}
}