View source
<?php
class NodehierarchyTestCase extends DrupalWebTestCase {
var $content_types = array();
var $nodes = array();
function setUp() {
parent::setUp('nodehierarchy');
}
function loginWithPermissions($permissions = NULL) {
if (!isset($permissions)) {
$permissions = array(
'access content',
'administer content types',
'administer nodes',
'administer hierarchy',
'create child nodes',
'edit all node parents',
'edit own node parents',
'reorder children',
'view site outline',
);
}
$user = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($user);
}
function createParentType() {
$parent_type_name = 'simpletest' . mt_rand();
$type = $this
->drupalCreateContentType(array(
'type' => $parent_type_name,
'name' => $parent_type_name,
'nh_parent' => 1,
));
return $type;
}
function createChildType() {
$child_type_name = 'simpletest' . mt_rand();
$type = $this
->drupalCreateContentType(array(
'type' => $child_type_name,
'name' => $child_type_name,
'nh_child' => 1,
));
return $type;
}
function createParentNode($edit = array()) {
if (isset($edit['type'])) {
$ctype = $this
->createParentType();
$edit['type'] = $ctype->type;
}
$node = $this
->drupalCreateNode($edit);
return $node;
}
}
class NodeHierarchyCreateParentChildTests extends NodehierarchyTestCase {
function getInfo() {
return array(
'name' => t('Nodehierarchy Test Functionality'),
'description' => t('Test nodehierarchy.'),
'group' => t('Nodehierarchy'),
);
}
function setUp() {
parent::setUp();
$this
->loginWithPermissions();
}
function testCreateChildNode() {
$parent_node = $this
->createParentNode();
$child_type = $this
->createChildType();
$edit['type'] = $child_type->type;
$edit['parent'] = $parent_node->nid;
$child_node = $this
->drupalCreateNode($edit);
$child_node_load = node_load($child_node->nid);
$this
->assertEqual($parent_node->nid, $child_node_load->parent, 'Child node has parent id: ' . $child_node_load->parent);
}
}
class NodeHierarchyPermissionsTests extends NodehierarchyTestCase {
function getInfo() {
return array(
'name' => t('Nodehierarchy Permissions'),
'description' => t('Test nodehierarchy permissions.'),
'group' => t('Nodehierarchy'),
);
}
function setUp() {
parent::setUp();
}
function testSiteOutlineInvalidPermissions() {
$perm = array(
'access content',
'administer nodes',
'administer hierarchy',
'create child nodes',
'edit all node parents',
'edit own node parents',
'reorder children',
);
$this
->loginWithPermissions($perm);
$this
->drupalGet('admin/content/nodehierarchy');
$this
->assertResponse('403', 'Site Outline returned 403 Forbidden');
}
function testSiteOutlineValidPermissions() {
$perm = array(
'view site outline',
);
$this
->loginWithPermissions($perm);
$this
->drupalGet('admin/content/nodehierarchy');
$this
->assertResponse('200', 'Site Outline returned 200');
}
}