1 system.test FrontPageTestCase::testBackdropIsFrontPage()

Test home page functionality.

File

core/modules/system/tests/system.test, line 1577
Tests for system.module.

Class

FrontPageTestCase
Test home page functionality and administration.

Code

function testBackdropIsFrontPage() {
  $this->backdropGet('');
  $this->assertText(t('On home page.'), 'Path is the home page.');
  config_set('system.core', 'site_frontpage', 'node');
  $this->backdropGet('node');
  $this->assertText(t('On home page.'), 'Path is the home page.');
  $this->backdropGet($this->node_path);
  $this->assertNoText(t('On home page.'), 'Path is not the home page.');

  // Test that the default_nodes_main setting is saved and works from
  // Site information form: /admin/config/system/site-information
  $node1 = $this->backdropCreateNode(array('title' => $this->randomName(20), 'promote' => 1));
  $node2 = $this->backdropCreateNode(array('title' => $this->randomName(20), 'promote' => 1));
  $node3 = $this->backdropCreateNode(array('title' => $this->randomName(20), 'promote' => 1));
  $this->backdropGet('');
  // Check that all three promoted nodes are on the frontpage.
  $this->assertText($node1->title, 'node1 title found on home page.');
  $this->assertText($node2->title, 'node2 title found on home page.');
  $this->assertText($node3->title, 'node3 title found on home page.');
  // Change the number of nodes allowed on frontpage.
  config_set('system.core', 'default_nodes_main', 2);
  backdrop_flush_all_caches();
  // Make sure that the 3rd node is no longer on frontpage.
  $this->backdropGet('');
  $this->assertNoText($node1->title, 'node3 title not on frontpage after setting frontpage listing to 2 nodes.');

  // Change the home page to an invalid path.
  $edit = array('site_frontpage' => 'kittens');
  $this->backdropPost('admin/config/system/site-information', $edit, t('Save configuration'));
  $this->assertText(t("The path '@path' is either invalid or you do not have access to it.", array('@path' => $edit['site_frontpage'])));

  // Change the home page to a valid path.
  $edit['site_frontpage'] = $this->node_path;
  $this->backdropPost('admin/config/system/site-information', $edit, t('Save configuration'));
  $this->assertText(t('The configuration options have been saved.'), 'The home page path has been saved.');

  $this->backdropGet('');
  $this->assertText(t('On home page.'), 'Path is the home page.');
  // Check that the path /node is redirected to the custom frontpage.
  $this->backdropGet('node');
  $node_alias = current_path();
  $this->backdropGet($this->node_path);
  $this_alias = current_path();
  $this->assertEqual($node_alias, $this_alias, 'Path /node is redirected to custom frontpage.');
  $this->backdropGet($this->node_path);
  $this->assertText(t('On home page.'), 'Path is the home page.');
}