summaryrefslogtreecommitdiff
path: root/kolab.org/www/drupal-7.15/sites/all/modules/page_title/page_title.test
blob: abc0bae31402ec853111768a096c455aa0be5d94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php

/**
 * @file
 * Test cases for the Page Title module.
 */

class PageTitleTestCase extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Page Title',
      'description' => 'Ensure that Page Title functions correctly',
      'group' => 'Page Title',
      'dependencies' => array('token'),
    );
  }

  public function setUp() {
    parent::setUp('token', 'page_title', 'forum', 'taxonomy');

    // Create an admin user
    $this->admin_user = $this->drupalCreateUser(array(
      'administer page titles',
      'administer taxonomy',
      'access content',
      'create page content',
      'edit any page content',
      'administer forums',
      'create forum content',
      'set page title')
    );
  }


  private function pageTitleCheck($path, $pattern, $tokens = array(), $section = '') {
    // Get the path...
    if (is_array($path)) {
      $this->drupalGet($path['path'], $path['options']);
    }
    else {
      $this->drupalGet($path);
    }

    // Apply tokens to pattern
    $title = strtr($pattern, $tokens);

    // Do some verbose output
    $this->pass(t('Pattern: %pat', array('%pat' => '<title>' . $pattern . '</title>')));
    $this->pass(t('Looking for title: %title', array('%title' => '<title>' . $title . '</title>')));

    // Look for the title in the content
    $res = $this->assertRaw($title, t('Correct page title found in the <head> for: %section', array('%section' => $section)), 'Page Title');

    // If the search failed, do some more verbose debugging
    if (!$res) {
      preg_match('/<title>.*<\/title>/', $this->drupalGetContent(), $found_title);
      $this->pass(t('Found instead: %found', array('%found' => $found_title[0])));
    }
  }


  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), // Set taxonomy for vocab 2 to term 1 See Hack/assumption above
    );

    // 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))), // Set taxonomy for vocab 1 (forum vocab) to term 1 (the General discussion forum)... See Hack/assumptions above
    );

    // 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');
  }
}