Version 1
[yaffs-website] / web / modules / contrib / typogrify / tests / typogrify.class.test
diff --git a/web/modules/contrib/typogrify/tests/typogrify.class.test b/web/modules/contrib/typogrify/tests/typogrify.class.test
new file mode 100644 (file)
index 0000000..56fb8ff
--- /dev/null
@@ -0,0 +1,128 @@
+<?php
+
+/**
+ * @file
+ * Unit tests for the basic typogrify functionality.
+ */
+
+class TypogrifyClassTestCase extends DrupalWebTestCase {
+  /**
+   * Implements getInfo().
+   */
+  function getInfo() {
+    return array(
+      'name' => t('typogrify.class basic tests'),
+      'description' => t('Testing all methods on the Typogrify class and their interaction.'),
+      'group' => t('Typogrify'),
+    );
+  }
+
+  /**
+   * Implements setUp().
+   */
+  function setUp() {
+    parent::setUp('typogrify');
+  }
+
+  /**
+   * Tests ampersand-wrapping.
+   */
+  function testAmpersandWrapping() {
+    $before = 'John & Robert.';
+    $after = 'John <span class="amp">&amp;</span> Robert.';
+    $this->assertEqual(Typogrify::amp($before), $after,
+      t('Basic ampersand wrapping'));
+
+    $before = 'P&T';
+    $after = 'P&T';
+    $this->assertEqual(Typogrify::amp($before), $after,
+      t("Don't mess with ampersands in words"));
+
+    $before = 'advanced robotics &&nbsp;computing...';
+    $after = 'advanced robotics <span class="amp">&amp;</span>&nbsp;computing...';
+    $this->assertEqual(Typogrify::amp($before), $after,
+      t("One space as HTML entitiy."));
+
+    $before = 'advanced robotics &amp; computing...';
+    $after = 'advanced robotics <span class="amp">&amp;</span> computing...';
+    $this->assertEqual(Typogrify::amp($before), $after,
+      t("Ampersand as HTML entitiy."));
+
+    $before = 'advanced robotics&nbsp;&amp;&nbsp;computing...';
+    $after = 'advanced robotics&nbsp;<span class="amp">&amp;</span>&nbsp;computing...';
+    $this->assertEqual(Typogrify::amp($before), $after,
+      t("Both spaces and ampersand as HTML entities."));
+
+    $before = 'P&amp;T had many clients, of which DD&T &amp; Cronhammar, Kronhammer & Hjort were the largest';
+    $after = 'P&amp;T had many clients, of which DD&T <span class="amp">&amp;</span> Cronhammar, Kronhammer <span class="amp">&amp;</span> Hjort were the largest';
+    $this->assertEqual(Typogrify::amp($before), $after,
+      t("Both spaces and ampersand as HTML entities."));
+
+  }
+
+  /**
+   * Widont test.
+   */
+  function testWidont() {
+    $before = 'A very simple test';
+    $after = 'A very simple&nbsp;test';
+    $this->assertEqual(Typogrify::widont($before), $after,
+      t('Basic widont. Once sentance, no HTML.'));
+
+    // Single word items shouldn't be changed.
+    $before = 'Test';
+    $after = 'Test';
+    $this->assertEqual(Typogrify::widont($before), $after,
+      t('Single word test #1'));
+
+    $before = ' Test';
+    $after = ' Test';
+    $this->assertEqual(Typogrify::widont($before), $after,
+      t('Single word test #2'));
+
+    $before = '<ul><li>Test</p></li><ul>';
+    $after = '<ul><li>Test</p></li><ul>';
+    $this->assertEqual(Typogrify::widont($before), $after,
+      t('Single word test #3'));
+
+    $before = '<ul><li> Test</p></li><ul>';
+    $after = '<ul><li> Test</p></li><ul>';
+    $this->assertEqual(Typogrify::widont($before), $after,
+      t('Single word test #4'));
+
+    $before = '<p>In a couple of paragraphs</p><p>paragraph two</p>';
+    $after = '<p>In a couple of&nbsp;paragraphs</p><p>paragraph&nbsp;two</p>';
+    $this->assertEqual(Typogrify::widont($before), $after,
+      t('Two paragraphs'));
+
+    $before = '<h1><a href="#">In a link inside a heading</i> </a></h1>';
+    $after = '<h1><a href="#">In a link inside a&nbsp;heading</i> </a></h1>';
+    $this->assertEqual(Typogrify::widont($before), $after,
+      t('In a link inside a heading'));
+
+    $before = '<h1><a href="#">In a link</a> followed by other text</h1>';
+    $after = '<h1><a href="#">In a link</a> followed by other&nbsp;text</h1>';
+    $this->assertEqual(Typogrify::widont($before), $after,
+      t('In a link followed by other text'));
+
+    $before = '<h1><a href="#"></a></h1>';
+    $after = '<h1><a href="#"></a></h1>';
+    $this->assertEqual(Typogrify::widont($before), $after,
+      t("Empty HTML tags shouldn't cause errors"));
+
+    $before = '<div>Divs get no love!</div>';
+    $after = '<div>Divs get no love!</div>';
+    $this->assertEqual(Typogrify::widont($before), $after,
+      t('Divs get no love'));
+
+    $before = '<pre>Neither do PREs</pre>';
+    $after = '<pre>Neither do PREs</pre>';
+    $this->assertEqual(Typogrify::widont($before), $after,
+      t('Neither do PREs'));
+
+    $before = '<div><p>But divs with paragraphs do!</p></div>';
+    $after = '<div><p>But divs with paragraphs&nbsp;do!</p></div>';
+    $this->assertEqual(Typogrify::widont($before), $after,
+      t('But divs with paragraphs do!'));
+  }
+}