You are here

public function PageTitleTestCase::testPageTitleTest in Page Title 7.2

Same name and namespace in other branches
  1. 8.2 page_title.test \PageTitleTestCase::testPageTitleTest()
  2. 6.2 tests/page_title.test \PageTitleTestCase::testPageTitleTest()

File

./page_title.test, line 62
Test cases for the Page Title module.

Class

PageTitleTestCase
@file Test cases for the Page Title module.

Code

public function testPageTitleTest() {
  $this
    ->drupalLogin($this->admin_user);

  // Create a term
  $term = array(
    'name' => 'Test Term Foo',
  );
  $this
    ->drupalPost('admin/structure/taxonomy/tags/add', $term, t('Save'));

  // Define our settings
  $settings = array(
    'page_title_default' => '[current-page:page-title] - DEFAULT TEST',
    'page_title_front' => '[site:name]',
    'page_title_user' => 'Profile For [user]',
    'page_title_type_page' => 'PAGE NODE: [current-page:page-title]',
    'page_title_type_page_showfield' => 1,
    'page_title_type_forum' => 'Forum - [current-page:page-title]',
    'page_title_pager_pattern' => ' - page [current-page:page-number]',
    'page_title_vocab_forums' => 'FORUM: [term:name]',
    'page_title_vocab_tags' => 'TERM: [current-page:page-title]',
    'page_title_vocab_forums_showfield' => 1,
    'page_title_vocab_tags_showfield' => 1,
    'page_title_forum_root_title' => 'Welcome to [site:name] [current-page:page-title]',
  );

  // Save the settings
  $this
    ->drupalPost('admin/config/search/page-title', $settings, t('Save configuration'));
  $this
    ->assertText(t('The configuration options have been saved.'), t('The configuration saved message was found'), 'Page Title');

  /**
   * Lets check the frontpage page title is working
   */
  $this
    ->pageTitleCheck('<front>', $settings['page_title_front'], array(
    '[site:name]' => 'Drupal',
  ), 'Frontpage Title');

  /**
   * Lets check a "default" page, such a the page title admin form
   */
  $this
    ->pageTitleCheck('admin/config/search/page-title', $settings['page_title_default'], array(
    '[current-page:page-title]' => 'Page titles',
  ), 'Admin Page');

  /**
   * Let's create a page node and check that
   */

  //Create a basic page node
  $node = array(
    'type' => 'page',
    'title' => 'Test Page Node',
    'taxonomy' => array(
      2 => 1,
    ),
  );

  // Save the node
  $node = $this
    ->drupalCreateNode($node);

  // Pass out a message to confirm the save
  $this
    ->pass(t('Created Node !nid', array(
    '!nid' => $node->nid,
  )), 'Page Title');

  // Load the node page and check for the title in the head
  $this
    ->pageTitleCheck('node/' . $node->nid, $settings['page_title_type_page'], array(
    '[current-page:page-title]' => $node->title,
  ), 'Page Node Type');

  // Post a page_title into the node and reload the node
  $edit['page_title'] = 'I am a test Page Title field';
  $this
    ->drupalPost('node/' . $node->nid . '/edit', $edit, 'Save');
  $node = node_load($node->nid, NULL, TRUE);

  // Node load the node page and check for the title in the head
  $this
    ->pageTitleCheck('node/' . $node->nid, $settings['page_title_type_page'], array(
    '[current-page:page-title]' => $node->page_title,
  ), 'Page Node Type');

  /**
   *  TAXONOMY
   */

  // Lets check a taxonomy/term/tid page (should be term from earlier!)
  // Load the term page and check for the title in the head
  $this
    ->pageTitleCheck('taxonomy/term/2', $settings['page_title_vocab_tags'], array(
    '[current-page:page-title]' => $term['name'],
  ), 'Taxonomy Title');

  // Lets check the pagenation suffix is working but appending it to taxonomy/term/1.
  // This is a little messy - but it works for our purpose
  // Remember, the page value in the URL is zero indexed. This means page=1 in URL is Page 2 on the site
  $this
    ->pageTitleCheck(array(
    'path' => 'taxonomy/term/2',
    'options' => array(
      'query' => array(
        'page' => 1,
      ),
    ),
  ), $settings['page_title_vocab_tags'] . $settings['page_title_pager_pattern'], array(
    '[current-page:page-title]' => $term['name'],
    '[current-page:page-number]' => 2,
  ), 'Taxonomy Title with pagenation suffix');

  /**
   *  FORUMS
   */

  // Updating term 1 - The General Discussion forum

  #$forum_forum = array('page_title' => 'I AM A TEST FORUM');

  #$this->drupalPost('admin/structure/forum/edit/forum/1', $forum_forum, t('Save'));

  //Create a basic forum topic node
  $forum_node = array(
    'nid' => NULL,
    'type' => 'forum',
    'title' => 'Test Forum Node',
    'taxonomy_forums' => array(
      'und' => array(
        0 => array(
          'tid' => 1,
        ),
      ),
    ),
  );

  // Save the node
  $forum_node = $this
    ->drupalCreateNode($forum_node);

  // Node load the node page and check for the title in the head
  $this
    ->pageTitleCheck('node/' . $forum_node->nid, $settings['page_title_type_forum'], array(
    '[current-page:page-title]' => $forum_node->title,
  ), 'Forum Topic');

  //Now test the forum root...
  $this
    ->pageTitleCheck('forum', $settings['page_title_forum_root_title'], array(
    '[current-page:page-title]' => 'Forums',
    '[site:name]' => 'Drupal',
  ), 'Forum Topic');

  //Now test the forum forum...
  $this
    ->pageTitleCheck('forum/1', $settings['page_title_vocab_forums'], array(
    '[term:name]' => 'General discussion',
  ), 'Forum Container');
}