class NodeAdminTestCase extends DrupalWebTestCase {
/**
* Implementation of getInfo().
*/
function getInfo() {
'name' =>
t('Node administration tests'),
'description' =>
t('Tests the node administration screens'),
);
}
function testNodeFilters() {
$promote_nodes =
array();
$type_map =
array('page',
'article');
// Create some nodes.
for ($status = 0; $status < 2; $status++) {
for ($promote = 0; $promote < 2; $promote++) {
for ($sticky = 0; $sticky < 2; $sticky++) {
foreach ($type_map as $type_key => $type) {
for ($i = 0; $i < 3; $i++) {
$node =
$this->
drupalCreateNode(array('status' =>
$status,
'promote' =>
$promote,
'sticky' =>
$sticky,
'type' =>
$type));
$status_nodes[$status][] = $promote_nodes[$promote][] = $sticky_nodes[$sticky][] = $type_nodes[$type_key][] = $node;
$all_nodes[$node->nid] = $node;
}
}
}
}
}
$user =
$this->
drupalCreateUser(array('administer nodes'));
$this->drupalLogin($user);
// Iterate through all of the combinations. -1 = undefined.
for ($status = -1; $status < 2; $status++) {
for ($promote = -1; $promote < 2; $promote++) {
for ($sticky = -1; $sticky < 2; $sticky++) {
for ($type = -1; $type < 2; $type++) {
foreach (array('status',
'promote',
'sticky',
'type') as $option) {
if ($$option != -1) {
$options[$option] = $$option;
}
}
$this->drupalGet('admin/content/node');
$first = TRUE;
// Iterate through the options, setting them in the form.
foreach ($options as $option => $value) {
if ($option == 'type') {
$edit =
array('filter' =>
'type',
'type' =>
$type_map[$value]);
}
else {
$edit =
array('filter' =>
'status',
'value' =>
$option .
'-' .
$value);
}
if ($first == TRUE) {
$this->
drupalPost('admin/content/node',
$edit,
t('Filter'));
$first = FALSE;
}
else {
$this->
drupalPost('admin/content/node',
$edit,
t('Refine'));
}
}
if (count($options) >
2) {var_dump($this->
drupalGetContent());exit;
}
$showing_nodes = $hidden_nodes = $all_nodes;
foreach ($options as $option => $value) {
$node_variable = $option . '_nodes';
$node_variable = $$node_variable;
foreach ($node_variable[(int)!$value] as $node) {
if (isset($showing_nodes[$node->
nid])) {
unset($showing_nodes[$node->
nid]);
}
}
}
}
foreach ($showing_nodes as $nid => $node) {
if (isset($hidden_nodes[$nid])) {
unset($hidden_nodes[$nid]);
}
foreach ($type_nodes as $node_type => $nodes) {
$this->
assertFieldByName('nodes[' .
$node->
nid .
']',
'', t
('Node %title shows up when it\'s supposed to.',
array('%title' =>
$node->
title)));
}
}
foreach ($hidden_nodes as $node) {
$this->
assertNoFieldByName('nodes[' .
$node->
nid .
']',
'', t
('Node %title doesn\'t show up when it\'s not supposed to.',
array('%title' =>
$node->
title)));
}
$this->
drupalPost('admin/content/node',
array(),
t('Reset'));
}
}
}
}
}
}