node.admin.inc test case

  1. class NodeAdminTestCase extends DrupalWebTestCase {
  2.   /**
  3.    * Implementation of getInfo().
  4.    */
  5.   function getInfo() {
  6.     return array(
  7.       'name' => t('Node administration tests'),
  8.       'description' => t('Tests the node administration screens'),
  9.       'group' => t('Node'),
  10.     );
  11.   }
  12.  
  13.   function testNodeFilters() {
  14.     $status_nodes = array();
  15.     $promote_nodes = array();
  16.     $sticky_nodes = array();
  17.     $type_nodes = array();
  18.     $all_nodes = array();
  19.     $type_map = array('page', 'article');
  20.     // Create some nodes.
  21.     for ($status = 0; $status < 2; $status++) {
  22.       for ($promote = 0; $promote < 2; $promote++) {
  23.         for ($sticky = 0; $sticky < 2; $sticky++) {
  24.           foreach ($type_map as $type_key => $type) {
  25.             for ($i = 0; $i < 3; $i++) {
  26.               $node = $this->drupalCreateNode(array('status' => $status, 'promote' => $promote, 'sticky' => $sticky, 'type' => $type));
  27.               $status_nodes[$status][] = $promote_nodes[$promote][] = $sticky_nodes[$sticky][] = $type_nodes[$type_key][] = $node;
  28.               $all_nodes[$node->nid] = $node;
  29.             }
  30.           }
  31.         }
  32.       }
  33.     }
  34.  
  35.     $user = $this->drupalCreateUser(array('administer nodes'));
  36.     $this->drupalLogin($user);
  37.  
  38.     // Iterate through all of the combinations. -1 = undefined.
  39.     for ($status = -1; $status < 2; $status++) {
  40.       for ($promote = -1; $promote < 2; $promote++) {
  41.         for ($sticky = -1; $sticky < 2; $sticky++) {
  42.           for ($type = -1; $type < 2; $type++) {
  43.             $options = array();
  44.             foreach (array('status', 'promote', 'sticky', 'type') as $option) {
  45.               if ($$option != -1) {
  46.                 $options[$option] = $$option;
  47.               }
  48.             }
  49.             $this->drupalGet('admin/content/node');
  50.             $first = TRUE;
  51.             // Iterate through the options, setting them in the form.
  52.             foreach ($options as $option => $value) {
  53.               if ($option == 'type') {
  54.                 $edit = array('filter' => 'type', 'type' => $type_map[$value]);
  55.               }
  56.               else {
  57.                 $edit = array('filter' => 'status', 'value' => $option . '-' . $value);
  58.               }
  59.               if (count($options) > 2) {print_r($edit);}
  60.               if ($first == TRUE) {
  61.                 $this->drupalPost('admin/content/node', $edit, t('Filter'));
  62.                 $first = FALSE;
  63.               }
  64.               else {
  65.                 $this->drupalPost('admin/content/node', $edit, t('Refine'));
  66.               }
  67.             }
  68.             if (count($options) > 2) {var_dump($this->drupalGetContent());exit;}
  69.  
  70.             $nodes = array();
  71.             $showing_nodes = $hidden_nodes = $all_nodes;
  72.             if (!empty($options)) {
  73.               foreach ($options as $option => $value) {
  74.                 $node_variable = $option . '_nodes';
  75.                 $node_variable = $$node_variable;
  76.                 foreach ($node_variable[(int)!$value] as $node) {
  77.                   if (isset($showing_nodes[$node->nid])) {
  78.                     unset($showing_nodes[$node->nid]);
  79.                   }
  80.                 }
  81.               }
  82.             }
  83.             foreach ($showing_nodes as $nid => $node) {
  84.               if (isset($hidden_nodes[$nid])) {
  85.                 unset($hidden_nodes[$nid]);
  86.               }
  87.               foreach ($type_nodes as $node_type => $nodes) {
  88.                 $this->assertFieldByName('nodes[' . $node->nid . ']', '', t('Node %title shows up when it\'s supposed to.', array('%title' => $node->title)));
  89.               }
  90.             }
  91.  
  92.             foreach ($hidden_nodes as $node) {
  93.               $this->assertNoFieldByName('nodes[' . $node->nid . ']', '', t('Node %title doesn\'t show up when it\'s not supposed to.', array('%title' => $node->title)));
  94.             }
  95.             $this->drupalPost('admin/content/node', array(), t('Reset'));
  96.           }
  97.         }
  98.       }
  99.     }
  100.   }
  101. }