public function SiteStatusMessageSchedulerTestCase::testPost in Site Status Message 7
Tests for checking form posts.
File
- modules/
site_status_message_scheduler/ tests/ site_status_message_scheduler.test, line 72 - Tests for Site Status Message Scheduler module.
Class
- SiteStatusMessageSchedulerTestCase
- Class SiteStatusMessageSchedulerTestCase.
Code
public function testPost() {
$this
->adminLogin();
// Test 1. Test message appears with start date in past and no end date.
$this
->drupalGet($this->siteStatusMessageAdminPage);
$this
->drupalPost($this->siteStatusMessageAdminPage, $this->validFormPost, 'Save configuration');
$this
->drupalGet('<front>');
$this
->assertRaw('<div id="site-status-message" class="site-status-message" role="alert">', 'Check the Site Status Message html div appears on the page.');
$this
->assertText(t('This is a test message.'), 'Check that Site Status Message text is showing on a content page.');
// Test 2. Set the End date to a future date.
$end = new DateTime('now +1 day');
$this->validFormPost['site_status_message_use_end_date'] = TRUE;
$this->validFormPost['site_status_message_end_date[date]'] = $end
->format('Y-m-d');
$this->validFormPost['site_status_message_end_date[time]'] = $end
->format('H:i:s');
$this
->drupalPost($this->siteStatusMessageAdminPage, $this->validFormPost, 'Save configuration');
$this
->drupalGet('<front>');
$this
->assertRaw('<div id="site-status-message" class="site-status-message" role="alert">', 'Check the Site Status Message html div appears on the page.');
$this
->assertText(t('This is a test message.'), 'Check that Site Status Message text is showing on a content page.');
// Test 3. Set the End Date to very small time in future so it will expire.
$end = new DateTime('now +2 seconds');
$this->validFormPost['site_status_message_end_date[date]'] = $end
->format('Y-m-d');
$this->validFormPost['site_status_message_end_date[time]'] = $end
->format('H:i:s');
$this
->drupalPost($this->siteStatusMessageAdminPage, $this->validFormPost, 'Save configuration');
$this
->drupalGet('<front>');
$this
->assertRaw('<div id="site-status-message" class="site-status-message" role="alert">', 'Check the Site Status Message html div appears on the page.');
$this
->assertText(t('This is a test message.'), 'Check that Site Status Message text is showing on a content page.');
// Wait 3 seconds. Reload the page.
debug('Waiting before reloading.');
sleep(3);
$this
->drupalGet('<front>');
$this
->assertNoRaw('<div id="site-status-message" class="site-status-message" role="alert">', 'Check the Site Status Message html div no longer appears on the page.');
$this
->assertNoText(t('This is a test message.'), 'Check that Site Status Message text is no longer showing on a content page.');
// Test 4. Set the start date to a very small time in the future.
$start = new DateTime('now +2 seconds');
$this->validFormPost['site_status_message_use_end_date'] = FALSE;
$this->validFormPost['site_status_message_start_date[date]'] = $start
->format('Y-m-d');
$this->validFormPost['site_status_message_start_date[time]'] = $start
->format('H:i:s');
$this
->drupalPost($this->siteStatusMessageAdminPage, $this->validFormPost, 'Save configuration');
$this
->drupalGet('<front>');
$this
->assertNoRaw('<div id="site-status-message" class="site-status-message" role="alert">', 'Check the Site Status Message html div does not appear on the page.');
$this
->assertNoText(t('This is a test message.'), 'Check that Site Status Message text does not show on a content page.');
// Wait 3 seconds. Reload the page.
debug('Waiting before reloading.');
sleep(3);
$this
->drupalGet('<front>');
$this
->assertRaw('<div id="site-status-message" class="site-status-message" role="alert">', 'Check the Site Status Message html div now appears on the page.');
$this
->assertText(t('This is a test message.'), 'Check that Site Status Message text is now showing on a content page.');
// Test 5. Set for future time and add expiry time.
$start = new DateTime('now +2 seconds');
$this->validFormPost['site_status_message_use_end_date'] = TRUE;
$this->validFormPost['site_status_message_start_date[date]'] = $start
->format('Y-m-d');
$this->validFormPost['site_status_message_start_date[time]'] = $start
->format('H:i:s');
$end = new DateTime('now +5 seconds');
$this->validFormPost['site_status_message_end_date[date]'] = $end
->format('Y-m-d');
$this->validFormPost['site_status_message_end_date[time]'] = $end
->format('H:i:s');
$this
->drupalPost($this->siteStatusMessageAdminPage, $this->validFormPost, 'Save configuration');
$this
->drupalGet('<front>');
$this
->assertNoRaw('<div id="site-status-message" class="site-status-message" role="alert">', 'Check the Site Status Message html div does not appear on the page.');
$this
->assertNoText(t('This is a test message.'), 'Check that Site Status Message text does not show on a content page.');
// Wait 3 seconds. Reload the page.
debug('Waiting before reloading.');
sleep(3);
$this
->drupalGet('<front>');
$this
->assertRaw('<div id="site-status-message" class="site-status-message" role="alert">', 'Check the Site Status Message html div now appears on the page.');
$this
->assertText(t('This is a test message.'), 'Check that Site Status Message text is now showing on a content page.');
// Wait 3 seconds. Reload the page.
debug('Waiting before reloading.');
sleep(3);
$this
->drupalGet('<front>');
$this
->assertNoRaw('<div id="site-status-message" class="site-status-message" role="alert">', 'Check the Site Status Message html div does not appear on the page.');
$this
->assertNoText(t('This is a test message.'), 'Check that Site Status Message text does not show on a content page.');
}