nd.regions.test in Node displays 6
Same filename and directory in other branches
Tests for Node displays (regions)
File
tests/nd.regions.testView source
<?php
/**
* @file
* Tests for Node displays (regions)
*/
class NodeDisplaysRegions extends DrupalWebTestCase {
/**
* Implementation of getInfo().
*/
function getInfo() {
return array(
'name' => t('Regions'),
'description' => t('Tests for regions.'),
'group' => t('Node Displays'),
);
}
/**
* Implementation of setUp().
*/
function setUp() {
parent::setUp('nd');
}
/**
* Debug helper function. Writes values away to a text file in the files directory.
*/
function _debugHelper($value, $writetype = 'a+') {
$debug = fopen($this->originalFileDirectory . '/simpletestdebug.txt', 'a+');
fwrite($debug, print_r($value, TRUE) . "\n");
fclose($debug);
}
/**
* Helper function to determine if a field is in a region. Returns true if not found.
* @param string $search The field to search for in the regions.
* @param array $regions A list of regions.
*/
function _nd_field_not_found($search, $regions) {
foreach ($regions as $region) {
foreach ($region as $field => $weight) {
if ($field == $search) {
return FALSE;
}
}
}
return TRUE;
}
/**
* Helper function to build an object.
* @param stdClass $object A node.
* @param $build_mode The build mode for the node.
*/
function _nd_build_object($object, $build_mode = NODE_BUILD_NORMAL, $teaser = FALSE, $page = TRUE) {
$object_loaded = node_load($object->nid, array(), TRUE);
$object_loaded->build_mode = $build_mode;
$object_rendered = node_build_content($object_loaded, $teaser, $page);
node_invoke_nodeapi($object_rendered, 'alter', $teaser, $page);
return $object_rendered;
}
/**
* Test that region handling works when no cck fields are defined.
*/
function testRegionsWithNoCCKFields() {
$admin_user = $this
->drupalCreateUser(array(
'administer content types',
'administer nodes',
));
$this
->drupalLogin($admin_user);
$this
->drupalGet('admin/content/node-type/page/display');
$this
->assertRaw('edit-body-full-region-wrapper', t('Region handling works with no CCK fields.'), t('Region handling'));
}
/**
* Test if nodeapi & preprocess do their job good by
* excluding fields and putting them in the right region.
*/
function testRendering() {
$admin_user = $this
->drupalCreateUser(array(
'administer content types',
'administer nodes',
));
$this
->drupalLogin($admin_user);
$page_node = $this
->drupalCreateNode();
// First post.
$edit = array(
'title[full][region]' => 'header',
'author[full][region]' => 'middle',
'body[full][region]' => 'middle',
'links[full][region]' => 'footer',
'terms[full][region]' => 'disabled',
);
$this
->drupalPost('admin/content/node-type/page/display', $edit, t('Save'));
$page_object = $this
->_nd_build_object($page_node);
$this
->assertTrue(in_array('title', array_keys($page_object->regions['header'])), t('Title is in header region'), t('Rendering tests'));
$this
->assertTrue(in_array('author', array_keys($page_object->regions['middle'])), t('Author is in middle region'), t('Rendering tests'));
$this
->assertTrue(in_array('body', array_keys($page_object->regions['middle'])), t('Body is in middle region'), t('Rendering tests'));
$this
->assertTrue(in_array('links', array_keys($page_object->regions['footer'])), t('Links is in footer region'), t('Rendering tests'));
$this
->assertTrue($this
->_nd_field_not_found('terms', $page_object->regions), t('Terms is disabled'), t('Rendering tests'));
// Let's do another one..
$edit = array(
'title[full][region]' => 'disabled',
'author[full][region]' => 'right',
'body[full][region]' => 'middle',
'links[full][region]' => 'footer',
'terms[full][region]' => 'footer',
);
$this
->drupalPost('admin/content/node-type/page/display', $edit, t('Save'));
$page_object = $this
->_nd_build_object($page_node);
$this
->assertTrue(in_array('terms', array_keys($page_object->regions['footer'])), t('Terms is in footer region'), t('Rendering tests'));
$this
->assertTrue(in_array('author', array_keys($page_object->regions['right'])), t('Author is in right region'), t('Rendering tests'));
$this
->assertTrue(in_array('body', array_keys($page_object->regions['middle'])), t('Body is in middle region'), t('Rendering tests'));
$this
->assertTrue(in_array('links', array_keys($page_object->regions['footer'])), t('Links is in footer region'), t('Rendering tests'));
$this
->assertTrue($this
->_nd_field_not_found('title', $page_object->regions), t('Title is disabled'), t('Rendering tests'));
}
}
Classes
Name | Description |
---|---|
NodeDisplaysRegions | @file Tests for Node displays (regions) |