Index: chessboard.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/chessboard/chessboard.info,v
retrieving revision 1.3
diff -u -p -r1.3 chessboard.info
--- chessboard.info	21 Dec 2010 12:24:51 -0000	1.3
+++ chessboard.info	6 Feb 2011 12:13:17 -0000
@@ -1,6 +1,5 @@
 ; $Id: chessboard.info,v 1.3 2010/12/21 12:24:51 erica Exp $
 
 name = Chessboard Renderer
-description = This module renders chessboard diagrams.
+description = This module provides the Chessboard Renderer core functionality.
 core = 7.x
-files[] = chessboard.test
Index: chessboard.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/chessboard/chessboard.install,v
retrieving revision 1.6
diff -u -p -r1.6 chessboard.install
--- chessboard.install	4 Jan 2011 21:19:00 -0000	1.6
+++ chessboard.install	6 Feb 2011 12:13:17 -0000
@@ -55,3 +55,21 @@ function chessboard_update_7000() {
     }
   }
 }
+
+/**
+ * Transfer ownership of filters from Chessboard Renderer to Chessboard Filter.
+ */
+function chessboard_update_7200() {
+  $has_rows = (bool) db_query_range("SELECT 1 FROM {filter} WHERE module='chessboard'", 0, 1)->fetchField();
+  if ($has_rows) {
+    db_update('filter')
+      ->fields(array(
+        'module' => 'chessboard_filter',
+      ))
+      ->condition('module', 'chessboard')
+      ->execute();
+    if (module_exists('chessboard')) {
+      module_enable(array('chessboard_filter'), FALSE);
+    }
+  }
+}
Index: chessboard.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/chessboard/chessboard.module,v
retrieving revision 1.82
diff -u -p -r1.82 chessboard.module
--- chessboard.module	4 Jan 2011 21:43:10 -0000	1.82
+++ chessboard.module	6 Feb 2011 12:13:17 -0000
@@ -2,53 +2,6 @@
 // $Id: chessboard.module,v 1.82 2011/01/04 21:43:10 erica Exp $
 
 /**
- * Implements hook_help().
- */
-function chessboard_help($path, $arg) {
-
-  switch ($path) {
-    case 'admin/help#chessboard':
-      $output = t('Renders chessboard diagrams specified with the FEN syntax or a simple piece placement format.');
-      break;
-
-    default:
-      $output = '';
-      break;
-  }
-
-  return $output;
-}
-
-/**
- * Implements hook_init().
- */
-function chessboard_init() {
-  $formats = filter_formats();
-
-  // Build list cache IDs.
-  $cids = _chessboard_filter_page_structures_list_cids($formats);
-
-  // Retrieve lists.
-  $cache = cache_get_multiple($cids, 'cache_filter');
-
-  // Build structure cache IDs.
-  $cids = array();
-  foreach ($cache as $item) {
-    $cids += array_keys($item->data);
-  }
-
-  // Retrieve structures.
-  $cache = cache_get_multiple($cids, 'cache_filter');
-
-  // Process structures.
-  foreach ($cache as $item) {
-    if (isset($item->data['#attached'])) {
-      drupal_process_attached($item->data);
-    }
-  }
-}
-
-/**
  * Implements hook_field().
  */
 function chessboard_field($op, &$node, $field, &$items, $teaser, $page) {
@@ -108,22 +61,6 @@ function chessboard_field($op, &$node, $
 }
 
 /**
- * Implements hook_filter_info().
- */
-function chessboard_filter_info() {
-  $filters = array();
-  $filters['chessboard_filter_diagram'] = array(
-    'title' => t('Chessboard'),
-    'description' => t('Renders chessboard diagrams.'),
-    'process callback' => '_chessboard_filter_0',
-    'tips callback' => '_chessboard_filter_0_tips',
-    'weight' => 10,
-  );
-
-  return $filters;
-}
-
-/**
  * Implements hook_theme().
  */
 function chessboard_theme() {
@@ -136,153 +73,6 @@ function chessboard_theme() {
   );
 }
 
-/**
- * Chessboard filter. Provides filtering of input into chessboard diagrams.
- *
- * @param $filter
- *   The filter object containing settings for the given format.
- *
- * @param $text
- *   The content to filter.
- */
-function _chessboard_filter_0($text, $filter) {
-  // Prepare the callback function.
-  _chessboard_filter_callback(NULL, $filter);
-
-  return preg_replace_callback('@\[chessboard\](.*?)\[/chessboard\]@si', '_chessboard_filter_callback', $text);
-}
-
-/**
- * Filter tips callback for chessboard filter.
- */
-function _chessboard_filter_0_tips($filter, $format, $long = FALSE) {
-  if ($long) {
-    return t('<h4>Chessboard Diagrams</h4>
-<h5>Basic Usage</h5>
-<p>Use the pair of <code>[chessboard]</code> and <code>[/chessboard]</code> tags to define a chessboard. The following formats are recognized:</p>
-<ul>
-  <li>The piece placement field (i.e., the first field) of the FEN (Forsyth-Edwards Notation) syntax. E.g., for the starting position:
-    <code>[chessboard]rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR[/chessboard]</code>
-  </li>
-  <li>A simple and direct piece placement format. E.g., for the starting position:
-<pre>[chessboard]
-rnbqkbnr
-pppppppp
---------
---------
---------
---------
-PPPPPPPP
-RNBQKBNR
-[/chessboard]</pre>
-Note that a dash (-) character represents an empty square.
-  </li>
-  <li>A mixture of the previous two formats. This is possible because the previous formats are in fact compatible to each other. E.g., for the starting position:
-<pre>[chessboard]
-rnbqkbnr
-pppppppp
-8/8/8/8
-PPPPPPPP
-RNBQKBNR
-[/chessboard]</pre>
-  However, the use of this format is NOT encouraged as it may lead to confusion.
-  </li>
-</ul>
-<p>The renderer also supports a special feature that will converts \'x\' character to a marked square. For example, to display the diagram below which shows the squares a knight can control, you can write</p>
-<pre>[chessboard]
---------
----x-x--
---x---x-
-----N---
---x---x-
----x-x--
---------
---------
-[/chessboard]</pre>
-<p>or</p>
-<pre>[chessboard]8/3x1x2/2x3x1/4N3/2x3x1/3x1x2/8/8[/chessboard]</pre>
-
-<h5>Advanced Usage</h5>
-<p>You can configure the appearance of the chessboard with a few flags, with the following syntax:</p>
-<pre>[chessboard](<i>flags</i>)board[/chessboard]</pre>
-<p>The following flags are supported:</p>
-<ul>
-  <li>Borders. Valid flags are T, B, L, and R, which correspond to the top border, the bottom border, the left border, and the right border respectively. The corresponding borders of the chessboard will be rendered for the flags specified. (Default: none is specified.)</li>
-  <li>Number of Files. Valid flags are positive integers such as 4, 6, and 12. (Default: 8.)</li>
-  <li>Color of the Upper Left Square. Valid flags are d and l, which correspond to the dark color and the light color. (Default: l.)</li>
-</ul>
-<p>These flags are especially useful in displaying a portion of a chessboard. For example, the following sentence illustrates a smothered mate at the upper-right corner:</p>
-<pre>[chessboard](d3TR)
--rk
-Npp
----
-[/chessboard]
-</pre>
-<p>Any portion of a chessboard can be displayed by using these flags.</p>
-');
-  }
-  else {
-    return t('Renders chessboard diagrams.');
-  }
-}
-
-/**
- * preg_replace callback to make chessboard diagrams out of chessboard syntax.
- *
- * @param $matches
- *   An array of matches found by preg_replace_callback(). Elements 0 and 1 of
- *   $matches must be the complete match and the piece placement field.
- *
- * @param $set_filter
- *   The filter object containing settings for the given format. This should
- *   only be set during a preparatory call before preg_replace_callback().
- *
- * @return
- *   A <code>string</code> containing the replacement text.
- */
-function _chessboard_filter_callback($matches, $set_filter = NULL) {
-  static $filter;
-  if (isset($set_filter)) {
-    // This is a preparatory call.
-    $filter = $set_filter;
-    return;
-  }
-  $item = array(
-    'value' => $matches[1],
-  );
-  $node = NULL;
-  $field = array();
-  $items = array($item);
-  chessboard_field('sanitize', $node, $field, $items, FALSE, FALSE);
-  $element = _chessboard_formatter_view($items);
-  $output = drupal_render($element);
-  if (isset($element['#attached']) && filter_format_allowcache($filter->format)) {
-    // Store attached structures so we can process these when cached filtered text is being output.
-    $data['#attached'] = $element['#attached'];
-    $cid = $filter->format . '::chessboard-filter-attached' . hash('sha256', serialize($element['#attached']));
-    $expire = REQUEST_TIME + (60 * 60 * 24);
-    cache_set($cid, $data, 'cache_filter', $expire);
-    $list_cid = $filter->format . '::chessboard-filter-attached-cids';
-    $cache = cache_get($list_cid, 'cache_filter');
-    $cids = isset($cache->data) ? $cache->data : array();
-    $cids[$cid] = TRUE;
-    if (!$cache || $cids != $cache->data || $expire != $cache->expire) {
-      cache_set($list_cid, $cids, 'cache_filter', $expire);
-    }
-  }
-  return $output;
-}
-
-function _chessboard_filter_page_structures_list_cids($formats) {
-  $cids = array();
-  foreach ($formats as $format) {
-    if ($format->cache) {
-      $cids[] = $format->format . '::chessboard-filter-attached-cids';
-    }
-  }
-  return $cids;
-}
-
 function _chessboard_formatter_view($items) {
   $element = array(
     '#attached' => array(
Index: chessboard.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/chessboard/chessboard.test,v
retrieving revision 1.6
diff -u -p -r1.6 chessboard.test
--- chessboard.test	4 Jan 2011 21:15:15 -0000	1.6
+++ chessboard.test	6 Feb 2011 12:13:17 -0000
@@ -1,164 +1,2 @@
 <?php
 // $Id: chessboard.test,v 1.6 2011/01/04 21:15:15 erica Exp $
-
-/**
- * @file
- * Tests for Chessboard Renderer module.
- */
-
-/**
- * Functional tests for the Chessboard Renderer filter.
- */
-class ChessboardFilterTestCase extends DrupalWebTestCase {
-  protected $expected;
-
-  public static function getInfo() {
-
-    return array(
-      'name' => 'Chessboard Renderer filter functionality',
-      'description' => 'Filter texts and assert that the result is the same for each supported syntax.',
-      'group' => 'Chessboard Renderer',
-    );
-  }
-
-  public function setUp() {
-    parent::setUp('chessboard');
-    module_disable(array('rdf'), FALSE);
-
-    $image_base = file_create_url(drupal_get_path('module', 'chessboard') . '/default');
-
-    $this->expected['starting position'] = '<div class="chessboard"><div class="row"><img class="chessboard-square" src="' . $image_base . '/rdl.png" width="40" height="40" alt="r" title="" /><img class="chessboard-square" src="' . $image_base . '/ndd.png" width="40" height="40" alt="n" title="" /><img class="chessboard-square" src="' . $image_base . '/bdl.png" width="40" height="40" alt="b" title="" /><img class="chessboard-square" src="' . $image_base . '/qdd.png" width="40" height="40" alt="q" title="" /><img class="chessboard-square" src="' . $image_base . '/kdl.png" width="40" height="40" alt="k" title="" /><img class="chessboard-square" src="' . $image_base . '/bdd.png" width="40" height="40" alt="b" title="" /><img class="chessboard-square" src="' . $image_base . '/ndl.png" width="40" height="40" alt="n" title="" /><img class="chessboard-square" src="' . $image_base . '/rdd.png" width="40" height="40" alt="r" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/pdd.png" width="40" height="40" alt="p" title="" /><img class="chessboard-square" src="' . $image_base . '/pdl.png" width="40" height="40" alt="p" title="" /><img class="chessboard-square" src="' . $image_base . '/pdd.png" width="40" height="40" alt="p" title="" /><img class="chessboard-square" src="' . $image_base . '/pdl.png" width="40" height="40" alt="p" title="" /><img class="chessboard-square" src="' . $image_base . '/pdd.png" width="40" height="40" alt="p" title="" /><img class="chessboard-square" src="' . $image_base . '/pdl.png" width="40" height="40" alt="p" title="" /><img class="chessboard-square" src="' . $image_base . '/pdd.png" width="40" height="40" alt="p" title="" /><img class="chessboard-square" src="' . $image_base . '/pdl.png" width="40" height="40" alt="p" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/pll.png" width="40" height="40" alt="P" title="" /><img class="chessboard-square" src="' . $image_base . '/pld.png" width="40" height="40" alt="P" title="" /><img class="chessboard-square" src="' . $image_base . '/pll.png" width="40" height="40" alt="P" title="" /><img class="chessboard-square" src="' . $image_base . '/pld.png" width="40" height="40" alt="P" title="" /><img class="chessboard-square" src="' . $image_base . '/pll.png" width="40" height="40" alt="P" title="" /><img class="chessboard-square" src="' . $image_base . '/pld.png" width="40" height="40" alt="P" title="" /><img class="chessboard-square" src="' . $image_base . '/pll.png" width="40" height="40" alt="P" title="" /><img class="chessboard-square" src="' . $image_base . '/pld.png" width="40" height="40" alt="P" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/rld.png" width="40" height="40" alt="R" title="" /><img class="chessboard-square" src="' . $image_base . '/nll.png" width="40" height="40" alt="N" title="" /><img class="chessboard-square" src="' . $image_base . '/bld.png" width="40" height="40" alt="B" title="" /><img class="chessboard-square" src="' . $image_base . '/qll.png" width="40" height="40" alt="Q" title="" /><img class="chessboard-square" src="' . $image_base . '/kld.png" width="40" height="40" alt="K" title="" /><img class="chessboard-square" src="' . $image_base . '/bll.png" width="40" height="40" alt="B" title="" /><img class="chessboard-square" src="' . $image_base . '/nld.png" width="40" height="40" alt="N" title="" /><img class="chessboard-square" src="' . $image_base . '/rll.png" width="40" height="40" alt="R" title="" /></div></div>';
-
-    $this->expected['marked squares'] = '<div class="chessboard"><div class="row"><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/xxl.png" width="40" height="40" alt="x" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/xxl.png" width="40" height="40" alt="x" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/xxl.png" width="40" height="40" alt="x" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/xxl.png" width="40" height="40" alt="x" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/nld.png" width="40" height="40" alt="N" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/xxl.png" width="40" height="40" alt="x" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/xxl.png" width="40" height="40" alt="x" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/xxl.png" width="40" height="40" alt="x" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/xxl.png" width="40" height="40" alt="x" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /></div></div>';
-
-    $this->expected['portion'] = '<div class="chessboard"><div class="border-top"><img class="chessboard-border-h" src="' . $image_base . '/h.png" width="40" height="4" alt="" title="" /><img class="chessboard-border-h" src="' . $image_base . '/h.png" width="40" height="4" alt="" title="" /><img class="chessboard-border-h" src="' . $image_base . '/h.png" width="40" height="4" alt="" title="" /><img class="chessboard-border-c" src="' . $image_base . '/c.png" width="4" height="4" alt="" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/rdl.png" width="40" height="40" alt="r" title="" /><img class="chessboard-square" src="' . $image_base . '/kdd.png" width="40" height="40" alt="k" title="" /><img class="chessboard-border-v" src="' . $image_base . '/v.png" width="4" height="40" alt="" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/nll.png" width="40" height="40" alt="N" title="" /><img class="chessboard-square" src="' . $image_base . '/pdd.png" width="40" height="40" alt="p" title="" /><img class="chessboard-square" src="' . $image_base . '/pdl.png" width="40" height="40" alt="p" title="" /><img class="chessboard-border-v" src="' . $image_base . '/v.png" width="4" height="40" alt="" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-border-v" src="' . $image_base . '/v.png" width="4" height="40" alt="" title="" /></div></div>';
-
-    $privileged_user = $this->drupalCreateUser(array('administer filters'));
-    $this->drupalLogin($privileged_user);
-    $edit_fields = array('filters[chessboard_filter_diagram][status]' => TRUE);
-    $this->drupalPost('admin/config/content/formats/filtered_html', $edit_fields, 'Save configuration');
-    $this->drupalLogout();
-  }
-
-  public function testChessboardFilterProcessField() {
-    $expected = '';
-    $expected .= $this->expected['starting position'];
-    $expected .= $this->expected['marked squares'];
-
-    $text = '';
-
-    // Starting position.
-    $text .= '[chessboard]rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR[/chessboard]';
-
-    // Marked squares.
-    $text .= '[chessboard]8/3x1x2/2x3x1/4N3/2x3x1/3x1x2/8/8[/chessboard]';
-
-    $settings = array(
-      'body' => array(LANGUAGE_NONE => array(array('value' => $text))),
-    );
-    $node = $this->drupalCreateNode($settings);
-    $this->drupalGet('node/' . $node->nid);
-    $this->assertRaw($expected);
-  }
-
-  public function testChessboardFilterProcessSimple() {
-    $expected = '';
-    $expected .= $this->expected['starting position'];
-    $expected .= $this->expected['marked squares'];
-    $expected .= $this->expected['portion'];
-
-    $text = '';
-
-    // Starting position.
-    $text .= '[chessboard]
-rnbqkbnr
-pppppppp
---------
---------
---------
---------
-PPPPPPPP
-RNBQKBNR
-[/chessboard]';
-
-    // Marked squares.
-    $text .= '[chessboard]
---------
----x-x--
---x---x-
-----N---
---x---x-
----x-x--
---------
---------
-[/chessboard]';
-
-    // Portion of a chessboard.
-    $text .= '[chessboard](d3TR)
--rk
-Npp
----
-[/chessboard]';
-
-    $settings = array(
-      'body' => array(LANGUAGE_NONE => array(array('value' => $text))),
-    );
-    $node = $this->drupalCreateNode($settings);
-
-    $this->drupalGet('node/' . $node->nid);
-    $this->assertRaw($expected);
-  }
-
-  public function testChessboardFilterProcessMixture() {
-    $expected = $this->expected['starting position'];
-
-    $text = '';
-
-    // Starting position.
-    $text .= '[chessboard]
-rnbqkbnr
-pppppppp
-8/8/8/8
-PPPPPPPP
-RNBQKBNR
-[/chessboard]';
-
-    $settings = array(
-      'body' => array(LANGUAGE_NONE => array(array('value' => $text))),
-    );
-    $node = $this->drupalCreateNode($settings);
-    $this->drupalGet('node/' . $node->nid);
-    $this->assertRaw($expected);
-  }
-
-  public function testChessboardFilterProcessAttached() {
-    $media = 'all';
-    $file = drupal_get_path('module', 'chessboard') . '/chessboard.css';
-    $query_string = variable_get('css_js_query_string', '0');
-    $raw = '<link type="text/css" rel="stylesheet" href="' . file_create_url($file) . '?' . $query_string . '" media="' . $media . '"';
-
-    $node = $this->drupalCreateNode(array());
-
-    // Assert that no chessboard structures are added to pages yet.
-    $this->drupalGet('node/' . $node->nid);
-    $this->assertNoRaw($raw);
-
-    $settings = array(
-      'body' => array(LANGUAGE_NONE => array(array('value' => '[chessboard]rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR[/chessboard]'))),
-      'nid' => $node->nid,
-      'vid' => $node->vid,
-    );
-    $node = $this->drupalCreateNode($settings);
-
-    // Activate the adding to the page of chessboard structures.
-    $this->drupalGet('node/' . $node->nid);
-
-    // Assert presence of chessboard structures (markup not retrieved from cache).
-    $this->drupalGet('node/' . $node->nid);
-    $this->assertRaw($raw);
-
-    // Assert presence of chessboard structures (markup retrieved from cache).
-    $this->drupalGet('node/' . $node->nid);
-    $this->assertRaw($raw);
-  }
-}
Index: chessboard_filter/chessboard_filter.info
===================================================================
RCS file: chessboard_filter/chessboard_filter.info
diff -N chessboard_filter/chessboard_filter.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ chessboard_filter/chessboard_filter.info	6 Feb 2011 12:13:17 -0000
@@ -0,0 +1,7 @@
+; $Id$
+
+name = Chessboard Filter
+description = This module renders chessboard diagrams.
+core = 7.x
+files[] = chessboard_filter.test
+dependencies[] = chessboard
Index: chessboard_filter/chessboard_filter.install
===================================================================
RCS file: chessboard_filter/chessboard_filter.install
diff -N chessboard_filter/chessboard_filter.install
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ chessboard_filter/chessboard_filter.install	6 Feb 2011 12:13:17 -0000
@@ -0,0 +1,57 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Install, update and uninstall functions for the Chessboard Filter module.
+ */
+
+/**
+ * Implements hook_uninstall().
+ */
+function chessboard_filter_uninstall() {
+}
+
+/**
+ * Upgrade the {filter} table for Chessboard Filter filters.
+ */
+function chessboard_filter_update_7000() {
+  // Get an array of the renamed filter deltas, organized by module.
+  $renamed_deltas = array(
+    'chessboard_filter' => array(
+      '0' => 'chessboard_filter_diagram',
+    ),
+  );
+
+  // Loop through each filter and make changes to the core filter table by
+  // each record from the old to the new table.
+  foreach ($renamed_deltas as $module => $deltas) {
+    foreach ($deltas as $old_delta => $new_name) {
+      $query = db_select('d6_upgrade_filter')
+        ->fields('d6_upgrade_filter', array('format', 'weight'))
+        ->condition('module', $module)
+        ->condition('delta', $old_delta)
+        ->distinct();
+
+      foreach ($query->execute() as $record) {
+        // Port the filter settings.
+        $settings = array();
+
+        db_insert('filter')
+          ->fields(array(
+            'format' => $record->format,
+            'module' => $module,
+            'name' => $new_name,
+            'weight' => $record->weight,
+            'settings' => serialize($settings),
+            'status' => 1,
+          ))
+          ->execute();
+      }
+      db_delete('d6_upgrade_filter')
+        ->condition('module', $module)
+        ->condition('delta', $old_delta)
+        ->execute();
+    }
+  }
+}
Index: chessboard_filter/chessboard_filter.module
===================================================================
RCS file: chessboard_filter/chessboard_filter.module
diff -N chessboard_filter/chessboard_filter.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ chessboard_filter/chessboard_filter.module	6 Feb 2011 12:13:17 -0000
@@ -0,0 +1,212 @@
+<?php
+// $Id$
+
+/**
+ * Implements hook_help().
+ */
+function chessboard_filter_help($path, $arg) {
+
+  switch ($path) {
+    case 'admin/help#chessboard_filter':
+      $output = t('Renders chessboard diagrams specified with the FEN syntax or a simple piece placement format.');
+      break;
+
+    default:
+      $output = '';
+      break;
+  }
+
+  return $output;
+}
+
+/**
+ * Implements hook_init().
+ */
+function chessboard_filter_init() {
+  $formats = filter_formats();
+
+  // Build list cache IDs.
+  $cids = _chessboard_filter_page_structures_list_cids($formats);
+
+  // Retrieve lists.
+  $cache = cache_get_multiple($cids, 'cache_filter');
+
+  // Build structure cache IDs.
+  $cids = array();
+  foreach ($cache as $item) {
+    $cids += array_keys($item->data);
+  }
+
+  // Retrieve structures.
+  $cache = cache_get_multiple($cids, 'cache_filter');
+
+  // Process structures.
+  foreach ($cache as $item) {
+    if (isset($item->data['#attached'])) {
+      drupal_process_attached($item->data);
+    }
+  }
+}
+
+/**
+ * Implements hook_filter_info().
+ */
+function chessboard_filter_filter_info() {
+  $filters = array();
+  $filters['chessboard_filter_diagram'] = array(
+    'title' => t('Chessboard'),
+    'description' => t('Renders chessboard diagrams.'),
+    'process callback' => '_chessboard_filter_0',
+    'tips callback' => '_chessboard_filter_0_tips',
+    'weight' => 10,
+  );
+
+  return $filters;
+}
+
+/**
+ * Chessboard filter. Provides filtering of input into chessboard diagrams.
+ *
+ * @param $filter
+ *   The filter object containing settings for the given format.
+ *
+ * @param $text
+ *   The content to filter.
+ */
+function _chessboard_filter_0($text, $filter) {
+  // Prepare the callback function.
+  _chessboard_filter_callback(NULL, $filter);
+
+  return preg_replace_callback('@\[chessboard\](.*?)\[/chessboard\]@si', '_chessboard_filter_callback', $text);
+}
+
+/**
+ * Filter tips callback for chessboard filter.
+ */
+function _chessboard_filter_0_tips($filter, $format, $long = FALSE) {
+  if ($long) {
+    return t('<h4>Chessboard Diagrams</h4>
+<h5>Basic Usage</h5>
+<p>Use the pair of <code>[chessboard]</code> and <code>[/chessboard]</code> tags to define a chessboard. The following formats are recognized:</p>
+<ul>
+  <li>The piece placement field (i.e., the first field) of the FEN (Forsyth-Edwards Notation) syntax. E.g., for the starting position:
+    <code>[chessboard]rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR[/chessboard]</code>
+  </li>
+  <li>A simple and direct piece placement format. E.g., for the starting position:
+<pre>[chessboard]
+rnbqkbnr
+pppppppp
+--------
+--------
+--------
+--------
+PPPPPPPP
+RNBQKBNR
+[/chessboard]</pre>
+Note that a dash (-) character represents an empty square.
+  </li>
+  <li>A mixture of the previous two formats. This is possible because the previous formats are in fact compatible to each other. E.g., for the starting position:
+<pre>[chessboard]
+rnbqkbnr
+pppppppp
+8/8/8/8
+PPPPPPPP
+RNBQKBNR
+[/chessboard]</pre>
+  However, the use of this format is NOT encouraged as it may lead to confusion.
+  </li>
+</ul>
+<p>The renderer also supports a special feature that will converts \'x\' character to a marked square. For example, to display the diagram below which shows the squares a knight can control, you can write</p>
+<pre>[chessboard]
+--------
+---x-x--
+--x---x-
+----N---
+--x---x-
+---x-x--
+--------
+--------
+[/chessboard]</pre>
+<p>or</p>
+<pre>[chessboard]8/3x1x2/2x3x1/4N3/2x3x1/3x1x2/8/8[/chessboard]</pre>
+
+<h5>Advanced Usage</h5>
+<p>You can configure the appearance of the chessboard with a few flags, with the following syntax:</p>
+<pre>[chessboard](<i>flags</i>)board[/chessboard]</pre>
+<p>The following flags are supported:</p>
+<ul>
+  <li>Borders. Valid flags are T, B, L, and R, which correspond to the top border, the bottom border, the left border, and the right border respectively. The corresponding borders of the chessboard will be rendered for the flags specified. (Default: none is specified.)</li>
+  <li>Number of Files. Valid flags are positive integers such as 4, 6, and 12. (Default: 8.)</li>
+  <li>Color of the Upper Left Square. Valid flags are d and l, which correspond to the dark color and the light color. (Default: l.)</li>
+</ul>
+<p>These flags are especially useful in displaying a portion of a chessboard. For example, the following sentence illustrates a smothered mate at the upper-right corner:</p>
+<pre>[chessboard](d3TR)
+-rk
+Npp
+---
+[/chessboard]
+</pre>
+<p>Any portion of a chessboard can be displayed by using these flags.</p>
+');
+  }
+  else {
+    return t('Renders chessboard diagrams.');
+  }
+}
+
+/**
+ * preg_replace callback to make chessboard diagrams out of chessboard syntax.
+ *
+ * @param $matches
+ *   An array of matches found by preg_replace_callback(). Elements 0 and 1 of
+ *   $matches must be the complete match and the piece placement field.
+ *
+ * @param $set_filter
+ *   The filter object containing settings for the given format. This should
+ *   only be set during a preparatory call before preg_replace_callback().
+ *
+ * @return
+ *   A <code>string</code> containing the replacement text.
+ */
+function _chessboard_filter_callback($matches, $set_filter = NULL) {
+  static $filter;
+  if (isset($set_filter)) {
+    // This is a preparatory call.
+    $filter = $set_filter;
+    return;
+  }
+  $item = array(
+    'value' => $matches[1],
+  );
+  $node = NULL;
+  $field = array();
+  $items = array($item);
+  chessboard_field('sanitize', $node, $field, $items, FALSE, FALSE);
+  $element = _chessboard_formatter_view($items);
+  $output = drupal_render($element);
+  if (isset($element['#attached']) && filter_format_allowcache($filter->format)) {
+    // Store attached structures so we can process these when cached filtered text is being output.
+    $data['#attached'] = $element['#attached'];
+    $cid = $filter->format . '::chessboard-filter-attached' . hash('sha256', serialize($element['#attached']));
+    $expire = REQUEST_TIME + (60 * 60 * 24);
+    cache_set($cid, $data, 'cache_filter', $expire);
+    $list_cid = $filter->format . '::chessboard-filter-attached-cids';
+    $cache = cache_get($list_cid, 'cache_filter');
+    $cids = isset($cache->data) ? $cache->data : array();
+    $cids[$cid] = TRUE;
+    if (!$cache || $cids != $cache->data || $expire != $cache->expire) {
+      cache_set($list_cid, $cids, 'cache_filter', $expire);
+    }
+  }
+  return $output;
+}
+
+function _chessboard_filter_page_structures_list_cids($formats) {
+  $cids = array();
+  foreach ($formats as $format) {
+    if ($format->cache) {
+      $cids[] = $format->format . '::chessboard-filter-attached-cids';
+    }
+  }
+  return $cids;
+}
Index: chessboard_filter/chessboard_filter.test
===================================================================
RCS file: chessboard_filter/chessboard_filter.test
diff -N chessboard_filter/chessboard_filter.test
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ chessboard_filter/chessboard_filter.test	6 Feb 2011 12:13:18 -0000
@@ -0,0 +1,164 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Tests for Chessboard Filter module.
+ */
+
+/**
+ * Functional tests for the Chessboard Filter filter.
+ */
+class ChessboardFilterTestCase extends DrupalWebTestCase {
+  protected $expected;
+
+  public static function getInfo() {
+
+    return array(
+      'name' => 'Chessboard Filter filter functionality',
+      'description' => 'Filter texts and assert that the result is the same for each supported syntax.',
+      'group' => 'Chessboard Renderer',
+    );
+  }
+
+  public function setUp() {
+    parent::setUp(array('chessboard', 'chessboard_filter'));
+    module_disable(array('rdf'), FALSE);
+
+    $image_base = file_create_url(drupal_get_path('module', 'chessboard') . '/default');
+
+    $this->expected['starting position'] = '<div class="chessboard"><div class="row"><img class="chessboard-square" src="' . $image_base . '/rdl.png" width="40" height="40" alt="r" title="" /><img class="chessboard-square" src="' . $image_base . '/ndd.png" width="40" height="40" alt="n" title="" /><img class="chessboard-square" src="' . $image_base . '/bdl.png" width="40" height="40" alt="b" title="" /><img class="chessboard-square" src="' . $image_base . '/qdd.png" width="40" height="40" alt="q" title="" /><img class="chessboard-square" src="' . $image_base . '/kdl.png" width="40" height="40" alt="k" title="" /><img class="chessboard-square" src="' . $image_base . '/bdd.png" width="40" height="40" alt="b" title="" /><img class="chessboard-square" src="' . $image_base . '/ndl.png" width="40" height="40" alt="n" title="" /><img class="chessboard-square" src="' . $image_base . '/rdd.png" width="40" height="40" alt="r" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/pdd.png" width="40" height="40" alt="p" title="" /><img class="chessboard-square" src="' . $image_base . '/pdl.png" width="40" height="40" alt="p" title="" /><img class="chessboard-square" src="' . $image_base . '/pdd.png" width="40" height="40" alt="p" title="" /><img class="chessboard-square" src="' . $image_base . '/pdl.png" width="40" height="40" alt="p" title="" /><img class="chessboard-square" src="' . $image_base . '/pdd.png" width="40" height="40" alt="p" title="" /><img class="chessboard-square" src="' . $image_base . '/pdl.png" width="40" height="40" alt="p" title="" /><img class="chessboard-square" src="' . $image_base . '/pdd.png" width="40" height="40" alt="p" title="" /><img class="chessboard-square" src="' . $image_base . '/pdl.png" width="40" height="40" alt="p" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/pll.png" width="40" height="40" alt="P" title="" /><img class="chessboard-square" src="' . $image_base . '/pld.png" width="40" height="40" alt="P" title="" /><img class="chessboard-square" src="' . $image_base . '/pll.png" width="40" height="40" alt="P" title="" /><img class="chessboard-square" src="' . $image_base . '/pld.png" width="40" height="40" alt="P" title="" /><img class="chessboard-square" src="' . $image_base . '/pll.png" width="40" height="40" alt="P" title="" /><img class="chessboard-square" src="' . $image_base . '/pld.png" width="40" height="40" alt="P" title="" /><img class="chessboard-square" src="' . $image_base . '/pll.png" width="40" height="40" alt="P" title="" /><img class="chessboard-square" src="' . $image_base . '/pld.png" width="40" height="40" alt="P" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/rld.png" width="40" height="40" alt="R" title="" /><img class="chessboard-square" src="' . $image_base . '/nll.png" width="40" height="40" alt="N" title="" /><img class="chessboard-square" src="' . $image_base . '/bld.png" width="40" height="40" alt="B" title="" /><img class="chessboard-square" src="' . $image_base . '/qll.png" width="40" height="40" alt="Q" title="" /><img class="chessboard-square" src="' . $image_base . '/kld.png" width="40" height="40" alt="K" title="" /><img class="chessboard-square" src="' . $image_base . '/bll.png" width="40" height="40" alt="B" title="" /><img class="chessboard-square" src="' . $image_base . '/nld.png" width="40" height="40" alt="N" title="" /><img class="chessboard-square" src="' . $image_base . '/rll.png" width="40" height="40" alt="R" title="" /></div></div>';
+
+    $this->expected['marked squares'] = '<div class="chessboard"><div class="row"><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/xxl.png" width="40" height="40" alt="x" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/xxl.png" width="40" height="40" alt="x" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/xxl.png" width="40" height="40" alt="x" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/xxl.png" width="40" height="40" alt="x" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/nld.png" width="40" height="40" alt="N" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/xxl.png" width="40" height="40" alt="x" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/xxl.png" width="40" height="40" alt="x" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/xxl.png" width="40" height="40" alt="x" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/xxl.png" width="40" height="40" alt="x" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /></div></div>';
+
+    $this->expected['portion'] = '<div class="chessboard"><div class="border-top"><img class="chessboard-border-h" src="' . $image_base . '/h.png" width="40" height="4" alt="" title="" /><img class="chessboard-border-h" src="' . $image_base . '/h.png" width="40" height="4" alt="" title="" /><img class="chessboard-border-h" src="' . $image_base . '/h.png" width="40" height="4" alt="" title="" /><img class="chessboard-border-c" src="' . $image_base . '/c.png" width="4" height="4" alt="" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/rdl.png" width="40" height="40" alt="r" title="" /><img class="chessboard-square" src="' . $image_base . '/kdd.png" width="40" height="40" alt="k" title="" /><img class="chessboard-border-v" src="' . $image_base . '/v.png" width="4" height="40" alt="" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/nll.png" width="40" height="40" alt="N" title="" /><img class="chessboard-square" src="' . $image_base . '/pdd.png" width="40" height="40" alt="p" title="" /><img class="chessboard-square" src="' . $image_base . '/pdl.png" width="40" height="40" alt="p" title="" /><img class="chessboard-border-v" src="' . $image_base . '/v.png" width="4" height="40" alt="" title="" /></div><div class="row"><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/l.png" width="40" height="40" alt="-" title="" /><img class="chessboard-square" src="' . $image_base . '/d.png" width="40" height="40" alt="-" title="" /><img class="chessboard-border-v" src="' . $image_base . '/v.png" width="4" height="40" alt="" title="" /></div></div>';
+
+    $privileged_user = $this->drupalCreateUser(array('administer filters'));
+    $this->drupalLogin($privileged_user);
+    $edit_fields = array('filters[chessboard_filter_diagram][status]' => TRUE);
+    $this->drupalPost('admin/config/content/formats/filtered_html', $edit_fields, 'Save configuration');
+    $this->drupalLogout();
+  }
+
+  public function testChessboardFilterProcessField() {
+    $expected = '';
+    $expected .= $this->expected['starting position'];
+    $expected .= $this->expected['marked squares'];
+
+    $text = '';
+
+    // Starting position.
+    $text .= '[chessboard]rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR[/chessboard]';
+
+    // Marked squares.
+    $text .= '[chessboard]8/3x1x2/2x3x1/4N3/2x3x1/3x1x2/8/8[/chessboard]';
+
+    $settings = array(
+      'body' => array(LANGUAGE_NONE => array(array('value' => $text))),
+    );
+    $node = $this->drupalCreateNode($settings);
+    $this->drupalGet('node/' . $node->nid);
+    $this->assertRaw($expected);
+  }
+
+  public function testChessboardFilterProcessSimple() {
+    $expected = '';
+    $expected .= $this->expected['starting position'];
+    $expected .= $this->expected['marked squares'];
+    $expected .= $this->expected['portion'];
+
+    $text = '';
+
+    // Starting position.
+    $text .= '[chessboard]
+rnbqkbnr
+pppppppp
+--------
+--------
+--------
+--------
+PPPPPPPP
+RNBQKBNR
+[/chessboard]';
+
+    // Marked squares.
+    $text .= '[chessboard]
+--------
+---x-x--
+--x---x-
+----N---
+--x---x-
+---x-x--
+--------
+--------
+[/chessboard]';
+
+    // Portion of a chessboard.
+    $text .= '[chessboard](d3TR)
+-rk
+Npp
+---
+[/chessboard]';
+
+    $settings = array(
+      'body' => array(LANGUAGE_NONE => array(array('value' => $text))),
+    );
+    $node = $this->drupalCreateNode($settings);
+
+    $this->drupalGet('node/' . $node->nid);
+    $this->assertRaw($expected);
+  }
+
+  public function testChessboardFilterProcessMixture() {
+    $expected = $this->expected['starting position'];
+
+    $text = '';
+
+    // Starting position.
+    $text .= '[chessboard]
+rnbqkbnr
+pppppppp
+8/8/8/8
+PPPPPPPP
+RNBQKBNR
+[/chessboard]';
+
+    $settings = array(
+      'body' => array(LANGUAGE_NONE => array(array('value' => $text))),
+    );
+    $node = $this->drupalCreateNode($settings);
+    $this->drupalGet('node/' . $node->nid);
+    $this->assertRaw($expected);
+  }
+
+  public function testChessboardFilterProcessAttached() {
+    $media = 'all';
+    $file = drupal_get_path('module', 'chessboard') . '/chessboard.css';
+    $query_string = variable_get('css_js_query_string', '0');
+    $raw = '<link type="text/css" rel="stylesheet" href="' . file_create_url($file) . '?' . $query_string . '" media="' . $media . '"';
+
+    $node = $this->drupalCreateNode(array());
+
+    // Assert that no chessboard structures are added to pages yet.
+    $this->drupalGet('node/' . $node->nid);
+    $this->assertNoRaw($raw);
+
+    $settings = array(
+      'body' => array(LANGUAGE_NONE => array(array('value' => '[chessboard]rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR[/chessboard]'))),
+      'nid' => $node->nid,
+      'vid' => $node->vid,
+    );
+    $node = $this->drupalCreateNode($settings);
+
+    // Activate the adding to the page of chessboard structures.
+    $this->drupalGet('node/' . $node->nid);
+
+    // Assert presence of chessboard structures (markup not retrieved from cache).
+    $this->drupalGet('node/' . $node->nid);
+    $this->assertRaw($raw);
+
+    // Assert presence of chessboard structures (markup retrieved from cache).
+    $this->drupalGet('node/' . $node->nid);
+    $this->assertRaw($raw);
+  }
+}
