Projet

Général

Profil

Paste
Télécharger (5,81 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / content_access / tests / content_access_acl.suspended @ ae34fb26

1
<?php
2

    
3
/**
4
 * @file
5
 * Automatd SimpleTest Case for using content access module with acl module
6
 */
7

    
8
require_once(drupal_get_path('module', 'content_access') .'/tests/content_access_test_help.php');
9

    
10
class ContentAccessACLTestCase extends ContentAccessTestCase {
11

    
12
  var $node;
13

    
14
  /**
15
   * Implementation of get_info() for information
16
   */
17
  public static function getInfo() {
18
    return array(
19
      'name' => t('Content Access Module with ACL Module Tests'),
20
      'description' => t('Various tests to check the combination of content access and ACL module.'),
21
      'group' => 'Content Access',
22
    );
23
  }
24

    
25
  /**
26
   * Setup configuration before each test
27
   */
28
  function setUp($module = '') {
29
    parent::setUp('acl');
30

    
31
    if (!module_exists('acl')) {
32
      $this->pass('No ACL module present, skipping test');
33
      return;
34
    }
35

    
36
    // Create test nodes
37
    $this->node = $this->drupalCreateNode(array('type' => $this->content_type->type));
38
  }
39

    
40
  /**
41
   * Test Viewing accessibility with permissions for single users
42
   */
43
  function testViewAccess() {
44
    // Exit test if ACL module could not be enabled
45
    if (!module_exists('acl')) {
46
      $this->pass('No ACL module present, skipping test');
47
      return;
48
    }
49

    
50
    // Restrict access to this content type (access is only allowed for the author)
51
    // Enable per node access control
52
    $access_permissions = array(
53
      'view[1]' => FALSE,
54
      'view[2]' => FALSE,
55
      'per_node' => TRUE,
56
    );
57
    $this->changeAccessContentType($access_permissions);
58

    
59
    // Allow access for test user
60
    $edit = array(
61
      'acl[view][add]' => $this->test_user->name,
62
    );
63
    $this->drupalPost('node/'. $this->node->nid .'/access', $edit, t('Add User'));
64
    $this->drupalPost(NULL, array(), t('Submit'));
65

    
66
    // Logout admin, try to access the node anonymously
67
    $this->drupalLogout();
68
    $this->drupalGet('node/'. $this->node->nid);
69
    $this->assertText(t('Access denied'), 'node is not viewable');
70

    
71
    // Login test user, view access should be allowed now
72
    $this->drupalLogin($this->test_user);
73
    $this->drupalGet('node/'. $this->node->nid);
74
    $this->assertNoText(t('Access denied'), 'node is viewable');
75

    
76
    // Login admin and disable per node access
77
    $this->drupalLogin($this->admin_user);
78
    $this->changeAccessPerNode(FALSE);
79

    
80
    // Logout admin, try to access the node anonymously
81
    $this->drupalLogout();
82
    $this->drupalGet('node/'. $this->node->nid);
83
    $this->assertText(t('Access denied'), 'node is not viewable');
84

    
85
    // Login test user, view access should be denied now
86
    $this->drupalLogin($this->test_user);
87
    $this->drupalGet('node/'. $this->node->nid);
88
    $this->assertText(t('Access denied'), 'node is not viewable');
89
  }
90

    
91
  /**
92
   * Test Editing accessibility with permissions for single users
93
   */
94
  function testEditAccess() {
95
    // Exit test if ACL module could not be enabled
96
    if (!module_exists('acl')) {
97
      $this->pass('No ACL module present, skipping test');
98
      return;
99
    }
100

    
101
    // Enable per node access control
102
    $this->changeAccessPerNode();
103

    
104
    // Allow edit access for test user
105
    $edit = array(
106
      'acl[update][add]' => $this->test_user->name,
107
    );
108
    $this->drupalPost('node/'. $this->node->nid .'/access', $edit, t('Add User'));
109
    $this->drupalPost(NULL, array(), t('Submit'));
110

    
111
    // Logout admin, try to edit the node anonymously
112
    $this->drupalLogout();
113
    $this->drupalGet('node/'. $this->node->nid .'/edit');
114
    $this->assertText(t('Access denied'), 'node is not editable');
115

    
116
    // Login test user, edit access should be allowed now
117
    $this->drupalLogin($this->test_user);
118
    $this->drupalGet('node/'. $this->node->nid .'/edit');
119
    $this->assertNoText(t('Access denied'), 'node is editable');
120

    
121
    // Login admin and disable per node access
122
    $this->drupalLogin($this->admin_user);
123
    $this->changeAccessPerNode(FALSE);
124

    
125
    // Logout admin, try to edit the node anonymously
126
    $this->drupalLogout();
127
    $this->drupalGet('node/'. $this->node->nid .'/edit');
128
    $this->assertText(t('Access denied'), 'node is not editable');
129

    
130
    // Login test user, edit access should be denied now
131
    $this->drupalLogin($this->test_user);
132
    $this->drupalGet('node/'. $this->node->nid .'/edit');
133
    $this->assertText(t('Access denied'), 'node is not editable');
134
  }
135

    
136
  /**
137
   * Test Deleting accessibility with permissions for single users
138
   */
139
  function testDeleteAccess() {
140
    // Exit test if ACL module could not be enabled
141
    if (!module_exists('acl')) {
142
      $this->pass('No ACL module present, skipping test');
143
      return;
144
    }
145

    
146
    // Enable per node access control
147
    $this->changeAccessPerNode();
148

    
149
    // Allow delete access for test user
150
    $edit = array(
151
      'acl[delete][add]' => $this->test_user->name,
152
    );
153
    $this->drupalPost('node/'. $this->node->nid .'/access', $edit, t('Add User'));
154
    $this->drupalPost(NULL, array(), t('Submit'));
155

    
156
    // Logout admin, try to delete the node anonymously
157
    $this->drupalLogout();
158
    $this->drupalGet('node/'. $this->node->nid .'/delete');
159
    $this->assertText(t('Access denied'), 'node is not deletable');
160

    
161
    // Login test user, delete access should be allowed now
162
    $this->drupalLogin($this->test_user);
163
    $this->drupalGet('node/'. $this->node->nid .'/delete');
164
    $this->assertNoText(t('Access denied'), 'node is deletable');
165

    
166
    // Login admin and disable per node access
167
    $this->drupalLogin($this->admin_user);
168
    $this->changeAccessPerNode(FALSE);
169

    
170
    // Logout admin, try to delete the node anonymously
171
    $this->drupalLogout();
172
    $this->drupalGet('node/'. $this->node->nid .'/delete');
173
    $this->assertText(t('Access denied'), 'node is not deletable');
174

    
175
    // Login test user, delete access should be denied now
176
    $this->drupalLogin($this->test_user);
177
    $this->drupalGet('node/'. $this->node->nid .'/delete');
178
    $this->assertText(t('Access denied'), 'node is not deletable');
179
  }
180
}