og_context.test in Organic groups 7.2
Test organic groups context module.
File
og_context/og_context.testView source
<?php
/**
* @file
* Test organic groups context module.
*/
/**
* Test OG access.
*/
class OgContextTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'OG context',
'description' => 'Check if context is returning only if user has right permissions.',
'group' => 'Organic groups context',
);
}
function setUp() {
parent::setUp('og_context', 'og_access');
node_access_rebuild();
$this->user1 = $this
->drupalCreateUser();
$this->user2 = $this
->drupalCreateUser();
// Create group and group content node types.
$this->group_type = $this
->drupalCreateContentType()->type;
og_create_field(OG_GROUP_FIELD, 'node', $this->group_type);
og_create_field(OG_ACCESS_FIELD, 'node', $this->group_type);
$this->group_content_type = $this
->drupalCreateContentType()->type;
og_create_field(OG_AUDIENCE_FIELD, 'node', $this->group_content_type);
// Create a group node and enable access.
$settings = array();
$settings['type'] = $this->group_type;
$settings[OG_GROUP_FIELD][LANGUAGE_NONE][0]['value'] = 1;
$settings[OG_ACCESS_FIELD][LANGUAGE_NONE][0]['value'] = 1;
$settings['uid'] = $this->user1->uid;
$this->group_node = $this
->drupalCreateNode($settings);
}
/**
* Testing of the og_context returning value. Should return group id if user
* has permissions and NULL if he doesn't.
*/
function testGettingGroupContext() {
$this
->drupalLogin($this->user1);
// User can get the group context.
$this
->assertTrue(og_context('node', $this->group_node));
// Unpublishing the group node.
$this->group_node->status = FALSE;
node_save($this->group_node);
$this->group_node = node_load($this->group_node->nid);
// Other user should not get the group context
$this
->assertFalse(og_context('node', $this->group_node, $this->user2));
// Anybody should get existing context if checking access is FALSE.
$this
->assertTrue(og_context('node', $this->group_node, $this->user2, FALSE));
}
}
Classes
Name | Description |
---|---|
OgContextTestCase | Test OG access. |