public function MessageDigestIntervalFormTest::testCrud in Message Digest 8
Tests CRUD operations.
File
- tests/
src/ Functional/ Form/ MessageDigestIntervalFormTest.php, line 48
Class
- MessageDigestIntervalFormTest
- Tests the message digest interval UI and forms.
Namespace
Drupal\Tests\message_digest\Functional\FormCode
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'));
/** @var \Drupal\message_digest\Entity\MessageDigestIntervalInterface $config */
$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');
// Edit the interval.
$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',
]));
// Try an invalid interval.
$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'],
]));
// Delete the 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.');
}