/[drupal]/contributions/modules/nodewords/nodewords.test
ViewVC logotype

Diff of /contributions/modules/nodewords/nodewords.test

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.1 by kiam, Thu Nov 26 13:14:45 2009 UTC revision 1.1.2.2 by ilo, Thu Nov 26 21:36:24 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id$  // $Id: nodewords.test,v 1.1.2.1 2009/11/26 13:14:45 kiam Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 9  Line 9 
9  /**  /**
10   * Nodewords Test Case implementation.   * Nodewords Test Case implementation.
11   */   */
12  class NodewordsTestCase extends DrupalWebTestCase {  class NodewordsFunctionalityTestCase extends DrupalWebTestCase {
13    
14    public static function getInfo() {    public static function getInfo() {
15      return array(      return array(
16        'name'        => 'Nodewords test',        'name'        => 'Nodewords functionality test',
17        'description' => 'Test nodewords functionality.',        'description' => 'Test basic nodewords functionality.',
18        'group'       => 'nodewords'        'group'       => 'nodewords'
19      );      );
20    }    }
# Line 24  class NodewordsTestCase extends DrupalWe Line 24  class NodewordsTestCase extends DrupalWe
24      parent::setUp('nodewords', 'nodewords_basic');      parent::setUp('nodewords', 'nodewords_basic');
25    }    }
26    
   
27    /**    /**
28       * Verify edit meta tag permissions. Configure the nodewords module to expose
29       * several meta tags, and allow a user to edit only a few of them. Verify that
30       * only allowed meta tags are available for the user and that value is saved
31       * and showed on node view.
32       *
33     * Verify that user without "administer nodes" permission is able to edit node     * Verify that user without "administer nodes" permission is able to edit node
34     * meta tags (issue: http://drupal.org/node/588946).     * meta tags (issue: http://drupal.org/node/588946).
35     */     */
36    function testNodePermissionFunctionality() {    function testMetaTagsPermissionFunctionality() {
37    
38      // Create an administrator user.      // Create an administrator user. This use will configure the nodewords
39        // settings according to the test.
40      $permissions = array(      $permissions = array(
       'administer content types',  
41        'administer meta tags',        'administer meta tags',
42      );      );
43      $user = $this->drupalCreateUser($permissions);      $user = $this->drupalCreateUser($permissions);
# Line 41  class NodewordsTestCase extends DrupalWe Line 45  class NodewordsTestCase extends DrupalWe
45      // Log in to Drupal using the administrator user.      // Log in to Drupal using the administrator user.
46      $this->drupalLogin($user);      $this->drupalLogin($user);
47    
48      // Enable the tags KEYWORDS, DESCRIPTION and COPYRIGHT for editing.      // Enable some meta tags
49      $options = array(      $options = array(
50          // Allow editing KEYWORDS, DESCRIPTION and COPYRIGHT
51        'nodewords_edit[keywords]' => 1,        'nodewords_edit[keywords]' => 1,
52        'nodewords_edit[description]' => 1,        'nodewords_edit[description]' => 1,
53        'nodewords_edit[copyright]' => 1,        'nodewords_edit[copyright]' => 1,
54          // Only show DESCRIPTION and COPYRIGHT meta tags
55          'nodewords_head[copyright]' => 1,
56          'nodewords_head[description]' => 1,
57      );      );
58      $this->drupalPost('admin/content/nodewords', $options, t('Save configuration'));      $this->drupalPost('admin/content/nodewords', $options, t('Save configuration'));
59        $this->assertRaw(t('The configuration options have been saved.'), t('Meta tags configuration saved.'));
     // Check that page content type has been updated.  
     $this->assertRaw(t('The configuration options have been saved.'));  
60    
61      // Create an user with permission to create a page node, and to edit the      // Create an user with permission to create a page node, and to edit the
62      // meta tags COPYRIGHT, and DESCRIPTION.      // meta tags COPYRIGHT, and DESCRIPTION.
63      $permissions = array(      $permissions = array(
64        'create page content',        'create page content',
65          'edit own page content',
66          'delete own page content',
67        'edit meta tag COPYRIGHT',        'edit meta tag COPYRIGHT',
68        'edit meta tag DESCRIPTION',        'edit meta tag DESCRIPTION',
69      );      );
   
70      $user = $this->drupalCreateUser($permissions);      $user = $this->drupalCreateUser($permissions);
71    
72      // Log in to Drupal using the previously created user.      // Log in to Drupal using the previously created user.
73      $this->drupalLogin($user);      $this->drupalLogin($user);
74    
75      // Try to create a page node.      // Verify that only COPYRIGHT and DESCRIPTION meta tags are available for
76        // this user due to edit meta tag permissions, even if other meta tags are
77        // available for editing.
78      $this->drupalGet('node/add/page');      $this->drupalGet('node/add/page');
79      $this->assertField('nodewords[copyright][value]', t('Copyright meta tag field found.'));      $this->assertField('nodewords[copyright][value]', t('Copyright meta tag field found.'));
80      $this->assertField('nodewords[description][value]', t('Description meta tag field found.'));      $this->assertField('nodewords[description][value]', t('Description meta tag field found.'));
81      $this->assertNoField('nodewords[keywords][value]', t('Keywords meta tag field not found.'));      $this->assertNoField('nodewords[keywords][value]', t('Keywords meta tag field not found.'));
82    
83        // Create a page node with random meta tag values
84        $options = array(
85          'title' => $this->randomName(),
86          'nodewords[copyright][value]' => $this->randomName(),
87          'nodewords[description][value]' => $this->randomName(),
88        );
89        $this->drupalPost('node/add/page', $options, t('Save'));
90        $this->assertRaw(t('Page %title has been created.', array('%title' => $options['title'])), t('Page successfully saved.'));
91    
92        // Check for meta information in the node/% page.
93        $this->assertRaw('<meta name="copyright" content="' . $options['nodewords[copyright][value]'] . '" />', t('Copyright meta tag successfully verified.'));
94        $this->assertRaw('<meta name="description" content="' . $options['nodewords[description][value]'] . '" />', t('Description meta tag successfully verified.'));
95    
96        // Update page: change copyright meta tag
97        $options = array(
98          'title' => $this->randomName(),
99          'nodewords[copyright][value]' => '',
100          'nodewords[description][value]' => $this->randomName(),
101        );
102        $this->drupalPost($this->getUrl() . '/edit', $options, t('Save'));
103        $this->assertRaw(t('Page %title has been updated.', array('%title' => $options['title'])), t('Page successfully saved.'));
104    
105        // Check for meta information again (update operation).
106        $this->assertRaw('<meta name="description" content="' . $options['nodewords[description][value]'] . '" />', t('Description meta tag successfully verified.'));
107        // Copyright Meta tag is not set, and should not exist.
108        $this->assertNoRaw('<meta name="copyright" ', t('Copyright meta tag successfully verified.'));
109      }
110    
111    }
112    
113    
114    /**
115     * Nodewords Search integration Test Case implementation.
116     */
117    class NodewordsSearchTestCase extends DrupalWebTestCase {
118    
119      public static function getInfo() {
120        return array(
121          'name'        => 'Nodewords Search integration',
122          'description' => 'Test nodewords searching feature functionality.',
123          'group'       => 'nodewords'
124        );
125    }    }
126    
127      function setUp() {
128        // Enable minimum required modules.
129        parent::setUp('nodewords', 'nodewords_basic', 'search');
130      }
131    
132      /**
133       * Verify that search works for KEYWORDS and DESCRIPTION meta tags
134       *
135       * Create two nodes with KEYWORDS and DESCRIPTION meta tags and does search
136       * for both tags and both modules.
137       *
138       * Also tests the issue: http://drupal.org/node/628868
139       */
140      function testSearchMetaTagsFunctionality() {
141    
142        // Create an administrator user.
143        $permissions = array(
144          'administer content types',
145          'administer meta tags',
146          'administer search',
147          'administer site configuration'
148        );
149        $admin_user = $this->drupalCreateUser($permissions);
150    
151        // Log in to Drupal using the administrator user.
152        $this->drupalLogin($admin_user);
153    
154        // Enable the tags KEYWORDS, DESCRIPTION and COPYRIGHT for editing and
155        // to rendered in the output.
156        $options = array(
157          'nodewords_edit[keywords]' => 1,
158          'nodewords_edit[description]' => 1,
159          'nodewords_edit[copyright]' => 1,
160          'nodewords_head[keywords]' => 1,
161          'nodewords_head[description]' => 1,
162          'nodewords_head[copyright]' => 1,
163        );
164        $this->drupalPost('admin/content/nodewords', $options, t('Save configuration'));
165    
166        // Check that page content type has been updated.
167        $this->assertRaw(t('The configuration options have been saved.'));
168    
169        // Create an user with permission to create a page node, and to edit the
170        // meta tags COPYRIGHT, and DESCRIPTION.
171        $permissions = array(
172          'create page content',
173          'edit meta tag KEYWORDS',
174          'edit meta tag DESCRIPTION',
175          'search content',
176        );
177        $user = $this->drupalCreateUser($permissions);
178    
179        // Log in to Drupal using the previously created user.
180        $this->drupalLogin($user);
181    
182        // Create two page nodes with meta tags.
183        $options1 = array(
184          'title' => $this->randomName(),
185          'nodewords[keywords][value]' => $this->randomName(),
186          'nodewords[description][value]' => $this->randomName(),
187        );
188        $this->drupalPost('node/add/page', $options1, t('Save'));
189        // Check for meta information in the node/% page.
190        $this->assertRaw('<meta name="keywords" content="' . $options1['nodewords[keywords][value]'] . '" />', t('Keywords meta tag successfully verified.'));
191        $this->assertRaw('<meta name="description" content="' . $options1['nodewords[description][value]'] . '" />', t('Description meta tag successfully verified.'));
192    
193        // Create two page nodes with meta tags.
194        $options2 = array(
195          'title' => $this->randomName(),
196          'nodewords[keywords][value]' => $this->randomName(),
197          'nodewords[description][value]' => $this->randomName(),
198        );
199        $this->drupalPost('node/add/page', $options2, t('Save'));
200        // Check for meta information in the node/% page.
201        $this->assertRaw('<meta name="keywords" content="' . $options2['nodewords[keywords][value]'] . '" />', t('Keywords meta tag successfully verified.'));
202        $this->assertRaw('<meta name="description" content="' . $options2['nodewords[description][value]'] . '" />', t('Description meta tag successfully verified.'));
203    
204        // Login again as admin user..
205        $this->drupalLogin($admin_user);
206    
207        // Launch cron, should re-index the site content.
208        $this->drupalGet('admin/reports/status/run-cron');
209        $this->assertRaw(t('Cron ran successfully.'));
210    
211        // Verify all content has been indexed.
212        $this->drupalGet('admin/settings/search');
213        $this->assertText(t('100% of the site has been indexed'));
214    
215        // Log in again as a regular user, has permissions to search content.
216        $this->drupalLogin($user);
217    
218        // Search for nodewords of node 1: use description meta tag
219        $this->drupalGet('search/node/' . $options1['nodewords[description][value]']);
220        $this->assertText($options1['title'], t('Search node using description verified successfully.'));
221    
222        // Search for nodewords of node 1: use keywords meta tag
223        $this->drupalGet('search/node/' . $options1['nodewords[keywords][value]']);
224        $this->assertText($options1['title'], t('Search node using keywords verified successfully.'));
225    
226        // Search for nodewords of node 2: use description meta tag
227        $this->drupalGet('search/node/' . $options2['nodewords[description][value]']);
228        $this->assertText($options2['title'], t('Search node using description verified successfully.'));
229    
230        // Search for nodewords of node 2: use keywords meta tag
231        $this->drupalGet('search/node/' . $options2['nodewords[keywords][value]']);
232        $this->assertText($options2['title'], t('Search node using keywords verified successfully.'));
233      }
234    
235  }  }

Legend:
Removed from v.1.1.2.1  
changed lines
  Added in v.1.1.2.2

  ViewVC Help
Powered by ViewVC 1.1.3