| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: content_access_test_help.php,v 1.1.4.2 2009/01/02 15:01:01 fago Exp $ 3 4 /** 5 * @file 6 * Helper class with auxiliary functions for content access module tests 7 */ 8 9 class ContentAccessTestCase extends DrupalWebTestCase { 10 11 var $test_user; 12 var $admin_user; 13 var $content_type_name; 14 var $url_content_type_name; 15 var $node1; 16 var $node2; 17 18 /** 19 * Preparation work that is done before each test. 20 * Test users, content types, nodes etc. are created. 21 */ 22 function setUp($module = '') { 23 24 if (empty($module)) { 25 // Enable content access module 26 parent::setUp('content_access'); 27 } 28 else { 29 // Enable content access module plus another module 30 parent::setUp('content_access', $module); 31 // Stop setup when module could not be enabled 32 if (!module_exists($module)) { 33 return; 34 } 35 } 36 37 // Create test user with seperate role 38 $this->test_user = $this->drupalCreateUser(); 39 40 // Create admin user 41 $this->admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'grant content access', 'grant own content access', 'administer nodes', 'access administration pages')); 42 $this->drupalLogin($this->admin_user); 43 44 // Rebuild content access permissions 45 $this->drupalPost('admin/content/node-settings/rebuild', array(), t('Rebuild permissions')); 46 47 // This would be nice to have - but it does not work in the current simpletest version 48 // Create test content type 49 //$content_type = $this->drupalCreateContentType(); 50 //$this->url_content_type_name = $content_type->type; 51 //$this->url_content_type_name = str_replace('_', '-', $content_type->type); 52 53 // Create test content type (the old way) 54 $this->content_type_name = strtolower($this->randomName(5)); 55 $edit = array( 56 'name' => $this->content_type_name, 57 'type' => $this->content_type_name, 58 ); 59 $this->drupalPost('admin/content/types/add', $edit, t('Save content type')); 60 $this->assertRaw(t('The content type %type has been added.', array('%type' => $this->content_type_name)), 'Test content type was added successfully: '. $this->content_type_name); 61 $this->url_content_type_name = str_replace('_', '-', $this->content_type_name); 62 } 63 64 /** 65 * Change access permissions for a content type 66 */ 67 function changeAccessContentType($access_settings) { 68 $this->drupalPost('admin/content/node-type/'. $this->url_content_type_name .'/access', $access_settings, t('Submit')); 69 $this->assertText(t('Your changes have been saved.'), 'access rules of content type were updated successfully'); 70 } 71 72 /** 73 * Change access permissions for a content type by a given keyword (view, update or delete) 74 * for the role of the user 75 */ 76 function changeAccessContentTypeKeyword($keyword, $access = TRUE, $user = NULL) { 77 if ($user === NULL) { 78 $user = $this->test_user; 79 } 80 $roles = $user->roles; 81 end($roles); 82 $access_settings = array( 83 $keyword .'['. key($roles) .']' => $access, 84 ); 85 $this->changeAccessContentType($access_settings); 86 } 87 88 /** 89 * Change the per node access setting for a content type 90 */ 91 function changeAccessPerNode($access = TRUE) { 92 $access_permissions = array( 93 'per_node' => $access, 94 ); 95 $this->changeAccessContentType($access_permissions); 96 } 97 98 /** 99 * Change access permissions for a node by a given keyword (view, update or delete) 100 */ 101 function changeAccessNodeKeyword($node, $keyword, $access = TRUE) { 102 $user = $this->test_user; 103 $roles = $user->roles; 104 end($roles); 105 $access_settings = array( 106 $keyword .'['. key($roles) .']' => $access, 107 ); 108 $this->changeAccessNode($node, $access_settings); 109 } 110 111 /** 112 * Change access permission for a node 113 */ 114 function changeAccessNode($node, $access_settings) { 115 $this->drupalPost('node/'. $node->nid .'/access', $access_settings, t('Submit')); 116 $this->assertText(t('Your changes have been saved.'), 'access rules of node were updated successfully'); 117 } 118 119 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |