1 system.test FrontPageTestCase::testBackdropIsFrontPage()

Test front page functionality.

File

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

Class

FrontPageTestCase
Test front page functionality and administration.

Code

function testBackdropIsFrontPage() {
  $this->backdropGet('');
  $this->assertText(t('On front page.'), 'Path is the front page.');
  config_set('system.core', 'site_frontpage', 'node');
  $this->backdropGet('node');
  $this->assertText(t('On front page.'), 'Path is the front page.');
  $this->backdropGet($this->node_path);
  $this->assertNoText(t('On front page.'), 'Path is not the front 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 front page.');
  $this->assertText($node2->title, 'node2 title found on front page.');
  $this->assertText($node3->title, 'node3 title found on front 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 forntpage listing to 2 nodes.');

  // Change the front 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 front 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 front page path has been saved.');

  $this->backdropGet('');
  $this->assertText(t('On front page.'), 'Path is the front 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 front page.'), 'Path is the front page.');
}