# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: contributions/modules/examples/nodeapi_example/nodeapi_example.info
--- contributions/modules/examples/nodeapi_example/nodeapi_example.info Base (1.2)
+++ contributions/modules/examples/nodeapi_example/nodeapi_example.info Locally Modified (Based On 1.2)
@@ -1,5 +1,8 @@
-; $Id: nodeapi_example.info,v 1.2 2009/10/03 14:56:46 rfay Exp $
+; $Id: nodeapi_example.info,v 1.3 2008/09/13 16:49:48 heyrocker Exp $
 name = NodeAPI Example
 description = An example module showing how to extend existing content types.
 package = Example modules
 core = 7.x
+files[] = nodeapi_example.module
+files[] = nodeapi_example.install
+files[] = nodeapi_example.test
\ No newline at end of file
Index: contributions/modules/examples/nodeapi_example/nodeapi_example.install
--- contributions/modules/examples/nodeapi_example/nodeapi_example.install Base (1.2)
+++ contributions/modules/examples/nodeapi_example/nodeapi_example.install Locally Modified (Based On 1.2)
@@ -1,26 +1,36 @@
 <?php
+// $Id: nodeapi_example.install,v 1.4 2007/10/05 16:44:50 drewish Exp $
 
-// $Id: nodeapi_example.install,v 1.2 2009/10/03 14:56:46 rfay Exp $
+/**
+ * @file
+ * Install, update and uninstall functions for the nodeapi example module.
+ *
+ * This file contains the functions required to perform install, update and
+ * uninstall operations. The schema (if the module defines any) will be included
+ * here.
+ *
+ */
 
 /**
- * Implementation of hook_install().
+ * Implements hook_install().
  */
 function nodeapi_example_install() {
   drupal_install_schema('nodeapi_example');
 }
 
 /**
- * Implementation of hook_uninstall().
+ * Implements hook_uninstall().
  */
 function nodeapi_example_uninstall() {
   drupal_uninstall_schema('nodeapi_example');
 }
 
 /**
- * Implementation of hook_schema().
+ * Implements hook_schema().
  */
 function nodeapi_example_schema() {
   $schema['nodeapi_example'] = array(
+    'description' => 'Stores information of extended content.',
     'fields' => array(
       'nid'    => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
       'rating' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
Index: contributions/modules/examples/nodeapi_example/nodeapi_example.module
--- contributions/modules/examples/nodeapi_example/nodeapi_example.module Base (1.2)
+++ contributions/modules/examples/nodeapi_example/nodeapi_example.module Locally Modified (Based On 1.2)
@@ -1,5 +1,5 @@
 <?php
-// $Id: nodeapi_example.module,v 1.2 2009/10/03 14:56:46 rfay Exp $
+// $Id: nodeapi_example.module,v 1.9 2008/09/15 21:57:07 davereid Exp $
 
 /**
  * @file
@@ -11,7 +11,7 @@
  */
 
 /**
- * Implementation of hook_form_alter().
+ * Implements hook_form_alter().
  *
  * By implementing this hook, we're able to modify any form. We'll only make
  * changes to two types: a node's content type configuration and edit forms.
@@ -19,26 +19,41 @@
  * We need to have a way for administrators to indicate which content types
  * should have our rating field added. This is done by inserting a checkbox in
  * the node's content type configuration page.
+ *
+ * Changes made by this hook will be show when editing the settings of any
+ * content type.
+ *
+ * Optionally, hook_form_FORM_ID_alter() could be used with the function name
+ * nodeapi_example_form_node_type_form_alter
  */
 function nodeapi_example_form_alter(&$form, $form_state, $form_id) {
   if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
     // Alter the node type's configuration form to add our setting. We don't
     // need to worry about saving this value back to the variable, the form
     // we're altering will do it for us.
-    $form['workflow']['nodeapi_example'] = array(
+    $form['rating'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Rating settings'),
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+      '#group' => 'additional_settings',
+      '#weight' => -1,
+    );
+
+    $form['rating']['nodeapi_example'] = array(
       '#type' => 'radios',
       '#title' => t('NodeAPI Example Rating'),
-      '#default_value' => variable_get('nodeapi_example_'. $form['#node_type']->type, 0),
+      '#default_value' => variable_get('nodeapi_example_' . $form['#node_type']->type, 1),
       '#options' => array(0 => t('Disabled'), 1 => t('Enabled')),
       '#description' => t('Should this node have a rating attached to it?'),
     );
   }
   // If the type and node field are set this may be a node edit form.
-  elseif (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) {
+  elseif (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] . '_node_form' == $form_id) {
     // If the rating is enabled for this node type, we insert our control
     // into the form.
     $node = $form['#node'];
-    if (variable_get('nodeapi_example_'. $form['type']['#value'], 0)) {
+    if (variable_get('nodeapi_example_' . $form['type']['#value'], 0)) {
       $form['nodeapi_example_rating'] = array(
         '#type' => 'select',
         '#title' => t('Rating'),
@@ -52,84 +67,168 @@
 }
 
 /**
- * Implementation of hook_nodeapi().
+ * hook_nodeapi() has been replaced in Drupal 7 with a set of different hooks
+ * providing the same or improved functionality.
  *
- * We will implement several node API operations here. This hook allows us to
- * act on all major node operations, so we can manage our additional data
- * appropriately.
+ * The replacement functions providing access to events ocurred to content in
+ * Drupal is listed below, and detailled in the following location:
+ * http://api.drupal.org/api/group/hooks/7
+ * or in the node API declaration file: modules/node/node.api.php
+ *
+ * hook_node_access	- Control access to a node.
+ * hook_node_access_records	-	Set permissions for a node to be written to the database.
+ * hook_node_access_records_alter	-	Alter permissions for a node before it is written to the database.
+ * hook_node_build_alter	-	The node content was built, the module may modify the structured content.
+ * hook_node_delete	-	Act on node deletion.
+ * hook_node_grants	-	Inform the node access system what permissions the user has.
+ * hook_node_grants_alter	-	Alter user access rules when trying to view, edit or delete a node.
+ * hook_node_info	-	Defines module-provided node types.
+ * hook_node_insert	-	Respond to node insertion.
+ * hook_node_load	-	Act on node objects when loaded.
+ * hook_node_operations	-	Add mass node operations.
+ * hook_node_prepare	-	The node is about to be shown on the add/edit form.
+ * hook_node_prepare_translation	-	The node is being cloned for translation.
+ * hook_node_presave	-	The node passed validation and is about to be saved.
+ * hook_node_revision_delete	-	A revision of the node is deleted.
+ * hook_node_search_result	-	The node is being displayed as a search result.
+ * hook_node_type_delete	-	Act on node type deletion.
+ * hook_node_type_insert	-	Act on node type creation.
+ * hook_node_type_update	-	Act on node type changes.
+ * hook_node_update	-	The node being updated.
+ * hook_node_update_index	-	The node is being indexed.
+ * hook_node_validate	-	The user has finished editing the node and is previewing or submitting it.
+ * hook_node_view	-	The node content is being assembled before rendering.
+ *
  */
-function nodeapi_example_nodeapi(&$node, $op, $teaser, $page) {
-  switch ($op) {
-    // When the content editing form is submitted, we need to validate the input
-    // to make sure the user made a selection, since we are requiring the rating
-    // field. We have to check that the value has been set to avoid showing an
-    // error message when a new blank form is presented. Calling form_set_error()
-    // when the field is set but zero ensures not only that an error message is
-    // presented, but also that the user must correct the error before being able
-    // to submit the node.
-    case 'validate':
-      if (variable_get('nodeapi_example_'. $node->type, TRUE)) {
+
+/**
+ * Implements hook_node_validate().
+ * 
+ * Check that rating attribute is set in the form submission, the field is
+ * required
+ */
+function nodeapi_example_node_validate($node, $form) {
+  if (variable_get('nodeapi_example_' . $node->type, TRUE)) {
         if (isset($node->nodeapi_example_rating) && !$node->nodeapi_example_rating) {
           form_set_error('nodeapi_example_rating', t('You must rate this content.'));
         }
       }
-      break;
+}
 
-    // Now we need to take care of loading one of the extended nodes from the
-    // database. An array containing our extra field needs to be returned.
-    case 'load':
-      $rating = db_result(db_query('SELECT rating FROM {nodeapi_example} WHERE nid = %d', $node->nid));
-      return array('nodeapi_example_rating' => $rating);
-      break;
+/**
+ * Implements hook_node_load().
+ *
+ * Load the rating information if available for any of the nodes in the argument
+ * list.
+ */
+function nodeapi_example_node_load($nodes, $form) {
+  foreach ($nodes as $node) {
+    if (variable_get('nodeapi_example_' . $node->type, TRUE)) {
+      $nids[] = $node->nid;
+    }
+  }
+  // Check if we should load rating for any of the nodes
+  if (!isset($nids) || !count($nids)) {
+    return;
+  }
 
-    // Insert is called after the node has been validated and saved to the
-    // database. It gives us a chance to create our own record in the database.
-    case 'insert':
-      db_query('INSERT INTO {nodeapi_example} (nid, rating) VALUES (%d, %d)', $node->nid, $node->nodeapi_example_rating);
-      break;
+  $result = db_select('nodeapi_example', 'e')
+    ->fields('e', array(
+        'nid',
+        'rating',
+      ))
+    ->where('e.nid IN (:nids)', array(':nids' => $nids))
+    ->execute();
 
-    // Update is called when an existing node has been changed. Here, we use a
-    // DELETE then an INSERT rather than an UPDATE. The reason is that a node
-    // created before this module was installed won't already have a rating
-    // saved so there would be nothing to update.
-    case 'update':
-      db_query('DELETE FROM {nodeapi_example} WHERE nid = %d', $node->nid);
-      db_query('INSERT INTO {nodeapi_example} (nid, rating) VALUES (%d, %d)', $node->nid, $node->nodeapi_example_rating);
-      break;
+  foreach ($result as $record) {
+    $nodes[$record->nid]->nodeapi_example_rating = $record->rating;
+  }
+}
 
-    // Delete is called whn the node is being deleted, it gives us a chance
-    // to delete the rating too.
-    case 'delete':
-      db_query('DELETE FROM {nodeapi_example} WHERE nid = %d', $node->nid);
-      break;
+/**
+ * Implements hook_node_insert().
+ *
+ * As a new node is being inserted into the database, we need to do our own
+ * database inserts.
+ */
+function nodeapi_example_node_insert($node) {
+  if (variable_get('nodeapi_example_' . $node->type, TRUE)) {
+    // Notice that we are ignoring any revision information using $node->nid
+    db_insert('nodeapi_example')
+      ->fields(array(
+        'nid' => $node->nid,
+        'rating' => $node->nodeapi_example_rating,
+      ))
+      ->execute();
+  }
+}
 
-    // Finally, we need to take care of displaying our rating when the node is
-    // viewed. This operation is called after the node has already been prepared
-    // into HTML and filtered as necessary, so we know we are dealing with an
-    // HTML teaser and body. We will inject our additional information at the front
-    // of the node copy.
-    //
-    // Using nodeapi('view') is more appropriate than using a filter here, because
-    // filters transform user-supplied content, whereas we are extending it with
-    // additional information.
-    case 'view':
+/**
+ * Implements hook_node_delete().
+ *
+ * When a node is deleted, we need to remove all related records from our table.
+ */
+function nodeapi_example_node_delete($node) {
+  // Notice that we're deleting even if the content type has no rating enabled.
+  db_delete('nodeapi_example')
+    ->condition('nid', $node->nid)
+    ->execute();
+}
+
+/**
+ * Implements hook_node_update().
+ *
+ * As an existing node is being updated in the database, we need to do our own
+ * database updates.
+ *
+ * Update is called when an existing node has been changed. Here, we use a
+ * DELETE then an INSERT rather than an UPDATE. The reason is that a node
+ * created before this module was installed won't already have a rating
+ * saved so there would be nothing to update.
+ */
+function nodeapi_example_node_update($node) {
+  if (variable_get('nodeapi_example_' . $node->type, TRUE)) {
+    nodeapi_example_node_delete($node);
+    nodeapi_example_node_insert($node);
+  }
+}
+
+/**
+ * Implements hook_view().
+ *
+ * This is a typical implementation that simply runs the node text through
+ * the output filters.
+ *
+ * Finally, we need to take care of displaying our rating when the node is
+ * viewed. This operation is called after the node has already been prepared
+ * into HTML and filtered as necessary, so we know we are dealing with an
+ * HTML teaser and body. We will inject our additional information at the front
+ * of the node copy.
+ *
+ * Using node API 'hook_node_view' is more appropriate than using a filter here, because
+ * filters transform user-supplied content, whereas we are extending it with
+ * additional information.
+ */
+function nodeapi_example_node_view($node, $build_mode = 'full') {
+  if (variable_get('nodeapi_example_' . $node->type, TRUE)) {
+    // Make sure to set a rating, also for nodes saved previously and not yet rated.
+    $rating = isset($node->nodeapi_example_rating) ? $node->nodeapi_example_rating : 0;
       $node->content['nodeapi_example'] = array(
-        '#value' => theme('nodeapi_example_rating', $node->nodeapi_example_rating),
+      '#markup' => theme('nodeapi_example_rating', array('rating' => $rating)),
         '#weight' => -1,
       );
-      break;
   }
 }
 
 /**
- * Implementation of hook_theme().
+ * Implements hook_theme().
  *
  * This lets us tell Drupal about our theme functions and their arguments.
  */
 function nodeapi_example_theme() {
   return array(
     'nodeapi_example_rating' => array(
-      'arguments' => array('rating'),
+      'arguments' => array('rating' => NULL),
     ),
   );
 }
@@ -142,7 +241,7 @@
  * also wrap the default presentation in a CSS class that is prefixed by the module
  * name. This way, style sheets can modify the output without requiring theme code.
  */
-function theme_nodeapi_example_rating($rating) {
+function theme_nodeapi_example_rating($variables) {
   $options = array(
     0 => t('Unrated'),
     1 => t('Poor'),
@@ -151,7 +250,7 @@
     4 => t('Good'),
     5 => t('Excellent'));
   $output = '<div class="nodeapi_example_rating">';
-  $output .= t('Rating: %rating', array('%rating' => $options[(int) $rating]));
+  $output .= t('Rating: %rating', array('%rating' => $options[(int) $variables['rating']]));
   $output .= '</div>';
   return $output;
 }
Index: contributions/modules/examples/nodeapi_example/nodeapi_example.test
--- contributions/modules/examples/nodeapi_example/nodeapi_example.test No Base Revision
+++ contributions/modules/examples/nodeapi_example/nodeapi_example.test Locally New
@@ -0,0 +1,110 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Test case for Testing the node API example module.
+ *
+ * This file contains the test cases to check if module is performing as
+ * expected.
+ *
+ */
+class NodeApiExampleTestCase extends DrupalWebTestCase {
+  /**
+   * User object to perform site browsing
+   * @var object
+   */
+  protected $web_user;
+
+  /**
+   * Content type to attach the rating system
+   * @var string
+   */
+  protected $type;
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Node API example functionality',
+      'description' => 'Extend exiting content type and verify its consistency in the database.',
+      'group' => 'Node API Example',
+    );
+  }
+
+  /**
+   * Enable modules and create user with specific permissions.
+   */
+  function setUp() {
+    parent::setUp('nodeapi_example');
+
+    // Create admin user. This module has no access control, so we can use a trusted user.
+    $this->web_user = $this->drupalCreateUser(array('administer content types', 'bypass node access'));
+    // Login the admin user.
+    $this->drupalLogin($this->web_user);
+  }
+
+  /**
+   * Login user, create an example node, and test blog functionality through the admin and user interfaces.
+   */
+  function testNodeExampleBasic() {
+
+    // Login the user.
+    $this->drupalLogin($this->web_user);
+
+    // Create custom content type
+    $content_type = $this->drupalCreateContentType();
+    $type = $content_type->type;
+
+    // Go to edit the settings of this content type
+    $this->drupalGet('admin/structure/types/manage/' . $type);
+    $this->assertResponse(200);
+
+    // Check if the new Rating options appear in the settings page
+    $this->assertText(t('NodeAPI Example Rating'), t('Rating options found in content type.'));
+    $this->assertFieldByName('nodeapi_example', 1, t('Rating is Disabled by default.'));
+
+    // Disable the rating for this content type: 0 for Disabled, 1 for Enabled.
+    $content_settings = array(
+      'nodeapi_example' => 0,
+    );
+    $this->drupalPost('admin/structure/types/manage/' . $type, $content_settings, t('Save content type'));
+    $this->assertResponse(200);
+    $this->assertRaw(' has been updated.', t('Settings modified successfully for content type.'));
+
+    // Create an example node
+    $langcode = FIELD_LANGUAGE_NONE;
+    $edit = array(
+      "title[$langcode][0][value]" => $this->randomName(),
+    );
+    $this->drupalPost('node/add/' . $type, $edit, t('Save'));
+    $this->assertResponse(200);
+
+    // Check that the rating is not shown, as we have not yet enabled it
+    $this->assertNoRaw('Rating: <em>', t('Extended rating information is not shown.'));
+
+    // Save current current url (we are viewing the new node)
+    $node_url = $this->getUrl();
+
+    // Enable the rating for this content type: 0 for Disabled, 1 for Enabled.
+    $content_settings = array(
+      'nodeapi_example' => TRUE,
+    );
+    $this->drupalPost('admin/structure/types/manage/' . $type, $content_settings, t('Save content type'));
+    $this->assertResponse(200);
+    $this->assertRaw(' has been updated.', t('Settings modified successfully for content type.'));
+
+    // Check previously create node. It should be not rated
+    $this->drupalGet($node_url);
+    $this->assertResponse(200);
+    $this->assertRaw(t('Rating: %rating', array('%rating' => t('Unrated'))), t('Content is not rated.'));
+
+    // Rate the content, 4 is for "Good"
+    $rate = array(
+      'nodeapi_example_rating' => 4,
+    );
+    $this->drupalPost($node_url . '/edit', $rate, t('Save'));
+    $this->assertResponse(200);
+
+    // Check that content has been rated
+    $this->assertRaw(t('Rating: %rating', array('%rating' => t('Good'))), t('Content is successfully rated.'));
+  }
+}
