View source
<?php
namespace Drupal\Tests\message_digest\Functional\Form;
use Drupal\message_digest\Entity\MessageDigestInterval;
use Drupal\Tests\BrowserTestBase;
class MessageDigestIntervalFormTest extends BrowserTestBase {
public static $modules = [
'block',
'message_digest',
'system',
];
protected $adminUser;
protected function setUp() {
parent::setUp();
$this
->createUser();
$this->adminUser = $this
->createUser([
'access administration pages',
'administer message digest',
'administer message templates',
]);
$this
->placeBlock('local_actions_block');
}
public function testCrud() {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('/admin/config/message');
$this
->clickLink(t('Message digest intervals'));
$this
->clickLink(t('Add digest interval'));
$edit = [
'id' => 'bi_weekly',
'label' => 'Every 2 weeks',
'interval' => '2 weeks',
'description' => 'Send digests every 2 weeks',
];
$this
->drupalPostForm(NULL, $edit, t('Save'));
$config = MessageDigestInterval::load('bi_weekly');
$this
->assertEquals('2 weeks', $config
->getInterval());
$this
->assertEquals('Every 2 weeks', $config
->label());
$this
->assertEquals('Send digests every 2 weeks', $config
->getDescription());
$this
->assertSession()
->responseContains(t('Interval %label has been added.', [
'%label' => $config
->label(),
]));
$this
->assertSession()
->addressEquals($config
->toUrl('collection')
->setAbsolute(TRUE)
->toString());
$this
->assertSession()
->pageTextContains('Every 2 weeks');
$this
->drupalGet($config
->toUrl('edit-form'));
$edit = [
'label' => 'Every 14 days',
];
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertSession()
->addressEquals($config
->toUrl('collection')
->setAbsolute(TRUE)
->toString());
$this
->assertSession()
->responseContains(t('Interval %label has been updated.', [
'%label' => 'Every 14 days',
]));
$this
->drupalGet($config
->toUrl('edit-form'));
$edit = [
'interval' => '42 bananas',
];
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertSession()
->responseContains(t('The interval %interval is invalid', [
'%interval' => $edit['interval'],
]));
$this
->drupalGet($config
->toUrl('delete-form'));
$this
->assertSession()
->responseContains(t('Delete %interval interval? This action cannot be undone.', [
'%interval' => 'Every 14 days',
]));
$this
->drupalPostForm(NULL, [], t('Delete interval'));
$this
->assertSession()
->responseContains(t('The %label message digest interval has been deleted.', [
'%label' => 'Every 14 days',
]));
$this
->assertSession()
->addressEquals($config
->toUrl('collection')
->setAbsolute(TRUE)
->toString());
\Drupal::entityTypeManager()
->getStorage('message_digest_interval')
->resetCache();
$this
->assertNull(MessageDigestInterval::load('bi_weekly'), 'The interval was not deleted.');
}
}