Index: chessboard.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/chessboard/chessboard.module,v
retrieving revision 1.67
diff -u -p -r1.67 chessboard.module
--- chessboard.module	30 Sep 2010 18:55:21 -0000	1.67
+++ chessboard.module	4 Nov 2010 03:41:42 -0000
@@ -65,6 +65,7 @@ function chessboard_field($op, &$node, $
         // Render the board in XHTML syntax
         //----------------------------------
         $board_value =& $matches[2];
+        $board_value = strip_tags($board_value);
         $item['board'] = array();
         $file = $rank_d = 0;
         for ($i=0; isset($board_value[$i]); $i++) {
Index: chessboard.test
===================================================================
RCS file: chessboard.test
diff -N chessboard.test
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ chessboard.test	4 Nov 2010 03:41:42 -0000
@@ -0,0 +1,161 @@
+<?php
+// $id$
+
+/**
+ * @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');
+
+    $image_base = base_path() . drupal_get_path('module', 'chessboard') . '/default';
+
+    $this->expected['starting position'] = '<div class="chessboard"><div class="row"><img src="' . $image_base . '/rdl.png" alt="r" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/ndd.png" alt="n" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/bdl.png" alt="b" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/qdd.png" alt="q" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/kdl.png" alt="k" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/bdd.png" alt="b" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/ndl.png" alt="n" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/rdd.png" alt="r" title="" width="40" height="40" class="chessboard-square" /></div><div class="row"><img src="' . $image_base . '/pdd.png" alt="p" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/pdl.png" alt="p" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/pdd.png" alt="p" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/pdl.png" alt="p" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/pdd.png" alt="p" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/pdl.png" alt="p" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/pdd.png" alt="p" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/pdl.png" alt="p" title="" width="40" height="40" class="chessboard-square" /></div><div class="row"><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /></div><div class="row"><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /></div><div class="row"><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /></div><div class="row"><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /></div><div class="row"><img src="' . $image_base . '/pll.png" alt="P" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/pld.png" alt="P" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/pll.png" alt="P" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/pld.png" alt="P" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/pll.png" alt="P" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/pld.png" alt="P" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/pll.png" alt="P" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/pld.png" alt="P" title="" width="40" height="40" class="chessboard-square" /></div><div class="row"><img src="' . $image_base . '/rld.png" alt="R" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/nll.png" alt="N" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/bld.png" alt="B" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/qll.png" alt="Q" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/kld.png" alt="K" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/bll.png" alt="B" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/nld.png" alt="N" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/rll.png" alt="R" title="" width="40" height="40" class="chessboard-square" /></div></div>';
+
+    $this->expected['marked squares'] = '<div class="chessboard"><div class="row"><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /></div><div class="row"><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/xxl.png" alt="x" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/xxl.png" alt="x" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /></div><div class="row"><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/xxl.png" alt="x" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/xxl.png" alt="x" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /></div><div class="row"><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/nld.png" alt="N" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /></div><div class="row"><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/xxl.png" alt="x" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/xxl.png" alt="x" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /></div><div class="row"><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/xxl.png" alt="x" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/xxl.png" alt="x" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /></div><div class="row"><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /></div><div class="row"><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /></div></div>';
+
+    $this->expected['portion'] = '<div class="chessboard"><div class="border-top"><img src="' . $image_base . '/h.png" alt="" title="" width="40" height="4" class="chessboard-border-h" /><img src="' . $image_base . '/h.png" alt="" title="" width="40" height="4" class="chessboard-border-h" /><img src="' . $image_base . '/h.png" alt="" title="" width="40" height="4" class="chessboard-border-h" /><img src="' . $image_base . '/c.png" alt="" title="" width="4" height="4" class="chessboard-border-c" /></div><div class="row"><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/rdl.png" alt="r" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/kdd.png" alt="k" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/v.png" alt="" title="" width="4" height="40" class="chessboard-border-v" /></div><div class="row"><img src="' . $image_base . '/nll.png" alt="N" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/pdd.png" alt="p" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/pdl.png" alt="p" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/v.png" alt="" title="" width="4" height="40" class="chessboard-border-v" /></div><div class="row"><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/l.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/d.png" alt="-" title="" width="40" height="40" class="chessboard-square" /><img src="' . $image_base . '/v.png" alt="" title="" width="4" height="40" class="chessboard-border-v" /></div></div>';
+
+    $privileged_user = $this->drupalCreateUser(array('administer filters'));
+    $this->drupalLogin($privileged_user);
+    $edit_fields = array('filters[chessboard/0]' => TRUE);
+    $this->drupalPost('admin/settings/filters/1', $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' => $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' => $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' => $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';
+    $raw = '<link type="text/css" rel="stylesheet" media="'. $media .'" href="'. base_path() . $file . '?';
+
+    $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' => '[chessboard]rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR[/chessboard]',
+      'nid' => $node->nid,
+    );
+    $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);
+  }
+}
