/[drupal]/contributions/modules/admin_menu/tests/admin_menu.test
ViewVC logotype

Diff of /contributions/modules/admin_menu/tests/admin_menu.test

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

revision 1.5, Sat Nov 29 17:14:51 2008 UTC revision 1.6, Sun Feb 1 04:25:25 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: admin_menu.test,v 1.4 2008/10/18 17:34:23 sun Exp $  // $Id: admin_menu.test,v 1.5 2008/11/29 17:14:51 davereid Exp $
3    
4  class AdminMenuTestCase extends DrupalWebTestCase {  /**
5     * Test menu links depending on user permissions.
6     */
7    class AdminMenuPermissionsTestCase extends DrupalWebTestCase {
8    
9    function getInfo() {    function getInfo() {
10      return array(      return array(
11        'name' => t('Admin menu functionality'),        'name' => t('Menu link permissions'),
12        'description' => t('Enable a module, make sure an admin user can see the new link.'),        'description' => t('Verify that menu is displayed according to user permissions.'),
13        'group' => t('Admin menu tests'),        'group' => t('Administration menu'),
14      );      );
15    }    }
16    
# Line 18  class AdminMenuTestCase extends DrupalWe Line 21  class AdminMenuTestCase extends DrupalWe
21    /**    /**
22     * Test that the links are added to the page (no JS testing).     * Test that the links are added to the page (no JS testing).
23     */     */
24    function testAdminMenu() {    function testPermissions() {
25      // Anonymous users should not see the menu.      // Anonymous users should not see the menu.
26      $this->assertNoRaw('<div id="admin-menu">', 'Admin menu not displayed to anonymous.');      $this->assertNoRaw('<div id="admin-menu">', t('Admin menu not displayed to anonymous.'));
27    
28      // Create a user who can see the admin_menu links, but without the      // Create a new user who can access administration menu, but without the
29      // permission 'display drupal links'.      // permission 'display drupal links'.
30      $admin_user = $this->drupalCreateUser(array('administer site configuration', 'access administration pages', 'administer nodes', 'bypass node access', 'access administration menu', 'administer site-wide contact form'));      $admin_user = $this->drupalCreateUser(array('administer site configuration', 'access administration pages', 'administer nodes', 'bypass node access', 'access administration menu'));
31      $this->drupalLogin($admin_user);      $this->drupalLogin($admin_user);
32    
33      // Check that the user can see the admin links, but not the drupal links.      // Check that the user can see the admin links, but not the drupal links.
34      $this->assertRaw('<div id="admin-menu">', 'Admin menu displayed to admin user.');      $this->assertRaw('<div id="admin-menu">', t('Administration menu is displayed.'));
35      $this->drupalGet('node');      $this->drupalGet('node');
36      $this->assertTrue(preg_match('@<div id="admin-menu">(.*\n)*.*admin/content/node@',  $this->drupalGetContent()), 'Administer content link found');      $this->assertPattern('@<div id="admin-menu">(.*\n)*.*admin/content/node@', t('Administer content link found.'));
37      $this->assertFalse(preg_match('@<div id="admin-menu">(.*\n)*.*http://drupal.org@',  $this->drupalGetContent()), 'Drupal link not found');      $this->assertNoPattern('@<div id="admin-menu">(.*\n)*.*http://drupal.org@', t('Drupal links not found.'));
38      $this->assertFalse(preg_match('@<div id="admin-menu">(.*\n)*.*admin/build/contact@',  $this->drupalGetContent()), 'Contact module link not found');      $this->assertNoPattern('@<div id="admin-menu">(.*\n)*.*admin/build/contact@', t('Contact module link not found.'));
39    
40      // Check that a link for the newly enabled module appears.      // Create a new user with the permission 'display drupal links'.
     $this->drupalModuleEnable('contact');  
     $this->drupalGet('node');  
     $this->assertTrue(preg_match('@<div id="admin-menu">(.*\n)*.*admin/build/contact@',  $this->drupalGetContent()), 'Contact module link found');  
     $this->drupalLogout();  
   
     // A second user with the added permission 'display drupal links', but not  
     // 'administer site-wide contact form'.  
41      $admin_user2 = $this->drupalCreateUser(array('administer site configuration', 'access administration pages', 'administer nodes', 'access administration menu', 'display drupal links'));      $admin_user2 = $this->drupalCreateUser(array('administer site configuration', 'access administration pages', 'administer nodes', 'access administration menu', 'display drupal links'));
42      $this->drupalLogin($admin_user2);      $this->drupalLogin($admin_user2);
43      $this->drupalGet('node');      $this->drupalGet('node');
44      $this->assertTrue(preg_match('@<div id="admin-menu">(.*\n)*.*http://drupal.org@',  $this->drupalGetContent()), 'Drupal link found');      $this->assertPattern('@<div id="admin-menu">(.*\n)*.*http://drupal.org@', t('Drupal links found.'));
45      $this->assertFalse(preg_match('@<div id="admin-menu">(.*\n)*.*admin/build/contact@',  $this->drupalGetContent()), 'Contact module link not found');      $this->assertNoPattern('@<div id="admin-menu">(.*\n)*.*admin/build/contact@', t('Contact module link not found.'));
46      }
47    }
48    
49    /**
50     * Test menu links depending on installed modules.
51     */
52    class AdminMenuModulesTestCase extends DrupalWebTestCase {
53    
54      function getInfo() {
55        return array(
56          'name' => t('Module menu links'),
57          'description' => t('Verify that menu contains links according to enabled modules.'),
58          'group' => t('Administration menu'),
59        );
60      }
61    
62      function setUp() {
63        parent::setUp('admin_menu', 'contact');
64      }
65    
66      /**
67       * Test that the links are added to the page (no JS testing).
68       */
69      function testContactModuleLinks() {
70        // Create a new user without 'administer site-wide contact form' permission.
71        $admin_user = $this->drupalCreateUser(array('access administration pages', 'access administration menu'));
72        $this->drupalLogin($admin_user);
73    
74        // Verify that proper links are displayed.
75        $this->assertRaw('<div id="admin-menu">', t('Administration menu is displayed.'));
76        $this->drupalGet('node');
77        $this->assertNoPattern('@<div id="admin-menu">(.*\n)*.*admin/build/contact@', t('Contact module link not found.'));
78    
79        // Create a new user with 'administer site-wide contact form' permission.
80        $admin_user = $this->drupalCreateUser(array('access administration pages', 'access administration menu', 'administer site-wide contact form'));
81        $this->drupalLogin($admin_user);
82    
83        // Verify that proper links are displayed.
84        $this->drupalGet('node');
85        $this->assertPattern('@<div id="admin-menu">(.*\n)*.*admin/build/contact@', t('Contact module link found.'));
86    }    }
87  }  }
88    

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

  ViewVC Help
Powered by ViewVC 1.1.2