public function SiteStatusMessageTestCase::testSiteStatusMessageRender in Site Status Message 7
Tests for Site Status Message module whether message renders correctly.
File
- tests/
site_status_message.test, line 137 - Tests for Site Status Message module.
Class
- SiteStatusMessageTestCase
- Class SiteStatusMessageTestCase.
Code
public function testSiteStatusMessageRender() {
// Create an Admin user.
$this
->adminLogin();
// Create a dummy Article node.
$node = $this
->drupalCreateNode(array(
'type' => 'article',
));
// Message variables.
$message = 'This is a test message.';
$no_message = '';
// Path variables.
$valid_link = 'node';
$invalid_link = 'invalid-page';
$edit = array(
'site_status_message_message' => $message,
'site_status_message_showlink' => FALSE,
'site_status_message_link' => $valid_link,
'site_status_message_readmore' => 'Click here',
'site_status_message_display_options' => 'off',
);
// Test 1. Valid message set, show more link off, valid link, valid link
// text, display message off.
$this
->drupalPost($this->siteStatusMessageAdminPage, $edit, 'Save configuration');
$this
->drupalGet('node/' . $node->nid);
$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 is not showing on the page.');
$this
->assertNoLink('Click here', 'Check the Site Status Message link is not on the page.');
// Change to Admin page.
$this
->drupalGet($this->siteStatusMessageAdminPage);
$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 is not showing on the page.');
$this
->assertNoLink('Click here', 'Check the Site Status Message link is not on the page.');
// Test 2. Valid message set, show more link off, valid link, valid link
// text, display message set to public-facing.
$edit['site_status_message_display_options'] = 'public';
$this
->drupalPost($this->siteStatusMessageAdminPage, $edit, 'Save configuration');
$this
->drupalGet('node/' . $node->nid);
$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.');
$this
->assertNoLink('Click here', 'Check the Site Status Message link is not on the content page.');
// Change to Admin page.
$this
->drupalGet($this->siteStatusMessageAdminPage);
$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 is not showing on the page.');
$this
->assertNoLink('Click here', 'Check the Site Status Message link is not on the page.');
// Test 3. Valid message set, show more link on, valid link, valid link
// text, display message set to public-facing.
$edit['site_status_message_showlink'] = TRUE;
$this
->drupalPost($this->siteStatusMessageAdminPage, $edit, 'Save configuration');
$this
->drupalGet('node/' . $node->nid);
$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.');
$this
->assertLink('Click here', 0, 'Check the Site Status Message link is on the content page.');
$this
->clickLink('Click here');
$this
->assertResponse(200, 'Check the Site Status Message link path returns a 200 code.');
$this
->drupalGet($this->siteStatusMessageAdminPage);
$this
->assertNoText(t('This is a test message.'), 'Check that Site Status Message text is not showing on a admin page.');
$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 admin page.');
$this
->assertNoLink('Click here', 'Check the Site Status Message link is not on the admin page.');
// Test 4. Valid message set, show more link on, valid link, valid link
// text, display message set to admin only.
$edit['site_status_message_display_options'] = 'admin';
$this
->drupalPost($this->siteStatusMessageAdminPage, $edit, 'Save configuration');
$this
->drupalGet('node/' . $node->nid);
$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 is not showing on the page.');
$this
->assertNoLink('Click here', 'Check the Site Status Message link is not on the page.');
$this
->drupalGet($this->siteStatusMessageAdminPage);
$this
->assertText(t('This is a test message.'), 'Check that Site Status Message text is showing on a admin page.');
$this
->assertLink('Click here', 0, 'Check the Site Status Message link is on the admin page.');
$this
->clickLink('Click here');
$this
->assertResponse(200, 'Check the Site Status Message link path returns a 200 code.');
// Test 5. Valid message set, show more link on, valid link, valid link
// text, display message set to both admin and public-facing pages.
$edit['site_status_message_display_options'] = 'both';
$this
->drupalPost($this->siteStatusMessageAdminPage, $edit, 'Save configuration');
$this
->drupalGet('node/' . $node->nid);
$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.');
$this
->assertLink('Click here', 0, 'Check the Site Status Message link is on the content page.');
$this
->clickLink('Click here');
$this
->assertResponse(200, 'Check the Site Status Message link path returns a 200 code.');
$this
->drupalGet($this->siteStatusMessageAdminPage);
$this
->assertText(t('This is a test message.'), 'Check that Site Status Message text is showing on a admin page.');
$this
->assertLink('Click here', 0, 'Check the Site Status Message link is on the admin page.');
$this
->clickLink('Click here');
$this
->assertResponse(200, 'Check the Site Status Message link path returns a 200 code.');
// Test 6. Set the message to blank.
$edit['site_status_message_message'] = $no_message;
$this
->drupalPost($this->siteStatusMessageAdminPage, $edit, 'Save configuration');
$this
->drupalGet('node/' . $node->nid);
$this
->assertNoText(t('This is a test message.'), 'Check that Site Status Message text is not showing on a content page.');
$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 content page.');
$this
->assertNoLink('Click here', 'Check the Site Status Message link is not on the content page.');
$this
->drupalGet($this->siteStatusMessageAdminPage);
$this
->assertNoText(t('This is a test message.'), 'Check that Site Status Message text is not showing on a content page.');
$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 content page.');
$this
->assertNoLink('Click here', 'Check the Site Status Message link is not on the content page.');
// Test 7. Reset message and set link to an invalid page.
$edit['site_status_message_message'] = $message;
$edit['site_status_message_link'] = $invalid_link;
$this
->drupalPost($this->siteStatusMessageAdminPage, $edit, 'Save configuration');
$this
->assertText(t('You must enter a valid internal path.'), 'Check that Site Status Message link error is showing the admin page.');
}