View source
<?php
require_once drupal_get_path('module', 'og') . '/tests/og_testcase.php';
class OgVocabTestCase extends OgTestCase {
public static function getInfo() {
return array(
'name' => t('OG vocab access'),
'description' => t('Check access to vocabulary.'),
'group' => t('Organic groups vocabulary'),
);
}
function setUp() {
parent::setUp('og', 'og_vocab');
$admin_user = $this
->drupalCreateUser(array(
'administer nodes',
'administer content types',
'access administration pages',
'administer site configuration',
'administer organic groups',
'administer taxonomy',
));
$this
->drupalLogin($admin_user);
$this->admin_user = $admin_user;
$group_type = $this
->drupalCreateContentType();
variable_set('og_content_type_usage_' . $group_type->name, 'group');
menu_rebuild();
$gid1 = $this
->addOgGroup($group_type->name);
$gid2 = $this
->addOgGroup($group_type->name);
$vid = $tid = array();
foreach (array(
$gid1,
$gid2,
) as $gid) {
$edit = array();
$machine_name = drupal_strtolower($this
->randomName());
$edit['name'] = $this
->randomName();
$edit['description'] = $this
->randomName();
$edit['machine_name'] = $machine_name;
$edit['og'] = $gid;
taxonomy_save_vocabulary($edit);
$vid[] = $edit['vid'];
$form_values = array();
$form_values['vid'] = $edit['vid'];
$form_values['name'] = $this
->randomName();
taxonomy_save_term($form_values);
$tid[] = $form_values['tid'];
}
list($vid1, $vid2) = $vid;
list($tid1, $tid2) = $tid;
$this->og_vocab_pages = array(
'group taxonomy tab' => "node/{$gid1}/og/vocab",
'add group vocabulary' => "node/{$gid1}/og/vocab/add/vocabulary",
'edit group vocabulary' => "node/{$gid1}/og/vocab/edit/vocabulary/{$vid1}",
'edit group vocabulary of another group' => "node/{$gid1}/og/vocab/edit/vocabulary/{$vid2}",
'list terms of group vocabulary' => "node/{$gid1}/og/vocab/terms/{$vid1}",
'list terms of group vocabulary of another group' => "node/{$gid1}/og/vocab/terms/{$vid2}",
'add new group term' => "node/{$gid1}/og/vocab/terms/{$vid1}/add_term",
'add new group term of a vocabulary of another group' => "node/{$gid1}/og/vocab/terms/{$vid2}/add_term",
'edit group term' => "node/{$gid1}/og/vocab/terms/edit/{$tid1}",
'edit group term of a vocabulary of another group' => "node/{$gid1}/og/vocab/terms/edit/{$tid2}",
);
$this->gid1 = $gid1;
}
function testOgVocabAccess() {
$web_user1 = $this
->drupalCreateUser();
$this
->drupalLogin($web_user1);
$this
->OgVocabTestPage(t('User not a member of a group'));
$web_user2 = $this
->drupalCreateUser();
$this
->drupalLogin($web_user2);
og_save_subscription($this->gid1, $web_user2->uid, array(
'is_active' => 1,
));
$this
->OgVocabTestPage(t('User a member of a group without permissions'));
$web_user3 = $this
->drupalCreateUser(array(
'administer own group vocabulary',
'add own group vocabulary',
'edit own group vocabulary',
'edit own group term',
));
$this
->drupalLogin($web_user3);
og_save_subscription($this->gid1, $web_user3->uid, array(
'is_active' => 1,
));
$responses = array(
'group taxonomy tab' => TRUE,
'add group vocabulary' => TRUE,
'edit group vocabulary' => TRUE,
'list terms of group vocabulary' => TRUE,
'add new group term' => TRUE,
'edit group term' => TRUE,
);
$this
->OgVocabTestPage(t('User member of a group with permissions'), $responses);
$web_user4 = $this
->drupalCreateUser();
$this
->drupalLogin($web_user4);
og_save_subscription($this->gid1, $web_user4->uid, array(
'is_active' => 1,
'is_admin' => 1,
));
$this
->OgVocabTestPage(t('User admin of a group'), $responses);
$this
->drupalLogin($this->admin_user);
$this
->OgVocabTestPage(t('User has "administer organic groups" permission'), $responses);
}
function OgVocabTestPage($message, $responses = array()) {
foreach ($this->og_vocab_pages as $name => $url) {
$response = !empty($responses[$name]) ? 200 : 403;
$op = $response == 200 ? t('can') : t('can not');
$this
->drupalGet($url);
$this
->assertResponse($response, $message . ' ' . $op . ' ' . $name . '.');
}
}
}